Multi-Leader Replication
Also known as master-master or active/active. More than one node accepts writes.
Use Cases
- Multi-Datacenter: A leader in each datacenter. Tolerates DC outages and gives better local write performance.
- Offline Clients: Devices (phones, laptops) act as local leaders.
- Collaborative Editing: Google Docs, Etherpad.
Conflict Avoidance
The simplest way to deal with conflicts is to avoid them. If the application ensures that all writes for a particular record go to the same leader, conflicts cannot occur.
- Example: Route all requests from a user to the same datacenter (the "home" DC) based on their location.
Convergence
If conflicts do happen, the database must resolve them in a way that all replicas arrive at the same final state (Convergence).
- Last Write Wins (LWW): Uses timestamps. Risky because clocks are unreliable.
- Version Vectors: Used in leaderless systems to track the history of changes across multiple nodes.
Knowledge Check
What is the most common strategy for dealing with multi-leader write conflicts?
Conflict Detection and Manual Merge
Conflict Avoidance (Routing to a specific leader)
Locking the entire database