Your application requires exactly-once processing semantics. How do you configure Kafka to achieve this?

Achieving exactly-once processing semantics in Kafka requires combining an idempotent producer, transactional writes, and offset commits that are tied to the same transaction as the processing output.

Key Points

Example

A service that reads payment events, computes a balance update, and writes the result back to another topic can wrap the read-process-write cycle in a Kafka transaction so that if the process crashes mid-way, the partial output is never visible to downstream consumers and the offset isn't committed either.

Properties props = new Properties();
props.put("enable.idempotence", "true");
props.put("transactional.id", "balance-updater-1");

KafkaProducer<String, String> producer = new KafkaProducer<>(props);
producer.initTransactions();

try {
    producer.beginTransaction();
    producer.send(new ProducerRecord<>("balances", key, updatedBalance));
    producer.sendOffsetsToTransaction(offsets, consumerGroupId);
    producer.commitTransaction();
} catch (Exception e) {
    producer.abortTransaction();
}

Interview Tip

A concise interview answer is

I'd enable idempotence on the producer, use a transactional producer with a transactional.id to wrap the produce and offset commit in one atomic transaction via sendOffsetsToTransaction, and set consumers to read_committed isolation, or simply use Kafka Streams' exactly_once_v2 guarantee if the workload is a stream processing job.

Last updated: 16 July 2026

Previous question: You notice that your Kafka consumers are lagging behind, unable to keep up with the rate at which messages are being produced. What steps would you take to address this issue?

Next question: You need to update the schema of the messages being produced to a Kafka topic without disrupting the existing consumers. How do you handle schema evolution in Kafka?

More Kafka (Optional) interview questions

All Kafka (Optional) questions