| Users | Traffic Characteristics | Database Load | Read Replica Usage | Notes |
|---|---|---|---|---|
| 100 users | Low read/write requests | Single primary DB handles all | Not needed | Simple setup, no replicas |
| 10,000 users | Moderate reads, writes increasing | Primary DB under moderate load | 1-2 read replicas for read scaling | Offload read queries to replicas |
| 1,000,000 users | High read volume, writes steady | Primary DB write bottleneck possible | Multiple read replicas distributed geographically | Use replicas for read-heavy traffic, reduce latency |
| 100,000,000 users | Very high read/write traffic | Primary DB write bottleneck, network limits | Sharded replicas, geo-distributed clusters | Advanced replication, caching, and sharding needed |
Read replicas in HLD - Scalability & System Analysis
At small to medium scale, the primary database becomes the first bottleneck because it handles all write operations and read queries if no replicas exist. As user count grows, the primary server's CPU, disk I/O, and network bandwidth limit its ability to serve all requests quickly.
Without read replicas, read-heavy workloads overwhelm the primary DB, causing slow responses and timeouts.
- Read Replicas: Create one or more read-only copies of the primary database to handle read queries, reducing load on the primary.
- Load Balancing: Distribute read requests evenly across replicas to maximize throughput.
- Geographical Distribution: Place replicas closer to users to reduce latency.
- Write Optimization: Keep writes on the primary; optimize with batching or queueing.
- Caching: Use in-memory caches (e.g., Redis) to reduce database reads further.
- Sharding: For very large scale, split data across multiple primary-replica clusters by key ranges.
- Assuming 10,000 users, each making 1 request per second: 10,000 QPS total.
- Primary DB can handle ~5,000 QPS; read replicas needed to handle remaining reads.
- Each read replica can handle ~5,000 QPS; 2 replicas cover 10,000 QPS reads.
- Storage: Replicas require same storage as primary; plan for data growth.
- Network bandwidth: 1 Gbps (~125 MB/s) can support ~10,000 QPS with small query sizes.
When discussing read replicas in an interview, start by explaining the primary database bottleneck under read-heavy workloads. Then describe how read replicas offload read queries to improve scalability and reduce latency. Mention trade-offs like replication lag and eventual consistency. Finally, discuss how to scale replicas horizontally and combine with caching and sharding for very large systems.
Your database handles 1000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first?
Answer: Add read replicas to offload read queries from the primary database. This reduces load on the primary and allows the system to handle increased read traffic without immediate changes to the primary server.
Practice
read replicas in a system design?Solution
Step 1: Understand the role of read replicas
Read replicas are copies of the primary database used mainly to handle read requests.Step 2: Identify the benefit in system design
By directing read queries to replicas, the primary database is less loaded, improving read scalability.Final Answer:
To improve read scalability by offloading read queries from the primary database -> Option CQuick Check:
Read replicas = improve read scalability [OK]
- Thinking read replicas improve write performance
- Confusing read replicas with backup systems
- Assuming read replicas encrypt data
Solution
Step 1: Understand replication types
Read replicas usually use asynchronous replication, meaning data updates are sent with some delay.Step 2: Identify the correct replication behavior
Because replication is asynchronous, replicas may not always have the latest data instantly.Final Answer:
Replication is asynchronous, so replicas may lag behind the primary database. -> Option DQuick Check:
Replication = asynchronous lag possible [OK]
- Assuming replication is always synchronous
- Thinking replication triggers only on restart
- Confusing replication of queries with replication of data
Solution
Step 1: Separate reads and writes
Writes must go to the primary database to maintain data consistency.Step 2: Offload reads to replicas
All read requests should be directed to read replicas to reduce load on the primary and improve read response.Final Answer:
Send all 300 read requests to the read replicas and 100 writes to the primary -> Option AQuick Check:
Reads to replicas, writes to primary = best practice [OK]
- Sending writes to replicas causing data inconsistency
- Overloading primary with all requests
- Randomly distributing requests without separation
Solution
Step 1: Identify cause of stale data
Stale data usually happens because asynchronous replication delays updates to replicas.Step 2: Fix by changing replication method
Using synchronous replication ensures replicas have the latest data but may impact performance.Final Answer:
Replication is asynchronous causing delay; fix by using synchronous replication -> Option BQuick Check:
Stale data = async replication delay [OK]
- Restarting replicas without checking replication
- Adding replicas without fixing replication lag
- Reducing reads instead of addressing replication
Solution
Step 1: Understand scalability needs
Millions of reads require multiple replicas to distribute load effectively.Step 2: Balance data freshness and performance
Asynchronous replicas scale well but have lag; cache invalidation helps keep data fresh for users.Step 3: Evaluate other options
Single synchronous replica limits scalability; sending all to primary causes bottlenecks; no cache hurts freshness.Final Answer:
Use multiple asynchronous read replicas with eventual consistency and implement cache invalidation on writes -> Option AQuick Check:
Multiple async replicas + cache = scalable & fresh [OK]
- Choosing single synchronous replica causing bottlenecks
- Ignoring cache leading to stale reads
- Sending all traffic to primary causing overload
Ready to prove it?
Pass the test and this pattern moves unknown
