{"canonical_url":"https://engineer.company/glossary/read-replica/","content_markdown":"# Read replica\n\n## What it is\n\nA read replica is a copy of a database that can serve read queries while another\ninstance receives writes. The replication mechanism delivers changes and the\nreplica applies them. A PostgreSQL hot standby, for example, can accept\nread-only connections while it replays write-ahead log records. The copy has its\nown resources and connections. A request reaching it observes the state that has\nbeen applied under the database's consistency rules.\n\nConsider an online shop that writes orders to its primary instance and sends\nhistorical reports to a replica. A report can use memory and CPU on the replica\nwhile checkout uses the primary. A customer who immediately opens a freshly\ncreated order may need to read from the primary, because the record can take\ntime to appear on the replica. A route that tolerates a short delay can normally\nuse the replica if the measured lag stays within its budget.\n\nThe topology can serve more than one purpose. A readable replica can provide\nquery capacity, and in certain configurations it can also be promoted after a\nfailure. Promotion changes which instance can accept writes and requires a route\nswitch or client reconnect. It calls for testing recovery objectives, fencing\nand the effect of incomplete replication. A service needing read capacity can\nchoose a different topology from one needing automatic failover. Decide which\npromise the replica is expected to support and whether the service can tolerate\nthe resulting trade-offs.\n\n## Why it matters\n\nReporting, exports and searches often compete with writes for database\nresources. A separate instance can absorb work that already reads a coherent\nsnapshot and can accept a predictable freshness delay. Moving a query can free\nprimary capacity, but the report itself can still need indexes, bounded work and\nenough memory. Compare the cost of adjusting the query with the cost of running\nanother instance and operating a replication topology.\n\nConsumers need a freshness policy before traffic moves. A dashboard that shows\nthe previous day's order totals can tolerate some delay. An order receipt and a\nsupport screen opened immediately after an update may need a read that reflects\nthe preceding write. Route based on the business requirement. Some services pin\na session to the primary for a short period. Others use a replication position\nand wait for a suitably advanced replica when their storage system exposes a\nusable mechanism. Include a time budget and a clear response when the condition\nis not met.\n\nReplication also creates operational signals. Track positions or timestamps at\nthe producer, receiver and replay process as appropriate for the engine. A\nconnection can be healthy while an intensive workload prevents the replica from\napplying changes promptly. Check disk usage, replay conflicts and query\ncancellations as well as a single lag number. An idle database can make\ntimestamp-only measures misleading, so consider a verified heartbeat when a\nservice needs continuous evidence of freshness.\n\n## What it looks like in practice\n\nIn a staging environment, place an example order through the primary and request\nthe order from the replica immediately. Record the first successful request on\neach route. Repeat while the replica is busy with a large report and while it is\ntemporarily disconnected. Test the important user outcome. A confirmation page\nmight always request the primary, while a chart might show its last refreshed\ntime and retry later. Check what each path displays when the preferred database\nis unavailable.\n\nPlan admission and recovery together. Limit the number of long reports that can\nrun at once and test what happens when a query competes with replay. PostgreSQL\ncan cancel conflicting standby queries or defer replay within a configured\nbudget. Run representative report sizes, measure their elapsed time and see how\nthe strategy affects freshness under sustained writes. A fallback that sends\nevery delayed read to the primary can bring back the overload that motivated the\nreplica, so include the primary's available capacity in the test.\n\nOur\n[case study on operating PostgreSQL and SQL Server systems](/portfolio/ran-10-postgresql-and-ms-sql-servers-on-ubuntu/)\ndescribes database performance monitoring and documented recovery procedures.\nThose are practices a team can apply when it adds a read replica. The shop\nexample describes tests for read routing and replication lag. A separate\npromotion exercise is relevant when the replica is also intended for recovery.\n\n## Where it goes wrong\n\nA generic read pool can mix requests with very different consistency needs. Map\nthe routes before enabling automatic read balancing. Include requests issued\nimmediately after writes, administrative views that expect new permissions and\njobs that depend on a certain data revision. Measure from the application\nboundary as well as the database metrics. A small average lag can conceal cases\nthat affect a user at the worst moment.\n\nA replica can fall too far behind to catch up from retained records. Follow how\nthe engine manages log history, slots and resets, and define the required disk\ncapacity. A slot that retains logs during an absence can put the primary under\npressure. In some systems an interrupted replica must restart from a new copy if\nthe needed history has been discarded. Drill the rebuild, including when to take\nthe replica out of load balancing and how to confirm it is ready again.\n\nA replica follows legitimate writes, including mistaken changes. Keep separate\nversioned backups and verify restores independently. When the design includes\nfailover, measure which committed changes survive, how the old primary stops\naccepting writes and where clients reconnect. A read replica can supply part of\nthat design. Its successful response to a read query leaves these\nfailure-handling questions open.\n\n## Further reading\n\n- [PostgreSQL hot standby](https://www.postgresql.org/docs/18/hot-standby.html)\n  describes read-only connections, replay conflicts and cancellations.\n- [PostgreSQL standby servers](https://www.postgresql.org/docs/18/warm-standby.html)\n  covers streaming, recovery and replication options.\n- [Amazon RDS PostgreSQL read replicas](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PostgreSQL.Replication.ReadReplicas.html)\n  documents how read copies work in this managed service.\n\n\u003chttps://engineer.company/glossary/read-replica/\u003e\n","date_modified":"2026-11-24T21:48:58Z","description":"How a read replica shares query load, when data becomes visible, and how to test lag and read routing.","formats":{"gemtext":"https://engineer.company/glossary/read-replica/index.gmi","gopher":"https://engineer.company/glossary/read-replica/gophermap","html":"https://engineer.company/glossary/read-replica/","json":"https://engineer.company/glossary/read-replica/index.json","markdown":"https://engineer.company/glossary/read-replica/index.md","pdf":"https://engineer.company/glossary/read-replica/index.pdf"},"kind":"page","language":"en","title":"What is a read replica?","url":"https://engineer.company/glossary/read-replica/","version":1}