Single-Leader Replication: One Node to Rule Them All
Think of a single source of truth. One 'leader' server takes all writes, while 'follower' servers handle read traffic. This is the default for many databases like PostgreSQL and MongoDB to scale reads.
Why it exists
Replication was created to solve three core problems: first, increasing read throughput by spreading read queries across multiple machines; second, increasing availability so the system can survive a node failure; and third, reducing latency by placing data geographically closer to users.
The mental model
Think of a project manager (the leader) who is the only person allowed to update the master project plan. Team members (the followers) all have read-only copies. When the manager makes a change, they announce it, and everyone updates their copy in the same order. This ensures everyone is working from a consistent, if slightly delayed, version of the plan. All write requests go to the manager; read requests can go to anyone.
How it works
In a single-leader setup, one replica is designated the leader. It is the only node that accepts write operations (like INSERT, UPDATE, DELETE). The leader records these changes in a sequential replication log. The other replicas, called followers, subscribe to this log and apply the changes in the exact same order as the leader. Followers are typically used for read-only queries. This process can be synchronous, where the leader waits for a follower to confirm the write, or asynchronous, where it does not wait, trading durability for performance.
When to use it
Use single-leader replication when your application is read-heavy, as you can add more followers to scale out read capacity. It's the standard, well-understood model for many relational databases (PostgreSQL, MySQL) and some NoSQL databases (MongoDB). It provides a straightforward path to high availability: if the leader fails, a follower can be promoted to be the new leader in a process called failover.
When not to use it
Avoid this model if your application is extremely write-intensive, as all writes must go through a single leader, which can become a bottleneck. It's also less suitable for multi-datacenter deployments where a single leader in one region introduces high latency for writes from other regions. The failover process, while possible, is complex and can lead to data loss or split-brain scenarios if not handled carefully.
One canonical example
A standard PostgreSQL setup for high availability. There is one primary (leader) database that handles all writes. It streams its Write-Ahead Log (WAL) to one or more standby (follower) servers. These standbys can serve read-only queries. If the primary server fails, a failover process promotes one of the standbys to become the new primary. However, any writes committed to the old primary that hadn't yet been streamed to the newly promoted leader are lost.
Interview question
Which application characteristic is most likely to expose a performance bottleneck in a single-leader replication setup?
- a.The need for data to be available even if one server fails.
- b.A high demand for read operations from various client locations.
- c.The requirement for all data replicas to be eventually consistent.
- d.A workload dominated by frequent and substantial data modification requests.Correct
Why? this is the answer
The card states that single-leader replication should be avoided for "extremely write-intensive" applications because "all writes must go through a single leader, which can become a bottleneck." Therefore, a workload with frequent data modification requests directly targets this limitation. High read demand (B) is a strength, and availability (A) and consistency (C) are goals, not primary performance bottlenecks of this architecture.
Just read this? Test yourself on what you have been reading.
Read the original → timilearning.com
- #databases
- #architecture
- #replication
- #distributed systems
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on databases — each one lists the topics its interview covers.
See open roles