End-to-End Delivery Semantics
Deconstruct At-Least-Once, At-Most-Once, and Exactly-Once delivery guarantees, and understand why end-to-end correctness requires client-broker-sink cooperation.
Marketing materials for distributed streaming platforms frequently advertise "out-of-the-box exactly-once processing". In distributed systems theory, however, there is no magic button that guarantees a message will be produced, transported, and stored in a database exactly once without explicit application design.
A distributed system comprises multiple failure boundaries: the producer network, broker disk persistence, consumer group processing, and external database sinks.
In this lesson, you will deconstruct the three core delivery semantics and learn what Apache Kafka guarantees on its own versus what your application architecture must provide.
01The Three Delivery Semantics
Every distributed messaging interaction falls into one of three semantic categories:
1. At-Most-Once Delivery
Messages may be lost, but are never duplicated.
- How it happens: The producer sends messages with
acks=0(no retries), or a consumer commits its offset to__consumer_offsetsbefore writing the data to downstream storage. - The Failure Scenario: If the consumer process crashes while writing to the database after committing the offset, the record is gone. Upon restart, the consumer reads the next offset, skipping the lost message forever.
- Valid Use Cases: Metrics, log telemetry, or non-critical sensor streams where occasional lost data points are acceptable.
2. At-Least-Once Delivery (The Industry Standard)
Messages are guaranteed never to be lost, but duplicates may occur.
- How it happens: The producer configures
acks=allwith retries, and the consumer commits its offset only after the business logic and database writes succeed. - The Failure Scenario: If the consumer writes to the database successfully, but a network disconnect prevents
commitSync()from reaching the broker, the consumer group rebalances. The replacement consumer re-reads the uncommitted message and attempts to insert it into the database a second time. - Operational Reality: At-Least-Once is the foundation of reliable systems, but it requires that downstream consumers be idempotent to absorb duplicates safely.
3. Exactly-Once Delivery (EOS)
Every message affects final system state exactly once, with zero message loss and zero duplicate side effects.
- What Kafka EOS actually means: Kafka's native Exactly-Once Semantics (introduced in KIP-98) guarantees that in a Kafka-to-Kafka pipeline (consuming from a Kafka topic, transforming records, and writing to another Kafka topic), records and consumer offsets are committed atomically.
- What Kafka EOS does NOT cover: If your consumer reads a Kafka topic and writes to an external PostgreSQL database or sends an email via SendGrid, Kafka cannot control external transactional rollbacks. If the database commit succeeds but the Kafka offset commit fails, the message will be read again.
Loading the rest of the lesson…