Quick revision
The short answer
One consumer per thread (Spring's concurrency setting) is simple and keeps per-partition order and correct commits, but parallelism stops at the partition count. One consumer feeding a worker pool goes beyond partitions, but records finish out of order, so the safe commit is the highest offset below which everything is done, and per-key order is lost unless work is routed by key. Key-based processing routes records with the same key to the same worker queue, keeping per-key order while different keys run in parallel, and commits again follow the lowest unfinished offset; libraries such as the Confluent Parallel Consumer implement it.
What to remember
In this answer, we compared three ways to add parallelism. One consumer per thread keeps order and simple commits but stops at the partition count. A worker pool goes beyond partitions but loses order and must commit only the lowest unfinished offset per partition. Key-based processing keeps per-key order while running different keys in parallel, with the same commit rule. In both pool models, the polling thread keeps polling and pauses partitions when queues fill, and libraries such as the Confluent Parallel Consumer, or share groups as they mature, take on the bookkeeping.
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.
One consumer per thread (Spring's concurrency setting) is simple and keeps per-partition order and correct commits, but parallelism stops at the partition count. One consumer feeding a worker pool goes beyond partitions, but records finish out of order, so the safe commit is the highest offset below which everything is done, and per-key order is lost unless work is routed by key. Key-based processing routes records with the same key to the same worker queue, keeping per-key order while different keys run in parallel, and commits again follow the lowest unfinished offset; libraries such as the Confluent Parallel Consumer implement it.
Why this question is asked
Sooner or later, a service needs more throughput than one thread per partition can give, and the way we add parallelism decides what we can still promise about ordering and about not losing or repeating records. Interviewers ask this comparison to see whether we know the price of each model, not just its speed. In this answer, we will recap the single-thread baseline, then go through the three models, how each commits offsets safely, how the polling thread stays in the group, and which libraries and newer Kafka features help.
1A Quick Recap: One Consumer, One Thread
A KafkaConsumer must be used from a single thread, and it processes the records of its assigned partitions in order. A committed offset means 'everything before this has been processed'. With one thread processing records in order and committing after each batch, that meaning is automatically true, and records with the same key, which always land in the same partition, are processed in the order they were written.
The cost is that each partition is handled by one thread at a time, so per-partition throughput is limited by how fast one thread can process records.
2Model 1: One Consumer per Thread
The first way to scale is to run more consumers in the group, each on its own thread. In Spring Kafka, setting concurrency on the listener container creates that many consumers in one process.
Notice what we keep: per-partition order, simple commits, and nothing new to reason about. What we give up is headroom: parallelism stops at the partition count, and adding partitions later changes which partition a key maps to, which is disruptive for keyed topics.
3Model 2: One Consumer Feeding a Worker Pool
The second model keeps one consumer per process and hands each record to a thread pool. Now a few partitions can keep dozens of threads busy, which is useful when processing is slow I/O, such as an HTTP call.
But records now finish out of order. Suppose offsets 100 to 104 are in the pool and 101, 102 and 104 finish first. Committing 105 would claim that 100 and 103 are done; a crash now would lose them. The safe commit is the highest offset below which every record is complete, here 100, since 100 itself is not done. When 100 finishes, the commit can move to 103. Each partition needs this small bookkeeping. Per-key order is also lost: two events for the same account can run at the same time on different threads, and the later one can finish first.
| Offset | Status | Commit after this step |
|---|---|---|
| 100 | running | 100 (nothing before it is unfinished) |
| 101 | done | still 100 |
| 102 | done | still 100 |
| 103 | running | when 100 finishes: 103 |
| 104 | done | when 103 finishes: 105 |
4Model 3: Key-Based Parallel Processing
The third model keeps the worker pool but routes records by key: every record with key 'account-42' goes to the same queue, processed by one worker at a time, while records with different keys go to other queues and run in parallel. Per-key order is preserved, which is usually the order that matters for business correctness, and parallelism can far exceed the partition count, since one partition contains many keys.
Commits follow the same rule as model 2, the lowest unfinished offset per partition, because records of different keys from the same partition still finish out of order. A hot key, one that receives a large share of traffic, limits throughput for that key, just as a hot partition does in model 1.
5Keeping the Polling Thread in the Group
In models 2 and 3, the consumer's polling thread must not wait for workers. It has to keep calling poll() within max.poll.interval.ms, or it will be removed from the group. When worker queues fill up, the polling thread calls pause() on its partitions, continues polling (which returns nothing for paused partitions), and calls resume() once the queues have room. On a rebalance, it must wait for or abandon in-flight records of revoked partitions and commit only what is complete.
This bookkeeping is easy to get subtly wrong, which is why libraries exist for it. The open-source Confluent Parallel Consumer implements key-based and unordered parallelism on top of the standard consumer, tracking per-record completion and encoding it into commit metadata so that, after a restart, it does not reprocess records it knows finished above the gap.
Kafka is also adding share groups (KIP-932), where several consumers can receive records from the same partition and acknowledge each record individually. They give queue-like parallelism without client bookkeeping, but without per-key order, and are still maturing, so check your Kafka version's status before relying on them.
| Model | Parallelism | Ordering | Offset safety |
|---|---|---|---|
| One consumer per thread | up to partition count | per partition | simple commits |
| Consumer + worker pool | beyond partitions | none | commit lowest unfinished offset |
| Key-based parallel | beyond partitions | per key | commit lowest unfinished offset |
6Follow-up questions
Which model would you choose by default?
Model 1, until it is not enough. It is the simplest, Spring supports it with one setting, and it keeps every guarantee. When partitions become the limit and processing is I/O-bound, key-based processing, preferably through a library, keeps per-key order while adding parallelism.
Does key-based processing remove the need for idempotence?
No. After a crash, records that finished above the lowest unfinished offset may be processed again, because the commit could not move past the gap. Processing must still tolerate duplicates.
7Conclusion
In this answer, we compared three ways to add parallelism. One consumer per thread keeps order and simple commits but stops at the partition count. A worker pool goes beyond partitions but loses order and must commit only the lowest unfinished offset per partition. Key-based processing keeps per-key order while running different keys in parallel, with the same commit rule. In both pool models, the polling thread keeps polling and pauses partitions when queues fill, and libraries such as the Confluent Parallel Consumer, or share groups as they mature, take on the bookkeeping.
Open with
The baseline is one consumer per thread, which in Spring is just the concurrency setting. Each thread owns some partitions and processes them in order, so per-partition and therefore per-key order is kept and commits are trivially correct.
Then, if they want more
The limit is that parallelism stops at the partition count; extra threads sit idle. The second model is one consumer feeding a worker pool.
That gives as much parallelism as I like, but records finish out of order, so I can only commit up to the lowest unfinished offset per partition: if 100 is still running, I cannot commit past it even if 101 to 104 are done. And per-key order is lost, two events for the same account can run at once.
The third model is key-based: records with the same key go to the same worker queue, so per-key order is preserved while different keys run in parallel. Commits follow the same lowest-unfinished rule. In both pool models, the polling thread must keep polling within max.poll.interval.ms and pause partitions when queues fill.
Processing still needs to be idempotent, since work above a gap can rerun after a crash. In practice I would start with concurrency, and if partitions became the limit I would use a library like the Confluent Parallel Consumer rather than writing the bookkeeping myself. Share groups are coming too, but without per-key order.
About this answer
- Last updated
- 13 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
- Apache Kafka documentation
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 "Compare three ways to process Kafka records in parallel in a Java service: one consumer...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-clients-in-depth/82556eaf01/