Data Systems
Data Replication
Replication copies data across multiple nodes to improve availability, reduce latency, and provide fault tolerance. The challenge is keeping replicas consistent as data changes.
- Availability â Replicas serve reads even if primary fails
- Latency â Users read from geographically close replicas
- Durability â Data survives individual node failures
Replication is the foundation of fault-tolerant distributed systems.
Leader-Follower Replication
The most common replication topology: one leader accepts writes, followers replicate the log.
Synchronous vs Asynchronous Replication
| Property | Synchronous | Asynchronous |
|---|---|---|
| Consistency | Strong | Eventual |
| Write latency | High (waits for all replicas) | Low (single node) |
| Availability | Lower (all replicas must be up) | Higher |
| Data loss risk | None (on commit) | Up to replication lag |
| Use case | Financial transactions | Social media feeds |
Replication Lag
Multi-Leader Replication
Multiple nodes accept writes, each replicating to all others.
When to Use Multi-Leader
- Multi-datacenter deployments for low-latency writes
- Offline clients that sync when reconnected
- Collaborative editing where multiple users edit simultaneously
Conflict Resolution
When two leaders update the same key concurrently, a conflict occurs.
Replication Topologies
| Topology | Pros | Cons |
|---|---|---|
| Linear | Simple, ordered | Slow propagation, single point of failure |
| Star | Fast propagation from center | Hub is bottleneck |
| Circular | No central bottleneck | Slow, fragile if one node fails |
| All-to-All | Fastest propagation | Conflict resolution complex |
Log-Based Replication
Most modern systems replicate via an append-only log.
Practice Exercises
-
Conceptual: Explain why synchronous replication is rarely used for all replicas in production. What is the alternative?
-
Design: Design a replication strategy for a global social media app where users write in their local region but must read their own writes immediately. How do you handle replication lag?
-
Conflict Resolution: Two users edit the same document offline. User A saves at 10:00:01, User B saves at 10:00:02. Both sync at 10:00:05. Design a conflict resolution strategy that preserves both users' intent.
-
Analysis: Compare linear, star, and all-to-all replication topologies for a 5-datacenter deployment. Which topology minimizes propagation delay? Which is most resilient?
What to Learn Next
-> Data Partitioning Horizontal partitioning, range vs hash partitioning, and rebalancing.
-> CAP Theorem Consistency models, availability, and partition tolerance.
-> Consistent Hashing Hash rings, virtual nodes, and load distribution.
-> Distributed Consensus Raft, Paxos, and leader election algorithms.
-> Databases SQL vs NoSQL, indexing, replication, and sharding.
-> Event-Driven Architecture Event sourcing, CQRS, and saga patterns.