Why a Prepare and Commit writes are needed in Transaction log


I try to get intimate with the server source code. I noticed for any given event write,

there’s a Prepare and a Commit write in the transaction log. In the architecture overview

documentation, it’s mentioned that while it also applied in a single node settings, it’s helpful

in replicated scenarios.

Any chance to know why because I can’t get it and I’m trying to get deep understanding of database design.

Thanks in advance for your help.



I don’t get it.

When writing a batch of events, the first one is flagged with TransactionBegin while the last one is flagged with TransactionEnd,

I can’t see what Prepare and Commit are bringing here.

when you write with a transaction, a transactionend is written separately on commit. which allows you to write more than a single batch in a transaction.

Thanks James for you response.

I did my homework and after staring at code for last couple of days I think I figured it out.

I noticed there is a PrepareAck message sent to each node of a cluster. So I imagine if the prepare phase has failed, the transaction is rolled back for the entire cluster.

The commit message is there to assess the changes have been materialized (I suppose it means it can be seen from the outside) across the system.

If it’s not possible then the transaction is rolled back.

Greg’s responses are often succinct but are a great source of motivation :slight_smile:


Transaction 1 Start
Transaction 2 Start
Transaction 1 Write A
Transaction 1 Write B
Transaction 2 Write C
Transaction 1 Write D
Transaction 1 Commit
Transaction 2 Commit

The prepare/commit is needed due to multiple operations. There is also
a ton of logic associated as when read this should result in:


As transaction 1 is committed before transaction 2. There are
literally hundreds of tests around this type of logic.