| Users / Data Size | 100 Users | 10K Users | 1M Users | 100M Users |
|---|---|---|---|---|
| Data Volume | Small (MBs to GBs) | Medium (GBs to TBs) | Large (TBs to PBs) | Very Large (PBs+) |
| Replication Type | Simple master-slave replication | Asynchronous replication with read replicas | Multi-region replication with conflict resolution | Geo-distributed multi-master replication with sharding |
| Latency Tolerance | Low latency acceptable | Some replication lag tolerated | Eventual consistency common | Strong consistency challenging, eventual consistency preferred |
| Replication Lag | Minimal, near real-time | Seconds to minutes | Minutes to hours | Hours, depending on region and network |
| Failure Handling | Manual failover possible | Automated failover with monitoring | Conflict detection and resolution needed | Complex conflict resolution and partition tolerance |
Data replication strategies in HLD - Scalability & System Analysis
At small scale, the primary database server becomes the bottleneck due to write load and replication overhead.
As users grow, replication lag increases causing stale reads and inconsistent data views.
Network bandwidth limits cross-region replication speed at large scale.
Conflict resolution complexity grows with multi-master setups, impacting performance and consistency.
- Horizontal scaling: Add read replicas to distribute read traffic and reduce load on master.
- Asynchronous replication: Use async replication to reduce write latency but accept eventual consistency.
- Multi-region replication: Deploy replicas in multiple regions to reduce latency for global users.
- Sharding: Partition data by key ranges or user segments to distribute load and storage.
- Conflict resolution: Implement application-level or database-level conflict handling for multi-master replication.
- Compression and batching: Compress data and batch replication updates to optimize network usage.
- Monitoring and automated failover: Use monitoring tools to detect failures and switch replicas automatically.
- Requests per second (RPS):
- 100 users: ~10-100 RPS
- 10K users: ~1K-10K RPS
- 1M users: ~100K-1M RPS
- 100M users: ~10M+ RPS
- Storage needed:
- 100 users: GBs
- 10K users: TBs
- 1M users: PBs
- 100M users: Multiple PBs to Exabytes
- Network bandwidth:
- Replication traffic grows with data volume and update frequency.
- Cross-region replication requires high bandwidth and low latency links.
Start by clarifying the scale and consistency requirements.
Discuss trade-offs between synchronous and asynchronous replication.
Explain how replication affects latency, availability, and consistency.
Describe how you would detect and handle replication lag and conflicts.
Outline scaling steps as user base grows, focusing on bottlenecks and solutions.
Your database handles 1000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first?
Answer: Add read replicas and implement connection pooling to distribute read load and reduce master bottleneck. Consider asynchronous replication to reduce write latency and monitor replication lag closely.
Practice
Solution
Step 1: Understand synchronous replication
Synchronous replication waits for all copies to confirm the write before completing the operation.Step 2: Compare with other strategies
Asynchronous replication does not wait, master-slave and multi-master describe topology, not timing.Final Answer:
Synchronous replication -> Option AQuick Check:
Strong consistency = Synchronous replication [OK]
- Confusing asynchronous with synchronous replication
- Mixing replication timing with replication topology
- Assuming master-slave means synchronous
Solution
Step 1: Define asynchronous replication
It copies data to replicas but does not wait for their confirmation before confirming the write.Step 2: Eliminate other options
Replicas confirm the data before the primary confirms the write requires replica confirmation before primary ack (synchronous); B copies before primary ack (incorrect); C describes synchronous behavior.Final Answer:
Data is copied to replicas without waiting for confirmation from them -> Option BQuick Check:
Asynchronous = no wait for replica confirmation [OK]
- Thinking asynchronous waits for replicas
- Confusing timing of data copy
- Mixing synchronous and asynchronous definitions
Solution
Step 1: Understand master-slave replication flow
Writes go to the master first, then are copied to slaves, usually asynchronously.Step 2: Check other options
Slaves do not receive writes first or alone; synchronous writes to all are not typical in master-slave.Final Answer:
The write is applied to the master and then asynchronously copied to slaves -> Option DQuick Check:
Master handles writes first in master-slave [OK]
- Assuming slaves can accept writes first
- Confusing synchronous with asynchronous replication
- Thinking slaves are independent masters
Solution
Step 1: Identify conflict in multi-master replication
Simultaneous writes cause conflicts that need resolution strategies.Step 2: Evaluate conflict resolution methods
Timestamps or version vectors help decide which write wins or how to merge.Final Answer:
Use conflict resolution strategies like timestamps or version vectors -> Option CQuick Check:
Conflict resolution = timestamps/version vectors [OK]
- Disabling multi-master writes defeats purpose
- Thinking asynchronous replication solves conflicts
- Removing replicas is impractical
Solution
Step 1: Analyze global user needs
Users worldwide require fast reads and writes from multiple locations.Step 2: Match replication strategy
Multi-master allows writes at multiple locations with conflict resolution, improving speed and availability.Step 3: Eliminate other options
Master-slave with synchronous writes is slow globally; single master limits write locations; no replication is slow and risky.Final Answer:
Multi-master replication with conflict resolution -> Option AQuick Check:
Global fast writes = multi-master + conflict resolution [OK]
- Choosing synchronous master-slave for global writes
- Ignoring conflict resolution in multi-master
- Using single master limits write speed globally
Ready to prove it?
Pass the test and this pattern moves unknown
