Batch Data Processing
itData engineering and analytics
Batch Data Processing
Batch data processing reads a bounded set of data, performs a finite sequence of transformations, and produces a result. A batch has an end. The job stops after it processes the selected input.
The central mental model is a repeatable function over a declared data slice:
declared input slice + versioned logic + run parameters
|
v
finite batch job
|
v
validated output slice
The slice might contain yesterday's transactions, one month of logs, a snapshot of customer records, or every file in a fixed delivery. The declaration matters. Without a precise boundary, retries and historical reruns can read different data and produce different answers.
Why batch processing exists
Many data tasks do not need an immediate answer for each arriving event. Payroll, daily reporting, billing reconciliation, search indexing, model training, file conversion, and historical analysis often work with accumulated data. Batch processing trades freshness for simpler finite execution and efficient use of compute.
A batch job can scan a whole bounded data set. It can sort and group records across that set. It can also use resources only while the job runs. These properties make batch processing useful when completion by a deadline matters more than per-event latency.
Batch does not mean small or single-machine. A distributed engine divides input into partitions, runs work in parallel, exchanges data when a transformation requires it, and combines the results. A bounded input can range from one file to a data set spread across many machines.
The batch pipeline
A production batch pipeline usually separates these concerns:
- Trigger — starts a run on a schedule, after an event, or on demand.
- Input boundary — identifies the exact files, table partitions, snapshot, or data interval for the run.
- Validation — rejects or quarantines malformed inputs before they contaminate trusted outputs.
- Transformation — filters, joins, groups, enriches, or calculates records.
- Materialization — writes durable outputs to a table, object store, index, or downstream system.
- Verification — checks counts, schema, quality rules, reconciliation totals, and delivery expectations.
- Publication — makes a complete output visible to consumers.
- Observation — records run state, duration, resource use, errors, and data-quality results.
An orchestrator manages dependencies and run state. A processing engine executes data transformations. A storage system holds inputs, intermediate data, and outputs. One product may cover several roles, but the roles remain distinct.
Full refresh and incremental batch
A full refresh recomputes the complete target from its source data. It is conceptually direct and can repair accumulated errors because it rebuilds everything. Its cost and runtime grow with the full input.
An incremental batch processes only a selected change or time range. It can reduce work and finish sooner, but it needs a reliable boundary and a safe update strategy. You must know which records changed, how updates and deletions appear, and how late records enter an older interval.
Incremental does not mean append-only. Blind appends can duplicate records during a retry. A pipeline may need an upsert, a partition replacement, or a new immutable output followed by an atomic pointer change.
Choose full refresh when the data fits the completion window and simplicity is valuable. Choose incremental processing when a full scan is too slow or costly, and when you can define change capture and correction behavior precisely.
Data intervals and logical time
A scheduled run needs two notions of time:
- Wall-clock time says when the job actually starts.
- Logical time says which data interval the job processes.
A daily run for July 13 may begin after midnight on July 14. Its input should still come from the declared July 13 interval. If the job uses the current time or the latest available partition instead, a retry can select different records.
Treat the interval as a parameter. Use it in source filters, output paths, checks, and run metadata. This makes one pipeline definition reusable for normal schedules, retries, and backfills.
Idempotency and safe publication
An idempotent run produces the same intended output when repeated with the same input slice, logic, and parameters. Idempotency makes automated retries safe.
Design for it explicitly:
- read a fixed input partition or snapshot;
- avoid current-time behavior in critical transformations;
- use deterministic keys and calculations;
- replace or merge a target slice instead of blindly appending it;
- keep incomplete output separate from published output;
- expose results only after validation succeeds.
Exactly-once execution is rarely the useful target. A task can start, write output, and lose contact with its orchestrator before reporting success. The orchestrator may retry it. Safe repeatable effects matter more than a promise that the code runs only once.
Partitioning, parallelism, and shuffle
A partition is a unit of data that a worker can process. More partitions can expose more parallel work. Too few partitions leave workers idle. Too many tiny partitions add scheduling, metadata, and I/O overhead.
Some transformations are local to one partition. A filter can often inspect each record where it already lives. Other transformations require records with the same key to meet. A group, wide join, or global sort can cause a shuffle, which redistributes data across workers.
Shuffle is often the expensive boundary. It adds network transfer, serialization, disk use, and coordination. It can also reveal data skew when one key owns far more records than others. That heavy partition becomes a straggler while other workers finish early.
Measure before tuning. Inspect input sizes, partition sizes, stage duration, shuffle volume, spill, and the slowest tasks. Adding workers does not fix a single overloaded key or a serial external service.
Failure, retry, and recovery
Classify failures before choosing a response:
- A transient failure may succeed on retry, such as a temporary network error.
- A deterministic failure repeats for the same input and code, such as an invalid record that crashes a parser.
- A capacity failure needs different resources, partitioning, or limits.
- A data-quality failure means execution completed but the result is not fit for publication.
Bound retries and add delay for transient conditions. Do not retry invalid data forever. Quarantine a bad record only when the business policy permits partial completion and the rejected records remain visible for repair.
Large pipelines may materialize an expensive intermediate result to reduce recovery cost. That checkpoint adds storage and lifecycle work, so place it where recomputation is genuinely costly.
Backfills and reprocessing
A backfill creates runs for historical intervals. You may backfill after introducing a new data product, fixing logic, or receiving corrected source data.
Backfills amplify normal operating risks. They can create many runs, contend with current production work, overload a sink, and overwrite outputs built with another code version. Control the date range, concurrency, run order, code version, and reprocessing policy. Preview the intended intervals before launch when the orchestrator supports it.
A backfill should use the same parameterized pipeline as a scheduled run. If historical work needs a separate code path, the normal pipeline probably depends on hidden current-time state.
Verification and service expectations
Job success is not the same as data success. A job can finish after reading an incomplete delivery or writing an implausible result.
Define a completion objective that includes both execution and data:
- expected completion deadline;
- input completeness and freshness;
- accepted error or quarantine rate;
- output schema and row-grain checks;
- reconciliation totals or invariants;
- publication state and downstream visibility.
Test transformation logic with unit tests. Test connectors and formats with integration tests. Run representative end-to-end tests before production. For a very large job, a smaller experiment can expose defects, skew, bottlenecks, and approximate cost before the full run.
Batch or stream?
Choose based on the decision deadline, not fashion.
Use batch when data is naturally bounded, a result can wait for an interval to close, or efficient bulk work matters more than immediate updates. Use stream processing when consumers need continuing low-latency results from unbounded input.
The boundary is not absolute. One system can ingest events continuously and process hourly batches. A unified engine can use related abstractions for bounded and unbounded data. The operational questions still differ: a batch job must finish by a deadline, while a streaming job must keep running and control ongoing latency.
Limits and poor fits
Batch processing is a poor fit when a consumer must react before a useful batch window closes. It can also hide quality problems until a large interval finishes. Large full refreshes may consume substantial compute and repeat work that has not changed.
Incremental batch reduces repeated work but adds state, correction, and deletion semantics. Distributed execution adds shuffle, skew, retries, serialization, and operational complexity. A database query or single process may be the better choice when the workload fits comfortably within one system.
The goal is not the largest cluster. The goal is a result that is correct, reproducible, observable, and ready before its consumer needs it.
A practical learning path
- Define a bounded input and a measurable output contract.
- Build a deterministic full-refresh pipeline on a small data set.
- Add schema checks, reconciliations, and atomic publication.
- Parameterize the pipeline by data interval and test a retry.
- Introduce incremental processing with explicit update and deletion rules.
- Run a controlled historical backfill.
- Profile partition sizes, shuffle, skew, runtime, and cost.
- Add service objectives, monitoring, incident response, and recovery tests.
- Compare the same use case with streaming requirements and choose from the consumer deadline.
