Set the concurrency attribute on @KafkaListener, or call setConcurrency() on a ConcurrentKafkaListenerContainerFactory, to run several consumer threads inside one Spring Boot application. Each thread owns its own KafkaConsumer and is assigned a share of the topic's partitions. Concurrency above the partition count gives no extra throughput, because a partition is consumed by only one consumer in a group at a time.
You can also set a global default with spring.kafka.listener.concurrency. The rest of this guide shows each option, how to choose a value, and what changes for ordering, offsets and thread safety.
Kafka assigns partitions to consumers in the same consumer group. Spring Kafka wraps this in a ConcurrentMessageListenerContainer. When you set concurrency to N, the container creates N child KafkaMessageListenerContainer instances. Each child has its own consumer, its own polling thread and its own set of assigned partitions.
Three rules follow from this:
For Spring Boot, the simplest option is a property. It applies to every @KafkaListener that uses the auto-configured container factory.
With this configuration every listener starts three consumer threads. The equivalent YAML key is spring.kafka.listener.concurrency: 3.
The concurrency attribute on the annotation overrides the factory default for one listener. It accepts a string, so you can read it from a property.
The log lines show different thread names, such as org.springframework.kafka.KafkaListenerEndpointContainer#0-0-C-1 and ...#0-1-C-1, each reading its own partitions. This is a quick way to confirm that concurrency works.
Define your own factory when different listeners need different settings, for example a batch listener or a different error handler.
If you name the bean kafkaListenerContainerFactory, Spring Boot's auto-configured factory backs off and your bean is used by default. Any other name must be referenced with @KafkaListener(containerFactory = "...").
Start from the partition count and the workload type.
| Situation | Suggested approach |
|---|---|
| CPU-bound processing | Concurrency near the number of cores available to the pod |
| I/O-bound processing (database, HTTP calls) | Concurrency up to the partition count; consider virtual threads for the work |
| Fewer partitions than desired parallelism | Increase partitions first, remembering that this changes key-to-partition mapping |
| Strict per-key ordering required | Keep one record at a time per partition; do not hand records to an unordered thread pool |
If a single record is slow, do not hand it to a separate executor and acknowledge early. That breaks ordering and can lose messages on failure. Increase partitions and concurrency instead.
Each listener container thread polls and processes records on the same thread, so your listener method is called concurrently by several threads. Keep the listener bean stateless, or make shared state thread-safe.
Offsets are committed per consumer according to the ack-mode. With the default batch mode the offsets of a poll are committed after the whole batch is processed. Keep processing time per poll below max.poll.interval.ms (five minutes by default), or the broker considers the consumer dead and triggers a rebalance. Lower max.poll.records if records are slow.
When an instance joins or leaves the group, partitions are redistributed. Make processing idempotent, because a record may be delivered again after a rebalance.
The default is 1, meaning one consumer thread per listener. You raise it with the concurrency attribute, the container factory or spring.kafka.listener.concurrency.
You can set it, but the extra consumers receive no partitions and sit idle. Increase the partition count if you need more parallelism.
Ordering is kept within a partition. Across partitions there is no order, so use a message key when related records must be processed in sequence.
The setting is per listener in each instance. The group total is the sum over all instances, and it is still capped by the partition count.
Spring Kafka scales consumption by starting several consumer threads per listener. Set concurrency through spring.kafka.listener.concurrency, the @KafkaListener attribute or a ConcurrentKafkaListenerContainerFactory, and keep it at or below the partition count. Keep listeners stateless, process records idempotently, and size max.poll.interval.ms and max.poll.records for your slowest record.