liveBook · Manning

Batching

As explained in The Art of Code

Batching is the technique of dividing work into groups that are processed as units rather than all at once.

Batching divides a large workload into smaller units that can be processed sequentially rather than all at once. It helps when a single pass exceeds available processing capacity or would hold too much data in memory. section 8.4.5 section 8.4.6

Generating invoices in manageable groups

Suppose an application generates thousands of monthly invoices, while the server can handle only 200 invoice generations at a time. Guava's Lists.partition divides customer IDs into fixed-size groups, and the application processes each group sequentially. section 8.4.5

List<Long> customerIds = loadCustomerIds();
List<List<Long>> batches = Lists              #1
  .partition(customerIds, 200);               #1
for (List<Long> batch : batches) {
  generateInvoices(batch);
}

The listing shows a complete batching flow: load the workload, partition it into groups of 200, and process each group. section 8.4.5

Apply batching with a few practical constraints:

  • Choose a batch size that fits available processing capacity and memory instead of increasing infrastructure automatically. section 8.4.5 section 8.4.6
  • Avoid batches that are too small when total execution time matters; efficient completion can return machines to low-power states sooner. section 8.4.5
  • Combine batching with queues, asynchronous execution, or concurrency when workloads are unpredictable, user-triggered, or suitable for available CPU cores. section 8.4.5
  • Use paginators, database cursors, or iterators when the main concern is limiting how much data remains in memory. section 8.4.6

How The Art of Code covers it

How deep it goes
Explains workload partitioning, capacity tradeoffs, memory benefits, and batch sizing, but does not examine partitioning internals.
Examples
Uses monthly invoice generation, Guava Lists.partition, 200-item groups, paginators, database cursors, and iterators.
What you can do after
Apply it via Guava Lists.partition to process large Java workloads gradually within capacity limits.
How it connects
Connects batching with asynchronous processing, queues, concurrency, rate limiting, database cursors, and memory efficiency.

Also explained in

Compare how 15 books explain batching →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Art of Code. The section links point to the parts of the book it draws on.