Search code examples
apache-kafkakafka-transactions-api

What are Kafka transactions?


What do transactions mean in Kafka? Of course I know the ordinary SQL transactions: A transaction is a sequence of operations performed (using one or more SQL statements) on a database as a single logical unit of work

So does it mean it's possible to send something to Kafka, and if something going wrong it will be rolled back (erase messages from partitions?)
And is it possible to write to different topics in a transaction?


Solution

  • The Transactional Producer allows to send data to multiple partitions and guarantees all these writes are either committed or discarded. This is done by grouping multiple calls to send() (and optionally sendOffsetsToTransaction()) into a transaction.

    Once a transaction is started, you can call commitTransaction() or abortTransaction() to complete it.

    Consumers configured with isolation.level=read_committed will not receive messages from aborted transactions.

    For more details, check the Message Delivery Semantics section in the docs