Read Replicas and Connection Routing
Route read-only traffic to replicas with PgBouncer or a smart driver, and accept the staleness trade-off.
Why Read Replicas?
Read-heavy workloads can offload SELECTs to replicas:
- Primary handles writes
- Replicas handle most reads
- Horizontal read scaling without sharding
Eventual Consistency Caveat
Replicas lag the primary. A user that just placed an order may not see it on the replica yet. Either:
- Route reads-after-writes to the primary
- Wait for replica catch-up
- Cache the post-write state in the app
All lessons in this course
- Streaming Replication and WAL
- Logical Replication for Sharding
- Failover and Leader Election (Patroni, Stolon)
- Read Replicas and Connection Routing