Scrivio Interview library
ConceptIntermediate6 min read · updated 12 November 2026

What does exactly-once semantics in Kafka actually guarantee, and what does it not cover? A product manager hears "Kafka is exactly-once" and assumes no customer will ever be charged twice.

Kafka's exactly-once semantics guarantee that a read-process-write cycle inside Kafka happens once: the consumed offsets and the records produced from them are committed together in one transaction, and consumers reading with isolation.level=read_committed never see records from aborted transactions. It says nothing about side effects outside Kafka, such as calling a payment API or writing to a database. To make sure no customer is charged twice, the payment service still needs idempotent operations, such as an idempotency key or a unique constraint on the payment id.

Why this question is asked

"Kafka is exactly-once" is one of the most misunderstood slogans in our field. It is true for a specific, narrow pattern, and people outside engineering often hear it as a promise about the business outcome. Interviewers ask this question because explaining the gap clearly, to engineers and to a product manager, is a sign that we have really used the feature. In this answer, we will recap the delivery guarantees, see exactly what Kafka transactions cover, follow a charge through the system to find where a duplicate can still happen, and then design the deduplication that gives an effectively-once outcome.

1A Quick Recap of Delivery Guarantees

Messaging systems describe what can go wrong when a component crashes or a network call times out. At-most-once means a message may be lost but never processed twice. At-least-once means a message is never lost but may be processed more than once, because when we are not sure whether it worked, we try again. Exactly-once would mean every message affects the result once, with no loss and no duplicate.

Retries are the root of duplicates. A producer sends a record, the broker writes it, and the acknowledgement is lost; the producer retries and the record is written twice. A consumer processes a record and crashes before committing its offset; after restart it processes the record again. Kafka's default for a well-configured consumer is at-least-once.

2What Kafka Transactions Actually Cover

Kafka adds two features. The idempotent producer, on by default since Kafka 3.0, gives each producer an id and a sequence number per partition, so the broker drops a retried batch it already has. That removes duplicates caused by producer retries.

Transactions go further. A transactional producer can write records to several partitions and also commit a consumer group's offsets, all as one atomic unit: either all of it becomes visible or none of it does. That is exactly what a stream processor needs. It reads input records, computes output records, and in one transaction writes the outputs and marks the inputs as consumed. If it crashes halfway, the transaction is aborted, the offsets were not committed, and the inputs are processed again, but the half-written outputs are never seen.

Java
producer.initTransactions();
while (running) {
ConsumerRecords<String, Order> in = consumer.poll(Duration.ofMillis(200));
producer.beginTransaction();
for (var r : in) producer.send(new ProducerRecord<>("invoices", r.key(), toInvoice(r.value())));
producer.sendOffsetsToTransaction(nextOffsets(in), consumer.groupMetadata());
producer.commitTransaction(); // outputs and input offsets become visible together
}
Step throughWhat exactly-once covers
  1. Source topic: ordersinside the guarantee
  2. Processor: read, compute, writeoffsets and outputs commit in one transaction
  3. Output topic: payment-requestsread_committed consumers see each record once
  4. Payment service calls the card provideroutside the guarantee
  5. Card provider and bankoutside the guarantee: needs idempotency keys

5 layers, from the top down. Step through them one at a time.

The guarantee ends at the last Kafka topic.

"Seen" depends on the reader. Records from aborted transactions are physically in the log. A consumer with the default isolation.level=read_uncommitted reads them anyway. Only consumers with isolation.level=read_committed skip aborted records and wait for open transactions to finish. So exactly-once inside Kafka needs both sides: a transactional producer and read_committed consumers.

3Where a Customer Can Still Be Charged Twice

Now follow a payment through the system. A payment service consumes payment-requests, calls the card provider's API to charge the customer, and then commits its offset. Suppose the API call succeeds but the service crashes before the offset is committed. On restart, the service reads the same request again and charges the customer again.

Kafka transactions cannot prevent this, because the charge is not a Kafka write. Kafka can roll back records it holds, but it cannot roll back an HTTP call to a card provider or a row in a separate database. Even putting the listener in a Kafka transaction only means the offset commit is aborted, which makes the redelivery more certain, not less.

Step throughA duplicate charge outside Kafka
payment-requestsPayment serviceCard provider
request 991 (charge 40.00)
charge 40.00
approved
crash before committing the offset
request 991 again after restart
charge 40.00 again

6 messages in order. Play them, or step through them one at a time.

Every Kafka guarantee held, and the customer still paid twice.

4Getting an Effectively-Once Outcome

What we want is not exactly-once delivery but an effectively-once outcome: no matter how many times a request is processed, the customer is charged once. The standard tool is idempotency. Every payment request carries a stable id created once at the source, and every side effect uses it to recognise a repeat.

For the card provider, we send the payment id as an idempotency key; most payment APIs return the original result for a repeated key instead of charging again. For our own database, we record the payment id in the same database transaction as the change, with a unique constraint, so a second attempt fails or does nothing.

Java
@KafkaListener(topics = "payment-requests", groupId = "payment-service")
@Transactional // database transaction
void onRequest(PaymentRequest req) {
if (payments.existsById(req.paymentId())) return; // already done: skip
var result = cardProvider.charge(req.amount(), req.card(),
/* idempotency key */ req.paymentId()); // provider returns the first result on a repeat
payments.save(new Payment(req.paymentId(), result)); // primary key = paymentId
}

Notice that each layer protects a different gap. The database check skips work we know we finished. The idempotency key covers the window where the charge succeeded but the database write did not, because the provider remembers the key. The unique key covers two instances racing on the same request after a rebalance.

5Explaining It to the Product Manager

For the product manager, the honest summary is that Kafka guarantees that messages between our own services are not lost or doubled inside Kafka, but charging a card happens in another company's system, and that step is protected by our own design. The promise 'no customer is charged twice' is a business requirement that we meet with idempotency keys and checks, and we verify it by reconciling our payment records against the provider's settlement reports every day.

That framing avoids two mistakes: believing the slogan and skipping deduplication, or the opposite, believing exactly-once is useless. It is very useful for Kafka-to-Kafka processing; it just is not the whole story.

6Follow-up questions

If we use Spring's ChainedKafkaTransactionManager or a Kafka plus database transaction, are we covered?

Not fully. Synchronising a Kafka transaction with a database transaction commits one after the other, not atomically; a crash between the two commits can leave them out of step. Spring Kafka has deprecated the chained transaction manager in favour of nesting transactions, but either way the safe design is still an idempotent consumer, for example storing processed ids in the database.

What does read_committed cost?

Consumers cannot read past the last stable offset, the first offset of a still-open transaction. So a long-running transaction delays every read_committed consumer of that partition, and end-to-end latency includes the producer's commit interval. Keeping transactions short keeps this cost small.

Does exactly-once also cover Kafka Connect sinks?

Only if the connector implements it, usually by storing offsets in the target system atomically with the data or by idempotent writes. Kafka itself cannot make an external write exactly-once; the sink has to.

7Conclusion

In this answer, we saw that Kafka's exactly-once semantics cover a read-process-write cycle inside Kafka: outputs and consumed offsets commit atomically, and read_committed consumers ignore aborted records. They do not cover side effects outside Kafka, such as calling a payment API, where a crash between the call and the offset commit causes a repeat. For those, we use idempotency keys, unique constraints and stored processed ids to get an effectively-once outcome, and we verify it with reconciliation.

What to say in the interviewAbout 80 seconds aloud

Open with

Kafka's exactly-once is real, but it's narrower than the slogan. It covers read-process-write inside Kafka: a transactional producer writes its output records and commits the consumer's offsets with sendOffsetsToTransaction in one atomic transaction, so either both become visible or neither does.

Then, if they want more

The idempotent producer removes duplicates from producer retries. Consumers also have to read with isolation.level=read_committed, otherwise they see records from aborted transactions. What it doesn't cover is any side effect outside Kafka.

If the payment service calls the card provider and then crashes before committing its offset, it will read the same request again after restart and charge again, and no Kafka setting can roll back an HTTP call.

So for 'no customer is charged twice' we need idempotency: every payment has a stable id from the source, we send it as an idempotency key to the provider so a repeat returns the first result, and we store the payment id with a unique constraint in the same database transaction as the payment record, so a second attempt is skipped.

To the product manager I'd say Kafka guarantees our internal messages aren't doubled, and the charge itself is protected by our own design, which we verify by reconciling against the provider's settlement reports.

About this answer

Last updated
12 November 2026
Versions it names
Kafka 3.0
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What does exactly-once semantics in Kafka actually guarantee, and what does it not...": https://scrivio-interview-library.netlify.app/spring-boot/kafka/4dbc3c0989/