Doubt regarding BigQuery best practice

Hello,

I have just recently set up in Python a streaming pipeline to BigQuery using the Storage Write API and so far it seems to be working fine. My doubt comes with the following advise found in AppendRows documentation:

As a best practice, send a batch of rows in each AppendRows call. Do not send one row at a time.

As an initial development, I am currently sending one row at a time (contrary to what's advised), however, I would like to know exactly the advantages batching presents here for my streaming application in order to maybe adapt moving forward to this approach.

Thanks!

3 1 42
1 REPLY 1

Batching rows when using the Storage Write API in BigQuery provides several key advantages:

  • Reduced API Calls and Overhead: Each API call incurs overhead for connection setup, authentication, and network latency. By batching multiple rows into a single call, you can significantly reduce the total number of API calls. This not only speeds up the data ingestion process but also reduces the load on your network and the BigQuery service.
  • Improved Throughput: Batching allows you to send more data in each network request, which can improve the overall throughput of your streaming pipeline. This is particularly beneficial for high-volume data scenarios, as it ensures that data is ingested more quickly and efficiently.
  • Cost Efficiency: Google Cloud services often charge based on the number of API calls or transactions. By reducing the number of calls through batching, you can also lower the cost associated with data ingestion.
  • Error Handling: Handling errors in a batch can be more manageable than dealing with errors in individual row submissions. If a problem occurs, you can retry the entire batch, potentially simplifying your error handling logic and recovery process. Note that BigQuery's streaming inserts are atomic at the row level, meaning that even within a batch, successfully processed rows will still be committed.
  • Concurrency and Quotas: BigQuery has quotas on the number of requests per second for the APIs. By batching, you decrease the likelihood of hitting these request rate limits, especially under high throughput scenarios.

To optimize your use of the Storage Write API, consider grouping rows into batches that are as large as feasible given your latency requirements and the memory capacity of your environment. Testing different batch sizes might also help you find the optimal configuration for your specific use case, balancing between throughput, latency, and resource utilization.