What are read replicas and when would you use them?
A read replica is a database instance that maintains a continuously updated copy of a primary (writer) instance and serves read-only queries. The primary streams its write-ahead log (WAL) or binlog to replicas, which apply the changes asynchronously — or synchronously in the case of synchronous replication.
The primary use case is **read scaling**. Most web applications are read-heavy (80–95% reads). A single primary can become a bottleneck. Adding read replicas distributes SELECT load horizontally. Replicas can also run expensive analytics or reporting queries without affecting primary performance.
**Replication lag** is the central trade-off. Asynchronous replicas apply changes after the primary commits — typically milliseconds behind, but potentially seconds during high write load or network issues. This means a client that reads from a replica immediately after a write may see stale data. Common mitigation: route the user's own read-after-write to the primary (read-your-writes consistency), or use a short delay before reading from a replica.
**When to use read replicas:** - Analytics or reporting queries that would saturate the primary - High read/write ratio with reads exceeding primary capacity - Geographic distribution — place replicas closer to users in different regions - Offloading backups — take snapshots from a replica to avoid locking the primary
**When not to use read replicas:** - Write-heavy workloads — replicas don't help; consider sharding instead - Strict read-after-write consistency requirements — either route all reads to primary or use synchronous replication (which adds write latency) - As a replacement for proper indexing — a poorly indexed query is slow on a replica too
Most cloud databases (AWS RDS, Google Cloud SQL, PlanetScale) support read replicas with simple configuration. Connection poolers like PgBouncer or application-level routing (separate read/write connection strings) handle traffic distribution. Multi-region replication (e.g., Aurora Global Database) uses the same model with higher lag due to cross-region network latency.
Promotion: if the primary fails, a replica can be promoted to primary. Failover time depends on replication mode — synchronous replicas have zero data loss; async replicas may lose the last few seconds of commits.
Explains WAL/binlog-based replication, names replication lag as the key trade-off, and gives two concrete use cases for adding replicas.
Covers replication lag mitigation (read-your-writes routing), distinguishes sync vs. async replication, addresses write-heavy anti-pattern, and discusses promotion/failover behavior.
Reading the answer is step one. Explaining it unprompted — under interview pressure — is what actually matters. Get AI-graded feedback on your answer with follow-up probes on your weak points.
Get Graded — Free Assessment