Skip to main content

Question 40 of 50

What is Exactly Once?

SeniorTech Lead

Question

"What is Exactly Once in Kafka? Does it eliminate the duplication problem for good?"

What the interviewer wants to assess

This section's most important trap question — tests whether the candidate understands this guarantee's exact scope, not just its name.

Resposta rápida

Exactly Once means the message is processed exactly once, with no loss and no duplication — via an idempotent producer and transactions. But that guarantee covers the Kafka-to-Kafka flow; any side effect outside Kafka (database, HTTP call, email) still requires its own idempotency.

Resposta nível Sênior

Kafka's exactly-once semantics (EOS) uses an idempotent producer (enable.idempotence=true, which avoids duplication caused by the producer's own automatic retries) combined with transactions (KafkaTransactionManager), guaranteeing that reading from a topic, processing, and writing to another topic happens as an atomic unit. That's real and it works — but only within the Kafka ecosystem. The moment processing includes a write to an external database or a call to an API, that write falls outside the Kafka transaction, and a failure right there can still produce duplication of that external effect. That's why, even when using exactly-once semantics, systems that integrate Kafka with external databases and APIs still need idempotency in those integrations.

In-depth explanation

See "Exactly Once: what it covers and what it doesn't" in Chapter 10.

Exemplo financeiro

A consumer that reads from a topic, transforms the data, and writes to another Kafka topic can safely use exactly-once semantics with full protection. But if that same consumer also writes the result to a relational database, that specific write still requires its own idempotency check (Chapter 11) — Kafka's exactly-once doesn't protect it.

"Exactly Once means the message is never processed twice, full stop"

That's the answer that fails senior interviews. The guarantee is real, but bounded to Kafka's internal flow via transactions — not to external side effects, which are the most common case in real systems.

Pode vir a seguir

Likely follow-ups: "what is Idempotency?" and "how would you avoid duplicate processing in an integration with an external database?".

Related chapters