In this blog post I will be covering one approach to implementing replication logs… statement-based replication.
How does leader based replication work under the hood? 🤔
Several different replication methods are used in practice (due to the multitude of edge cases!)
- Statement-based replication
- Leader logs every request, statement that it executes and send that statement log to the followers
- For RDBMS databases, CRUD operations are forwarded to followers
- This is then parsed and then this executes as SQL statements as if it has been received from a client
- If statements use an auto increments column or if they depend on existing data in database
- They must be executed in exactly the same order from each replica
- This can be limiting in a concurrently run applications
- They must be executed in exactly the same order from each replica
- Statements that have side effects
- 👉 Triggers
- 👉 Stored procedures
- 👉 User defined functions
- These can have different side effects on each replica
- Unless the side effects are absolutely deterministic ⚠️
- It is possible to work around these issues ✅
- Such as:
- A leader can replace any none deterministic function calls with fixed return value when a statement is logged
- Therefore, followers can all get the same value
- Such as:
- It is possible to work around these issues ✅
- Unless the side effects are absolutely deterministic ⚠️
Final note
However, as there are so many edge cases, other replication methods are now generally preferred.
Statement-based replication used in MySQL before version 5.1 and it it still used today, because it is compact.
- But by default MySQL now switched to row based replication if there is a none determinism in a function
In addition, VoltDB did use statement-based replication, which was made safe by requiring transactions to be deterministic.
For further reading on this MySQL has an documentation on the pros and cons of this for both statement-based replication and row-based replication. https://dev.mysql.com/doc/refman/8.0/en/replication-sbr-rbr.html
Up next on replication logs…
- Write-ahead Log (WAL) shipping
- Logical (row-based) log replication
- Trigger based replication
📚 Further Reading & Related Topics
If you’re exploring statement-based replication and log management in distributed systems, these related articles will provide deeper insights:
• Distributed Data-Intensive Systems: Logical Log Replication – Learn how logical logging helps maintain data consistency and complements statement-based replication techniques.
• Resolving Write Conflicts in Distributed Data-Intensive Systems – Understand different strategies for managing replication conflicts and ensuring data integrity in distributed databases.









Leave a comment