Copying data to multiple servers
Day 122 of 149
👉 Full deep-dive with code examples
The Backup Copy Analogy
Important documents:
- One copy at home
- One copy at the bank
- One copy at your lawyer's
If your house burns down, you still have copies!
Database Replication keeps copies of your database in multiple places!
Why Replicate?
Safety:
- If one server fails, another replica may still have the data (and can take over, depending on your setup)
- Can reduce data-loss risk, but replication is not a full backup strategy by itself
Speed:
- Users far away can read from a nearby replica
- Can reduce read latency for globally distributed users
Availability:
- One server down → Others handle requests
- Less downtime for users (depending on failover and client behavior)
Types of Replication
Primary-Replica:
Primary (writes) ──→ Replica 1 (reads)
└──→ Replica 2 (reads)
- One leader accepts writes
- Replicas get copies, handle reads
Multi-Primary:
- Multiple servers accept writes
- More complex, handles conflicts
The Trade-offs
Consistency:
- Replicas might be slightly behind
- User writes, then reads from replica = might see old data
Complexity:
- Managing multiple servers
- Handling conflicts if two writes happen
Common Uses
- Global apps → Replicas in each region
- High-traffic sites → Spread read load
- Disaster recovery → Backup in different location
In One Sentence
Database Replication copies your data to multiple servers for safety, speed, and availability when one server isn't enough.
🔗 Enjoying these? Follow for daily ELI5 explanations!
Making complex tech concepts simple, one day at a time.
Top comments (0)