DEV Community

Rizwan Saleem
Rizwan Saleem

Posted on

Database replication: leader-follower, multi-leader, and quorum patterns

Database replication: leader-follower, multi-leader, and quorum patterns

Database replication is essential for high availability, read scaling, and disaster recovery. The replication pattern you choose determines your system's consistency, latency, and failure tolerance.

Leader-follower replication is the simplest and most common pattern. One node handles all writes. One or more followers replicate data from the leader and handle read queries. If the leader fails, a follower is promoted. Leader-follower works well for read-heavy workloads but has a single point of failure for writes.

Synchronous replication ensures that the leader waits for at least one follower to confirm a write before acknowledging it to the client. This guarantees data durability on failover. The tradeoff is higher write latency.

Asynchronous replication is the default in most databases. The leader processes writes independently and streams changes to followers asynchronously. Replication lag can vary. Asynchronous replication provides the best write performance and works well when some data loss on failover is acceptable.

Multi-leader replication allows multiple nodes to accept writes, which are then replicated to all other leaders. This pattern improves write availability and enables writes in multiple geographic regions. The complexity is conflict resolution.

Quorum replication is used in distributed databases like Cassandra. A write is acknowledged when a configurable number of nodes confirms it. Reads also require a quorum. Quorum-based systems can survive node failures without data loss.

Choose your replication strategy based on your consistency requirements. Leader-follower with synchronous replication provides strong consistency at the cost of latency. Multi-leader provides global write availability at the cost of complexity.

-

Rizwan Saleem | https://rizwansaleem.co

Top comments (0)