Read replica
Also called replica database, read-only replica.
A read-only copy of a database that is kept in sync with the main database and takes read queries off it.
Last updated
What it is.
All writes go to the primary database. Changes are copied to one or more replicas, which answer read queries such as reports, search pages and dashboards. Replicas can sit in other regions to serve distant users faster.
Copying takes time, called replication lag. It is often a fraction of a second, but under load it can grow, so a replica may briefly show slightly old data.
Why it matters
Most apps read far more than they write. Replicas let you add read capacity without a bigger primary, keep heavy reports from slowing down users and give a warm copy that can help in recovery.
In a product build
We route only reads that can tolerate slight delay to replicas, keep read-after-write flows (like showing a user what they just saved) on the primary, monitor lag and alert on it, and use connection pooling for each database.
Common mistakes.
- 01
Sending a user's read right after their own write to a replica, so their change seems lost.
- 02
Treating a replica as a backup. A bad delete replicates too.
- 03
Not watching lag, so reports quietly show stale numbers.
Related terms.
- ShardingSplitting one large dataset across several databases, called shards, by a key such as customer ID, so each shard holds only part of the data.
- Connection poolingKeeping a set of open database connections and sharing them across requests, instead of opening a new connection for each one.
- Data warehouseA database built for analysis and reporting, where cleaned data from many systems is kept together in one place.
- Load balancerA service that spreads incoming traffic across several servers, and stops sending traffic to any that fail their health checks.
- AutoscalingAutomatically adding or removing computing capacity, such as servers or containers, as the load on a system goes up or down.