Read-process-write becomes atomic: the output and the offset commit succeed or fail together.
props.put(ProducerConfig.TRANSACTIONAL_ID_CONFIG, "orders-processor-1");
producer.initTransactions();
producer.beginTransaction();
producer.send(outputRecord);
producer.sendOffsetsToTransaction(offsets, consumerGroupMetadata);
producer.commitTransaction();
// consumer side:
props.put(ConsumerConfig.ISOLATION_LEVEL_CONFIG, "read_committed");
Without read_committed the downstream consumer sees aborted records.
Exactly-once holds only INSIDE Kafka - an external HTTP call is still at-least-once.
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-08-11