Middle+
How is delivery guaranteed in Kafka? Describe the entire chain from preparation to processing by the receiver.
sobes.tech AI
Answer from AI
The guarantee of message delivery in Kafka is ensured by several mechanisms at different stages:
-
Message preparation (producer):
- The producer sends a message to a specific topic and partition.
- The acknowledgment level (acks) can be configured:
acks=0— no confirmation is waited for (no delivery guarantee).acks=1— waits for confirmation from the partition leader.acks=all(or-1) — waits for confirmation from all replicas, ensuring maximum reliability.
- The producer can retry sending in case of errors (retries).
-
Storage in the broker:
- The message is written to the partition log.
- Replication between brokers provides fault tolerance.
- A message is considered confirmed when the required number of replicas has acknowledged it.
-
Processing by the consumer:
- The consumer reads messages from the partition by offset.
- To guarantee delivery, consumers can use manual offset commits after successful processing.
- If the consumer crashes before committing, the message will be read again.
Thus, the delivery guarantee chain is built on:
- producer configuration (acks, retries),
- replication and confirmation of record writing in brokers,
- processing control and confirmation by consumers.
This allows achieving "at least once" delivery, and with additional processing logic — "exactly once".