Batch processing is running a program over a large, finite set of records or files as one unit of work, without anyone interacting while it runs. A typical batch program reads many records from a database, file or queue, processes them, and writes the results back in a modified form.
That definition comes from the Spring Batch documentation, which describes the pattern as processing "similar transactions as a set, typically in an offline environment without any user interaction." The same idea applies whether the job is a payroll run, a nightly report, or converting 10,000 image files.
How batch processing works
Almost every batch job follows the same three steps:
- Read a large number of records from a database, a file or a queue.
- Process each record: validate it, transform it, apply business rules, aggregate it.
- Write the output, usually to a new file or back to a database.
Microsoft's big data guidance describes the same shape: jobs "usually involve reading source files, processing them, and writing the output to new files." The input is fixed when the job starts. When the last record has been handled, the job finishes.
Terms you will see: job, step, run
Batch frameworks use a shared vocabulary. These definitions are from the Spring Batch reference, but the same concepts appear in most batch tools under similar names:
| Term | Meaning |
|---|---|
| Job | The entire batch process, for example "produce the monthly statements". |
| Step | An independent, sequential phase of a job. A job is made of one or more steps. |
| Job instance | One logical run of a job: the job plus the parameters that identify it, such as "the March run". |
| Reader, processor, writer | The parts of a step: the reader supplies input one item at a time, the optional processor applies business logic, and the writer outputs a chunk of items at a time. |
Writing output in chunks matters for large jobs. If a job fails after 9 million of 10 million records, a framework that saves its state at each commit point can restart from the last committed chunk instead of the beginning. Spring Batch lists restart and skip (leaving out a bad record) among the functions that are essential when processing large volumes.
Examples of batch processing
The Spring Batch documentation groups typical uses into three kinds:
- Time-based events. Month-end calculations, notices and correspondence, processed in bulk without a user waiting.
- Bulk rule processing. Applying complex business rules over very large data sets, such as insurance benefit determination or rate adjustments.
- System integration. Receiving data from internal and external systems and formatting, validating and loading it into the system of record.
Other common cases follow the same pattern. Converting a folder of images in one pass, computing checksums for every file in a backup, or loading a day of web server logs into a data warehouse are all batch jobs: a finite input, no user in the loop, and an output at the end. Microsoft's big data guidance lists web server log files as a typical data source for batch work and describes filtering and aggregating them before analysis.
Batch processing vs stream processing
The difference is the shape of the data. Google's Dataflow documentation calls a source that "does not contain continuously updating data" bounded, and one fed by a continuously updating source such as Pub/Sub unbounded. A bounded source is batch; an unbounded source is streaming. In Dataflow, when a bounded source is fully consumed, the pipeline stops running.
| Batch | Stream | |
|---|---|---|
| Input | Finite set that already exists ("data at rest") | Events that keep arriving ("data in motion") |
| When it ends | When the input is used up | It does not end by itself |
| Latency | Results arrive after the whole job finishes | Low latency, results as events arrive |
| Typical trigger | Schedule, file arrival, or manual start | Always running |
The cost of batch is latency. Microsoft's guidance notes that if processing takes a few hours, a query might return results that are several hours old. Its Lambda architecture handles this by running a batch layer for accuracy alongside a speed layer for low latency, and then combining them. Its Kappa architecture instead sends everything through one stream-processing path and replays the stream when a full recomputation is needed.
Batch processing vs online transaction processing
Interactive systems answer one request at a time while a person waits: a checkout, a login, a search. Batch work is the opposite. It handles many records together, nobody waits on the result of any single record, and it can be scheduled for when the system is quiet. Many systems do both: online requests during the day add records, and a batch job processes them later.
What triggers a batch job
A batch job needs something to start it. The common options:
- A scheduler. Cron on Linux and macOS, or Task Scheduler on Windows. Spring Batch states that it "is not a scheduling framework" and is meant to work with a scheduler rather than replace one.
- A job queue. You submit jobs and a service runs them as resources become free. AWS Batch works this way: it "plans, schedules, and runs" containerized batch workloads and provisions compute in response to the jobs submitted.
- A manual start. A person or a script launches it on demand, such as a one-off migration.
On Windows, a simple batch job is often a script of commands; see What Is a .bat File? for how those scripts work. Note that "batch file" there means a script, a narrower thing than batch processing. For batch pricing in AI APIs, where requests are submitted together and returned later, see Batch API Explained.
Advantages and drawbacks
Advantages that follow from the design:
- No user waiting. Long-running work does not block anyone.
- Efficient use of resources. Heavy jobs can run when the system is idle, and a queue service can match compute to the amount of work.
- Repeatable. The same job with the same inputs can be rerun, and a failed run can be restarted if the tool records progress.
Drawbacks:
- Stale results. Output is only as fresh as the last completed run.
- Failures show up late. A bad record found at hour three of a four-hour job is costly unless the job can skip it or restart.
- Needs monitoring. With no user watching, someone has to check that the job ran and succeeded.
When to use batch processing
Use batch when the work is bulk, the input is a known set, and a delay between data arriving and results appearing is acceptable. Reports, month-end billing, data warehouse loads, model training on historical data and bulk file conversion fit well. Use streaming when decisions depend on data seconds old, such as fraud alerts or live sensor monitoring. Many real systems use both, as in the Lambda architecture above.
Frequently asked questions
- What is an example of batch processing?
- A month-end calculation is the classic example. The program reads every record for the month from a database or file, applies the rules to each one, and writes the results back, with nobody interacting while it runs. Spring Batch's documentation lists month-end calculations, notices and correspondence as typical batch work.
- What is the difference between batch processing and stream processing?
- Batch processing works on a finite set of data that already exists, and the job ends when the data is used up. Stream processing works on data that keeps arriving and handles it continuously with low latency. Google's Dataflow documentation calls these bounded and unbounded data sources.
- Does batch processing have to run overnight?
- No. Batch jobs often run at night or at month-end because they are heavy and need no user, but the defining feature is that a set of records is processed together without interaction. A batch job can be triggered by a schedule, by a file arriving, or by hand.
- Is a .bat file the same as batch processing?
- No. A .bat file is a Windows script that runs commands in order. It can be used to automate a batch job, but batch processing as a concept covers any program that handles many records as one unit of work, on any operating system.