Highlights

Contents

Part II
02

Batch processing

We process a bounded collection of records. A finite job simplifies completion but delays fresh answers and can still fail halfway. We will select a batch boundary, trace transformations, publish atomically, and recover retries without double counting.

CHAPTER ATLAS / FOLLOW THE READING PATHCHAPTER ATLAS / FOLLOW THE READING PATH1OLTP vs OLAP2Batch processing3Stream processing4Event time, windows,watermarks5ETL, ELT, warehouses, andlakes6CDC and materializedviews7Checkpoints andexactly-once8Spark and Flink9Case study: score toreport

#Section 5A batch has a defined input boundary

Heron collects an hour of accepted score events and processes them together. Batch processing operates on a bounded input collection with a known completion point. At twenty events per second, an illustrative hour contains 72,000 records and 14,400,000 payload bytes.

The boundary might be a file set, source offset range, or consistent database snapshot. A wall-clock name like the noon batch is not enough if events arrive late or files continue changing. Record the exact input set and its versions. The job can then repeat the same calculation after a failure.

AN HOURLY BATCH IS A NAMED SET: 72,000 RECORDS, 14,400,000 B, POSITIONS 1–72,000AN HOURLY BATCH IS A NAMED SET: 72,000 RECORDS, 14,400,000 B, POSITIONS 1–72,0003,600 s × 20 events/s = 72,000 recordsmanifestpositions1 … 72,00014,400,000 B"the noon batch" is a clock label; the manifest is the identity
Figure 17.5Computed illustrative hourly batch size. The manifest or position range defines a reproducible input.

At an assumed 2,000 records per second, processing takes 36 seconds. Under uniformly distributed arrivals within the hour, mean wait before the batch starts is 1,800 seconds. A record just missing the previous boundary can wait roughly one interval plus the next job’s 36 seconds, or 3,636 seconds under this simplified schedule. These are assumptions, not product defaults.

#Section 6Map records before grouping them

Our tiny input contains four records: red adds 2, blue adds 3, red adds 4, and red adds 1. A map operation transforms each record independently, such as emitting a (team, runs) pair after validation. It does not need all records together when its meaning depends only on that record.

The mapped output is (red,2), (blue,3), (red,4), and (red,1). The operator must handle invalid fields under a declared policy instead of silently treating a missing number as zero. Preserve event identity through the transform when later duplicate suppression or lineage needs it.

MAP TURNS EACH RECORD INTO A (TEAM, RUNS) CONTRIBUTION AND KEEPS ITS IDMAP TURNS EACH RECORD INTO A (TEAM, RUNS) CONTRIBUTION AND KEEPS ITS IDevent aa: red 2event bb: blue 3event cc: red 4event dd: red 1invalid runs field?reject or quarantine,never treat as 0
Figure 17.6Computed illustrative mapped contributions. Event identities remain available for auditing and retry-safe processing.

Transformations should preserve the declared row grain. Exploding a record with several tags into several output rows changes how later sums must interpret that contribution. If the same scoring value travels on every exploded row, grouping by another field can count it repeatedly. Name that relationship and normalize the contribution before a downstream aggregate assumes independent facts.

A filter operation excludes records under a condition. Its rejected count is part of the output’s meaning. A pipeline that reports successful processing while rejecting most source records is not serving the intended analysis. Track invalid, filtered, and accepted records separately and retain enough context to repair rejected data safely.

#Section 7Shuffle puts equal keys together

The red contributions may begin on different workers. To sum them by team, a shuffle redistributes intermediate records so equal grouping keys reach the same aggregation owner. A reduce operation combines those grouped values into the chosen result.

The red owner receives [2,4,1] and computes 7. The blue owner receives [3] and computes 3. Their total is 10. The shuffle moves data across workers and can dominate a job even when each addition is cheap. A local pre-aggregation can combine red values within each worker before transfer, reducing records when the operation permits it.

SHUFFLE GATHERS EACH KEY BEFORE REDUCING ITS VALUESSHUFFLE GATHERS EACH KEY BEFORE REDUCING ITS VALUESred2blue3red4red1red group2 + 4 + 1 = 7blue: 373
Figure 17.7Computed illustrative grouping. Values 2, 4 and 1 travel to the red group and sum to 7; the blue group contains 3. The shuffle groups keys before reduction.

Pre-aggregation is safe for a compatible associative combination, such as sum. An average requires both sum and count, not an average of unequal-size local averages. A hot key can concentrate most intermediate work on one owner. Splitting or salting that key requires a final combination preserving the chosen result’s semantics.

#Section 8Publish a complete batch result

A worker writes red’s total and crashes before writing blue’s. Readers now see a mixture of new and old output. A publication boundary makes a complete result generation visible as one logical version. Build the generation under a job or batch identity, validate it, then switch the reader’s manifest or transactional pointer.

On retry, the same batch identity should replace or recognize its own output rather than add it again. Writing total=total+batch_sum without a durable batch-application record duplicates results after an uncertain acknowledgement. A transactional target can record the batch ID with its effect. A file target can publish a committed manifest of the successful generation.

WRITE GENERATION 12 ASIDE, VALIDATE IT, THEN FLIP THE MANIFESTWRITE GENERATION 12 ASIDE, VALIDATE IT, THEN FLIP THE MANIFESTwrite outputgen 12 filesvalidateall partitionscommit manifestcurrent = 12readers switchgen 12retry recognises gen 12; "total = total + batch" double-counts after a crash
Figure 17.8Illustrative complete-result publication. Temporary partial data is not the current published result.

Task attempts can leave abandoned files or partial target rows. Cleanup needs attempt IDs and ownership rules so an old attempt cannot remove a newer committed generation. Job-level completion does not automatically give atomic visibility at every external sink. Define the sink publication protocol explicitly.