Read replicas: what they are and when to use them
Copies of your database that stay in sync with the primary and serve read queries. How replication works, what replication lag means for your users, and when replicas are (and aren't) the right tool.
In one sentence
A read replica is a copy of the database that receives every change from the primary and answers read queries, so you can add read capacity without touching writes.
How it works
All writes go to one primary. The primary records each change in a log and streams it to one or more replicas, which apply the same changes. Your app sends writes to the primary and spreads reads across the replicas.
Replication lag
Most replication is asynchronous: the primary confirms the write before replicas have it. Usually the gap is milliseconds, but under heavy load, long transactions or network trouble it can grow to seconds or more.
The visible symptom: a user saves something, the page reloads from a replica, and their change isn't there yet.
- Read-your-writes: after a user writes, send that user's reads to the primary for a few seconds (or until the replica catches up).
- Sticky by version: remember the write's position in the log and only read from replicas that have reached it.
- Critical reads on the primary: "show my balance before paying" always reads the primary.
- Synchronous replicas for zero lag, paying with slower writes.
When to use read replicas
Good fit
- The database CPU is mostly spent on reads
- Reporting or analytics queries that shouldn't slow down the app
- Serving users in another region with a nearby copy
- A ready standby: a replica can be promoted if the primary dies
Not the fix
- Writes are the bottleneck: every replica must apply every write too (look at sharding, queues, batching)
- Reads that must always be perfectly fresh
- A missing index: fix the query before adding machines
Key takeaways
- 01Writes go to the primary; replicas copy every change and serve reads.
- 02Replicas scale reads, not writes.
- 03Asynchronous replication means lag: design read-your-writes for flows where users expect to see their change.
- 04Replicas also provide failover and keep heavy reports away from production traffic.
Check your understanding
1 of 3
Where do writes go in a primary-replica setup?
Related concepts
Read-heavy vs write-heavy
A read-heavy part is read far more than it changes (a video page); a write-heavy part receives a constant flood of new data (view counts, analytics). Each one needs different tools.
7 min read →Caching
A cache stores copies of data that are expensive to get (slow query, far away server) so the next request can be answered from somewhere fast and close.
9 min read →Sharding
Sharding splits one big database into several independent databases (shards), each holding a slice of the rows, so storage and writes scale with the number of machines.
8 min read →CAP theorem
When a network partition splits your replicas, a system can stay Consistent (refuse what it can't answer correctly) or Available (answer anyway, maybe with old data). It can't do both until the network heals.
7 min read →