Skip to content

3.8. What are Kafka Transactions, and how do they work?

Answer: Kafka transactions allow a producer to write multiple records atomically across partitions and topics, and they work with read-committed consumers to hide aborted transactional writes. They are useful when an application needs coordinated event publication and wants stronger exactly-once semantics within Kafka. A typical flow is: begin transaction, write several output records, optionally commit consumer offsets as part of the transaction, and then commit the transaction. If the application crashes before commit, the transaction can be aborted and transactional consumers will not expose those records as committed results. I would still be careful with the phrase exactly once: Kafka can provide exactly-once processing guarantees for supported Kafka-to-Kafka workflows, but external side effects such as a database update need their own design. Transactions increase coordination and can reduce throughput, so they should be used where the consistency benefit is worth the cost.

Interview close: The key is to choose the Kafka behavior that matches the required durability, ordering, throughput, and recovery guarantees.