Advanced Topic 37 of 51 Databases
Replication
Copying data across servers for availability.
How it works
Replication keeps copies of data on multiple servers for availability, read scaling and disaster recovery. In primary-replica setups, writes go to the primary and changes stream to replicas by shipping the log, either synchronously, where the commit waits for the replica, or asynchronously, which is faster but can lose recent commits on failover. Multi-primary replication accepts writes in several places and requires conflict resolution.
Step-by-step walkthrough
- Writes go to the primary.
- Changes are streamed to replicas.
- The same stream reaches the second replica.
- Reads can be served by replicas.
- If the primary fails a replica is promoted, with replication lag as the risk.
Where it is used
Read-heavy applications direct queries to replicas, failover systems promote a replica when the primary fails, and geographically distributed copies reduce latency and survive regional outages.
Common pitfall
Asynchronous replicas lag, so reads may be stale; read-your-own-writes needs care. Failover can cause split brain if two nodes think they are primary. Replication is not a backup, since mistaken deletes replicate too. Monitor lag, test failover and design for eventual consistency.
Where it fits in the course
Replication is topic 37 of 51 in Databases, rated Advanced. It follows Database Partitioning. The next topic is Sharding.
Practice and explore
- Open the interactive lesson, with a mini quiz.
- Take the Databases quiz.
How to study this topic
- Read the explanation above and restate the definition in your own words.
- Open the interactive lesson and answer its mini quiz.
- Read the common pitfall, then write a short example that avoids it.
- Check your understanding in the Databases quiz, and revisit the topic if you miss a question.
Frequently asked questions
What is Replication?
Where do people use Replication?
What is the most common mistake with Replication?
What should I learn before this topic?
How can I practice it?
Is Replication hard to learn?
How long does it take to learn Replication?
Which topics are related to Replication?
What should I study after Replication?
Related topics
- Database Partitioning (Databases)
- Sharding (Databases)
- Recovery and Logging (Databases)
- NoSQL Databases (Databases)
- Replication Strategies (Distributed Systems & Cloud)