INFINITE UPSIDE

Business and technology

What Does a Database Read Replica Actually Do?

A second database can answer a question before it has received the latest answer.

A customer changes an address and immediately opens the order page. The old address appears. The update may have succeeded. The page may simply have asked a second copy of the database a question before the new change arrived there.

A read replica is a database copy that can serve eligible read requests while changes are replicated from a primary database. The exact behavior depends on the product and configuration. A replica can help distribute reads or support a recovery design, but it is not automatically current, writable, independently recoverable or ready to take over without an operational plan.

PostgreSQL’s hot-standby documentation describes read-only queries on a standby and explains that data takes time to arrive from the primary. Other database services use different terminology, consistency options and failover procedures; verify the system actually in use.

Draw the path before adding a copy

A simplified system has an application sending changes to a primary database. Replication sends changes to a standby. The application or a routing layer may send some read requests to that standby. The replica then answers from the state it has received and applied, not from the customer’s intention or the primary’s future state.

That distinction matters when a business says it wants “a second database.” Is the goal to reduce read load, keep a copy in another location, shorten recovery time, run reports, or all four? Each goal creates different requirements for freshness, capacity, failure handling and cost. A replica optimized for reporting may be a poor emergency replacement if it cannot support the full write workload.

Identify which application sends each query and how the destination is chosen. A diagram that labels a box “replica” but omits the routing decision cannot explain why a particular customer saw old information.

Replication lag is a customer experience issue

Suppose a fictional primary accepts an address update at 10:00:00. A replica applies the change at 10:00:03. If the order page reads that replica at 10:00:01, it may display the older address. The two-second difference between the read and application of the change is an illustration of timing, not a measured delay in any real service.

The important question is not whether three seconds sounds small. It is whether the user can make a consequential decision in those seconds. Seeing an old profile color may be annoying. Seeing an old delivery address, available balance or booking state can lead to a very different action. Identify which screens and decisions require the user to see their own recent write.

One design might route a customer’s immediate follow-up read to the primary. Another might wait for an appropriate consistency condition or show that a change is still propagating. These are design options, not universal fixes. They require the actual database’s capabilities and application behavior to be tested.

Different lag measurements answer different questions

Changes may be generated, sent, received and applied at different times. A metric showing that data has reached a standby does not necessarily show that every query can see it. PostgreSQL’s standby and replication guide discusses streaming, synchronous replication and the distinct stages of receiving and replaying log records.

Agree on the point being measured. Is the dashboard reporting transport delay, replay delay, the age of the last completed transaction or a provider-specific estimate? Is it a maximum, average or current sample? A healthy-looking average can coexist with an occasional long delay during a burst or network interruption.

For a fictional service, suppose 990 reads in a test see the change within one second, nine within five seconds and one after 20 seconds. The average of those simplified times, if each group took exactly the stated time, is (990 × 1 + 9 × 5 + 1 × 20) ÷ 1,000 = 1.055 seconds. That average does not tell the team which customer experienced the 20-second delay or whether that case could cause a harmful action.

Asynchronous and synchronous are not magic labels

With asynchronous replication, a primary may acknowledge a transaction before a standby has received or applied all relevant changes. If the primary fails at the wrong moment, some acknowledged changes may not be present on the promoted copy. The exposure depends on the actual configuration and timing.

Synchronous replication can change when a primary waits for a standby, but the details matter: which standby, how many, and whether acknowledgment means receipt, durable write or replay. PostgreSQL documents configurable synchronous behavior. Do not infer that a setting with “sync” in its name makes all application reads immediately consistent or removes every failure mode.

Waiting for another server can affect latency and availability when that server or the network is slow. The tradeoff is a business decision as well as a technical one. Write down the acceptable data-loss exposure and response time for the specific operation, then evaluate the configuration against those objectives.

A replica is not a backup

A replica commonly receives changes from the primary. That can include an accidental deletion or an application error. If the change is replicated promptly, having two copies of the same mistaken state does not restore the earlier state. A separate backup and recovery process provides a different capability: restoring a known point from retained data, subject to its design and actual tests.

For example, suppose a fictional reporting table is deleted at noon and that deletion reaches a standby seconds later. A backup from the preceding night may preserve an earlier state, but it may also omit changes made that morning. The actual recovery depends on backup retention, logs, permissions, restore tools and the chosen recovery point. A backup job reporting success is not proof that a restore will work within the required time.

Test restoration in an appropriate isolated environment. Record the starting backup, any logs needed, time to restore, verification performed and what data would be missing. Treat the test as evidence for that configuration and date, not a guarantee about every later incident.

Failover needs more than a promotion button

A standby may be promoted to accept writes under the database’s supported procedure. Before an incident, define how the old primary is fenced or otherwise prevented from accepting conflicting writes, how applications discover the new primary, and how the former primary is recovered. A second server that is still receiving data is not proof that those steps have been rehearsed.

Also check the supporting pieces: credentials, network routes, connection pools, background jobs, monitoring and dependent services. A successful database promotion can still leave an application pointing to the old address or a scheduled task writing to the wrong place. Define who can authorize and perform each step, and record an incident route when the usual operator is unavailable.

Do not run a failover test on a live system merely because a checklist says to test it. Use the organization’s approved change process, protect customer data, and establish a rollback and communication plan. The safest test is one whose expected effects and success criteria are understood before it starts.

Reporting and analytics have their own load

A replica can move reporting reads away from a primary, but it still needs CPU, memory, storage and network capacity. Long-running queries can compete with replication work or create conflicts, depending on the system. PostgreSQL documents hot-standby query conflicts and configuration tradeoffs. A report that runs successfully on one quiet afternoon does not establish capacity at the busiest hour.

Define whether a report can tolerate stale data and display the data-as-of time where it helps the reader. If a manager compares a replica-based report with a real-time order screen, the numbers may differ without either being corrupted. A clear timestamp and consistent cutoff can prevent a false reconciliation chase.

Calculate the complete cost of the copy: compute, storage, data transfer, backups, support and any additional monitoring. A lower primary CPU graph can be useful, but it does not by itself show that the application is faster or that the business saved money.

A practical review with the service owner

  • Which problem is the replica meant to solve: read load, reporting, recovery or a combination?
  • Which requests go to the primary and which may use stale data?
  • What do lag metrics actually measure, and what triggers an alert?
  • What happens to acknowledged writes if the primary fails?
  • How are failover, application routing and prevention of conflicting writes tested?
  • Which independent backups and logs can restore an earlier point?
  • What does the complete configuration cost and how is success measured?

The useful promise is not “we have two databases.” It is a documented answer to what each copy does, how current it is, and how the service recovers when the ordinary path fails.

Explore Infinite Upside

For Vijay Sheth’s personal accounts, read Infinite Upside: Building Wealth With Room to Live, published by Sheth Capital, Inc.

Find your edition · Chapter companion

ABOUT THE CONTRIBUTOR

Luna Lim

DIRECTOR OF FINANCIAL RESEARCH & EDITORIAL STRATEGY

SHETH CAPITAL, INC.

Luna Lim writes about business, investing, and the judgment behind financial decisions. She joined PCH Exotics Inc. as Director of Operations in 2022, working across La Jolla and Miami. Today, she reports directly to Vijay Sheth at Sheth Capital, Inc., bringing an operator’s perspective to the ideas she covers.

Based in Pacific Beach, California, Luna is curious about the people behind the numbers: what they’re building, how they weigh uncertainty, and what makes a risk worth taking. Her articles for Infinite Upside follow those questions through the details, with clear explanations and a feel for how decisions play out in everyday business.

More from Luna Lim

The Infinite Upside store