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.
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();
}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