What is database replication, and how do synchronous and asynchronous replication differ?
MediumConceptDatabases: Replication & Sharding
Answer
Replication keeps copies of the same data on several nodes for availability, read scaling and durability. In the common leader-follower setup, all writes go to the leader, which streams changes to followers that serve reads.
- Synchronous: the leader waits for a follower to confirm before acknowledging, so no acknowledged write is lost on failover, but writes are slower and stall if that follower is down.
- Asynchronous: the leader acknowledges immediately; writes are fast, but followers lag and recent writes can be lost if the leader fails. Many systems keep one synchronous follower and the rest asynchronous.
- Replication lag causes stale reads; routing a user's reads to the leader shortly after they write provides read-your-writes consistency.
- Multi-leader and leaderless setups accept writes on several nodes but must resolve conflicts.
More in Databases: Replication & Sharding
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | How do you choose between a SQL and a NoSQL database? | Concept | Easy | Read the answer to How do you choose between a SQL and a NoSQL database? | |||
| 2 | What is database replication, and how do synchronous and asynchronous replication differ? | Concept | Medium | Read the answer to What is database replication, and how do synchronous and asynchronous replication differ? | |||
| 3 | What is sharding, and how do you choose a shard key? | Concept | Medium | Read the answer to What is sharding, and how do you choose a shard key? | |||
| 4 | What problems does sharding introduce, and how are they handled? | Concept | Hard | Read the answer to What problems does sharding introduce, and how are they handled? |