Spring-Kafka
AckMode
MANUAL vs MANUAL_IMMEDIATE
Spring Framework
Kafka Messaging

Spring Kafka AckMode: MANUAL vs MANUAL_IMMEDIATE

Codemia Knowledge Hub ·

In both MANUAL and MANUAL_IMMEDIATE, your listener decides when a record counts as handled by calling acknowledge(). The difference is when the offset is committed afterwards: with MANUAL, acknowledged offsets follow BATCH semantics and are committed once the records returned by the poll have been processed, while MANUAL_IMMEDIATE commits the offset as soon as acknowledge() is called.

What acknowledgment controls

After a consumer reads and processes a message, it commits its offset so Kafka knows where to resume. How and when that commit happens affects redelivery, offset handling, and ultimately the resilience and data consistency of the system.

MANUAL

MANUAL gives you full control over when a message is treated as handled. Offsets are not committed automatically: your code must call acknowledge() after processing, and the offset is not updated until it does. That makes custom error handling and retry logic possible.

For example, if a message must be written to a database and the write fails, you can skip the acknowledgment so the message stays available for reprocessing:

java
1@KafkaListener(topics = "myTopic", containerFactory = "kafkaManualAckListenerContainerFactory")
2public void listen(ConsumerRecord<?, ?> record, Acknowledgment acknowledgment) {
3    try {
4        processData(record);
5        acknowledgment.acknowledge();
6    } catch (Exception e) {
7        // Handle the error without acknowledging the message
8    }
9}

Once acknowledged, the commit is deferred and done with the same semantics as BATCH, so it is not sent the moment you call acknowledge().

MANUAL_IMMEDIATE

MANUAL_IMMEDIATE works the same way from the listener's point of view, but commits the offset immediately when acknowledge() is called. This shortens the gap between processing and commit, which narrows the window in which messages can be redelivered if the consumer crashes. It helps when commit latency affects the application, or in high-throughput, low-latency systems where commits must be reflected quickly to avoid duplicate processing.

java
1@KafkaListener(topics = "myTopic", containerFactory = "kafkaManualImmediateAckListenerContainerFactory")
2public void listen(ConsumerRecord<?, ?> record, Acknowledgment acknowledgment) {
3    processData(record);
4    acknowledgment.acknowledge();
5}

Side-by-side comparison

FeatureMANUALMANUAL_IMMEDIATE
Acknowledgment DelayYou decide when to acknowledge, can be delayedImmediate acknowledgment once acknowledge() is called
PerspectiveMore control, manual managementFaster, less control but immediate
Use CaseScenarios needing complex business logic before acknowledgingScenarios where process efficiency and quick offset commits are critical

Choosing between them

Both modes give more control than the automatic acknowledgment modes, but you must handle offsets carefully to avoid message loss or redelivery, which adds complexity to the consumer. Pick based on your business requirements, data integrity needs, and how much commit timing affects performance and reliability.


Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design