Quick revision
The short answer
Scale out by running the partitions on many pods instead of threads on one: either remote partitioning with spring-batch-integration, where a manager sends partitions to workers over messaging, or separate Kubernetes Jobs for the partitions that all share one job repository. Choose partition keys that spread the load evenly and match the source's indexes or table partitions, make sure both the job repository database and the source database can take the concurrency, keep every partition restartable on its own so a lost worker costs only its part, and load test at full volume before month end with a fallback plan ready.
What to remember
In this answer, we scaled a 2 billion record month-end job to fit a 4-hour window. We sized the work at about 139,000 records per second, chose between remote partitioning with spring-batch-integration and Kubernetes Jobs sharing the job repository, picked partition keys that spread evenly and match the source's indexes or table partitions, checked that both the repository and the business databases can take the concurrency, made every partition independently restartable, and load tested at full volume ahead of month end with a written fallback plan.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Scale out by running the partitions on many pods instead of threads on one: either remote partitioning with spring-batch-integration, where a manager sends partitions to workers over messaging, or separate Kubernetes Jobs for the partitions that all share one job repository. Choose partition keys that spread the load evenly and match the source's indexes or table partitions, make sure both the job repository database and the source database can take the concurrency, keep every partition restartable on its own so a lost worker costs only its part, and load test at full volume before month end with a fallback plan ready.
Why this question is asked
Two billion records in four hours is roughly 139,000 records per second, sustained, with no time to spare for a failure at hour three. A single pod, even with eight partition threads, usually reaches a ceiling of CPU, memory or network well below that. Scaling out to many pods is the obvious answer, but it moves the hard problems to the databases and to failure handling. Interviewers ask this design question to see whether we can do the arithmetic, choose a scale-out mechanism, and name the risks before month end discovers them. In this answer, we will size the problem, compare remote partitioning with Kubernetes Jobs, choose partition keys, check the databases, plan for worker failures, and prepare the test and fallback.
1Sizing the Problem
Four hours is 14,400 seconds, so 2 billion records need about 139,000 records per second on average. In practice we should plan for a margin, say finishing in three hours, which means about 185,000 per second. If measurements show that one well-tuned worker thread handles 3,000 records per second, we need around 60 concurrent workers. With 8 threads per pod that is about 8 pods, plus spare capacity. These numbers are illustrative, but the method matters: measure one worker, divide, and add margin.
This also shows why local partitioning is not enough. One pod with 60 threads would need the CPU, memory and network of eight pods, and one pod failing would stop everything.
2Option 1: Remote Partitioning With Spring Batch Integration
Remote partitioning keeps the Spring Batch model we know. A manager step runs the Partitioner, creating for example 400 partitions, and instead of running them on local threads, it sends a message for each partition over a broker, such as Kafka, RabbitMQ or JMS, using the spring-batch-integration module. Worker pods listen on that channel, and each one runs the worker step for the partition it receives, reading and writing its own range and updating the shared job repository. The manager learns the result either from reply messages or by polling the job repository for the partition step executions.
7 messages in order. Play them, or step through them one at a time.
The advantage is that partitions are pulled by whichever worker is free, so faster pods take more work and the load balances itself. Restart works exactly as with local partitioning. The cost is a message broker in the critical path and more moving parts to operate.
3Option 2: Kubernetes Jobs Sharing the Job Repository
The other approach uses Kubernetes to distribute the work. A Kubernetes Indexed Job runs, say, 50 pods, each with an index from 0 to 49, and each pod processes the partitions assigned to its index. Every pod uses the same job repository database, so all the executions are visible in one place. This avoids a broker and uses tooling the platform team already knows, with Kubernetes handling pod restarts. The trade-off is that the assignment of partitions to pods is fixed by index, so a slow pod does not hand its work to an idle one, and we have to define clearly whether each pod is its own JobInstance or a worker of one shared instance, which affects how restart is done. Many teams find option 1 cleaner for a single logical job, and option 2 simpler when the partitions are naturally independent, such as one per region.
4Choosing Partition Keys
Partitions should take similar time. If they are ranges of an id and the ids are skewed, some partitions finish in minutes and others take hours, and the job is as slow as its slowest partition. We choose ranges from the data distribution, for example with percentiles of the key, and create many more partitions than workers, say 400 partitions for 60 workers, so that uneven sizes average out.
Partitions should also match how the source is stored. If the source table is partitioned by month and account, or has an index on the key we split by, each worker's query touches only its own part of the table. A key that does not match an index makes every worker scan the whole table, which multiplies the load by the number of workers.
| Key | Spread | Fits indexes | Verdict |
|---|---|---|---|
| account_id ranges by percentile | even | yes, primary key | good |
| source table partition (month, region) | even if regions similar | yes, partition pruning | good |
| raw id ranges with archived gaps | very uneven | yes | fix with percentiles |
| hash of customer name | even | no, full scans | bad |
5Can the Databases Take It?
Sixty workers means sixty concurrent transactions on the source or target database, each committing every chunk. At 185,000 records per second and chunks of 1,000, that is 185 commits per second on the business database, plus the same number of updates to the job repository's step execution and context tables. The job repository is often a small shared database that has never seen this load, so it can become the bottleneck or affect other jobs using it. We size it for the run, check its indexes, and if needed give this job its own repository schema.
On the business side, we check CPU, I/O, connection limits, lock contention and replication lag at full concurrency. If the target database cannot absorb the writes, adding pods only makes it slower, and the honest answer may be to write to a staging area and merge, or to spread the work over a longer window.
6Planning for Worker Failures, Testing and Fallback
With dozens of pods running for hours, some will fail: a node is drained, a pod is evicted, a network blip breaks a connection. Every partition must therefore be restartable on its own, from its last commit, with idempotent writes so that a partially processed partition can be resumed or redone without duplicates. Workers should handle SIGTERM by stopping at a chunk boundary, and the platform must detect partitions left in STARTED by a killed pod and mark them failed so they can be restarted.
Finally, none of this should be first tried at month end. We load test at full volume, 2 billion records on a production-sized copy, weeks ahead, and measure throughput, database load and the time to recover from a killed worker. The fallback plan is written down: for example, which partitions can be postponed to the next morning, or a reduced run of the records needed for regulatory deadlines first, so that a bad night ends with a decision rather than a scramble.
7Follow-up questions
Should the manager wait for replies or poll the repository?
Replies give faster feedback but need a reply channel and aggregation. Polling the job repository is simpler and survives a manager restart, since the state is in the database. For a long job with hundreds of partitions, polling every few seconds is usually enough.
Is remote chunking an alternative here?
Only if reading is cheap and processing is the bottleneck, because in remote chunking a single manager reads every record and sends it over the broker. At 2 billion records, sending every item through messaging is a large overhead, so remote partitioning, where workers read their own data, is usually the better fit.
How many partitions is too many?
Each partition adds rows to the job repository and some startup cost. Hundreds are fine; tens of thousands start to load the repository and the manager. A good range is a few times to ten times the number of workers.
8Conclusion
In this answer, we scaled a 2 billion record month-end job to fit a 4-hour window. We sized the work at about 139,000 records per second, chose between remote partitioning with spring-batch-integration and Kubernetes Jobs sharing the job repository, picked partition keys that spread evenly and match the source's indexes or table partitions, checked that both the repository and the business databases can take the concurrency, made every partition independently restartable, and load tested at full volume ahead of month end with a written fallback plan.
Open with
First I would do the arithmetic: two billion records in four hours is about 139,000 per second, and I would plan for three hours to leave a margin.
Then, if they want more
I measure one worker's throughput and divide, which gives the number of concurrent workers, maybe 60, so about 8 pods. To spread across pods I would use remote partitioning with spring-batch-integration: the manager creates many partitions, sends them over a broker, and worker pods run the worker step for whichever partition they receive, all sharing one job repository.
The alternative is a Kubernetes Indexed Job where each pod processes its own set of partitions; it avoids a broker but balances load less well. I would create many more partitions than workers, with boundaries taken from the data distribution and keys that match an index or the table's partitions, so workers do not scan the whole table.
The risks are mostly in the databases: 60 concurrent writers and the job repository updates at each commit, so I would size and test both, and watch locks and replication lag. Every partition must restart independently from its last commit with idempotent writes, workers should stop cleanly on SIGTERM, and stale STARTED partitions need detecting.
Finally, a full-volume load test weeks before month end and a written fallback plan.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Batch reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A month-end job processes 2 billion records and must finish within a 4-hour window....": https://scrivio-interview-library.netlify.app/spring-boot/spring-batch/5d2517fb5f/