0
0
Kafkadevops~10 mins

At-least-once delivery in Kafka - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - At-least-once delivery
Producer sends message
Message stored in Kafka topic
Consumer reads message
Consumer processes message
Consumer commits offset
If commit fails or consumer crashes
Message re-delivered
Consumer processes message again
At-least-once delivery achieved
This flow shows how Kafka ensures messages are delivered at least once by re-delivering if acknowledgments fail.
Execution Sample
Kafka
producer.send(topic, message)
consumer.poll()
process(message)
consumer.commitSync()
Producer sends a message, consumer reads and processes it, then commits offset to mark message as processed.
Process Table
StepActionMessage StateOffset CommitResult
1Producer sends messageMessage stored in topicNoMessage ready for consumption
2Consumer polls messageMessage fetchedNoMessage available to process
3Consumer processes messageProcessingNoMessage being handled
4Consumer commits offsetProcessedCommit sentOffset saved
5Consumer crashes before commitProcessedNo commitOffset not saved, message will be re-delivered
6Consumer restarts and pollsMessage fetched againNoMessage re-delivered
7Consumer processes message againProcessingNoMessage handled again
8Consumer commits offsetProcessedCommit sentOffset saved, no more re-delivery
💡 Consumer commits offset successfully, so message is not re-delivered again.
Status Tracker
VariableStartAfter Step 2After Step 4After Step 5After Step 6After Step 8
message_stateNot sentFetchedProcessedProcessedFetched againProcessed
offset_committedFalseFalseTrueFalseFalseTrue
Key Moments - 2 Insights
Why does the message get processed twice sometimes?
If the consumer crashes before committing the offset (see step 5 in execution_table), Kafka will re-deliver the message to ensure it is not lost, causing duplicate processing.
What does committing the offset mean?
Committing the offset (step 4 and 8) tells Kafka the consumer has successfully processed the message and it can move on, preventing re-delivery.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the consumer fail to commit the offset?
AStep 5
BStep 4
CStep 6
DStep 8
💡 Hint
Check the 'Offset Commit' column for 'No commit' status.
According to variable_tracker, what is the offset_committed value after step 6?
ATrue
BFalse
CUnknown
DNot applicable
💡 Hint
Look at the 'offset_committed' row under 'After Step 6' column.
If the consumer commits offset immediately after processing, what changes in the execution_table?
AMessage will be lost
BConsumer will crash more often
CMessage will never be re-delivered
DMessage will be processed twice
💡 Hint
Refer to the flow where committing offset prevents re-delivery.
Concept Snapshot
At-least-once delivery in Kafka means messages may be delivered more than once but never lost.
Producer sends messages to topic.
Consumer reads and processes messages.
Consumer commits offset after processing.
If commit fails, message is re-delivered.
This ensures reliability but can cause duplicates.
Full Transcript
At-least-once delivery means Kafka guarantees each message is delivered to the consumer at least once. The producer sends a message to a Kafka topic. The consumer polls and processes the message. After processing, the consumer commits the offset to mark the message as done. If the consumer crashes before committing, Kafka will re-deliver the message when the consumer restarts. This causes the message to be processed again, ensuring no message is lost but duplicates can happen. Committing the offset is key to preventing re-delivery. This flow ensures reliability in message delivery.