Replication
~2 mins read
Keeping the same data on multiple nodes
Why distribute data?
- fault tolerance
- lower latency, eg. multiple AZ, closer to users
- scale
A simple concept yet requires a lot of thought to implement well
Sync or Async?
- sync -> wait for a write to be replicated on all nodes
- async -> write to the leader and async write followers
- semi-sync -> write to the leader and some of the followers and async write others
What to replicate?
-
SQL statements
indeterministic, eg. now()
-
WAL (write ahead log)
depends on internal bytes layout of a specific db version, so an upgrade requires downtime
-
Row based
higher level, easier to parse for external systems, nodes might run different versions of db
-
Trigger based
more flexible, custom application code, more prone to bugs, greater overhead
How to replicate?
Multi-leader
Makes more sense in a multiple datacenter setup
Offline clients and collaborative editing are also similar to a multi leader setup