📨 Apache Kafka Intermediate

What are Kafka Transactions?

Answer

Kafka Transactions enable atomic writes across multiple partitions and topics — all messages in a transaction are either all committed or all aborted. Use cases: read from one topic, process, write results to another topic atomically (no partial writes visible to consumers). Setup: configure the producer with a unique transactional.id, then: producer.initTransactions(); producer.beginTransaction(); write to multiple topics; producer.commitTransaction(); or producer.abortTransaction(); on error. Consumers must set isolation.level=read_committed to only see committed transactional messages (not aborted or in-progress). Transactions are the building block for exactly-once processing in Kafka Streams (exactly_once_v2 mode). They come with throughput overhead — use only when exactly-once is required.