System Design Atlas
LOCAL GUEST MODERead and practice without an account.

Your saved topics and reading progress stay in this browser. Sign in to sync supported profile and progress data.

Replica Lag (30s)

A user reads their old profile immediately after a successful write.

◐ MediumDrill 051 min1 prerequisite
My progress
Topic tools

Layout updated

Explore the design, then rehearse the decisions without looking.

Prompt

A user reads their old profile immediately after a successful write.

A replica is a delayed photocopy. A user who just changed a fact may need the latest original rather than whichever copy responds first.

Constraints

  • Honor the freshness requested by the session.
  • Limit waits and primary fallback during replica delays.

Think first

Take five minutes to state the failure, the evidence you need and your first safe move.

5:00

Staged reveal

First move

The writer owns committed state and replicas report what they have applied.

What to check

Carry the required commit/version token and compare replica apply progress.

Recovery

Route to an eligible replica, wait within a deadline or use the primary. Return an explicit error if the requested guarantee cannot be met.

What you give up

Read-your-writes applies to the stated session. A stronger global ordering promise needs additional coordination, latency or reduced availability.

Architecture and technical reference

High-level design

Replica Lag (30s)
G client->routing 1. Submit request routing->replica 2. stale OK routing->primary 3. strong read routing->fallback 4. no healthy source client Read Client edge routing Consistency Router edge replica PostgreSQL / Lagging Replica state · durable primary PostgreSQL / Primary Database state · durable fallback Wait / Error Path compute
  • Edge
  • State
  • Compute

━━ Synchronous┄┄ Asynchronous···· Recovery / control▧ Fault

Select a component or follow a numbered connection.

Each arrow is one interaction. Request, background and recovery branches are not one linear transaction.

Read the 4 flow steps

Problem statement

A replica is 30 seconds behind immediately after the user changed their profile. Which reads can use it?

Functional requirements

  • Read data from a primary or replica.
  • Let a session request its latest saved version.
  • Wait, use the primary or report unavailable fresh data.

Non-functional requirements

  • Honor the freshness requested by the session.
  • Limit waits and primary fallback during replica delays.

Entities

Entity / logical owner
Authoritative state

API design

Operation / inputResponse and retry contract
Decision contractIdentify acceptance, retry identity, version/ and the response on uncertainty.

High-level design component walkthrough

Client / user

Read Client

Needs fresh profile

Why, tradeoff and connected operations

An application or user-facing endpoint starts or receives this flow.

Tradeoff: Stronger guarantees increase latency

Connected operations: Submit request

Gateway / routing

Consistency Router

Choose freshness policy

Why, tradeoff and connected operations

Centralize admission and routing while keeping business-state ownership downstream.

Tradeoff: Extra branching and coordination

Connected operations: Submit request; stale OK; strong read; no healthy source

Relational database

PostgreSQL / Lagging Replica

Fast, possibly 30s stale

Why, tradeoff and connected operations

: PostgreSQL. Relational tables and constraints own this state. Logical tables shown within the same business database are not separate databases; only at the defined transaction boundary. Use transactional constraints for related authoritative records; indexes follow the access pattern.

Tradeoff: Can violate read-your-writes

Connected operations: stale OK

Relational database

PostgreSQL / Primary Database

Latest acknowledged state

Why, tradeoff and connected operations

: PostgreSQL. Relational tables and constraints own this state. Logical tables shown within the same business database are not separate databases; only at the defined transaction boundary. Use transactional constraints for related authoritative records; indexes follow the access pattern.

Tradeoff: Read overload on writer

Connected operations: strong read

Backend service

Wait / Error Path

When freshness required

Why, tradeoff and connected operations

Isolate this operation so it can scale and fail independently from storage.

Tradeoff: Unavailability / long waits

Connected operations: no healthy source

Engineering control room

Deep dives — decisions, failures and recovery

Open a deep dive to follow the steps, try an example and see how recovery works.

Deep dive 1

Compare the read with the session's saved version

The writer owns committed state and replicas report what they have applied.

Read the explanation and worked example
How it works

The primary records commit order; a replica reports the last committed position it has applied. A freshness promise must compare positions from the same timeline or a compatible version token, not just assume a replica that is reachable is current.

Walk through an example

The replica is 30 seconds behind but responds in two milliseconds. Its excellent latency does not satisfy a user who requires the write they just completed to be visible.

Failure and recovery

Keep primary failover timelines and token interpretation explicit. If a token cannot be interpreted after failover, route or fail according to policy rather than claiming the replica has caught up.

Why this helps

A replica can answer quickly while still missing the user's latest change.

What you give up

Read-your-writes applies to the stated session. A stronger global ordering promise needs additional coordination, latency or reduced availability.

Deep dive 2

Wait briefly or choose a fresh-enough source

Carry the write's version token and route only to a source that covers it.

Read the explanation and worked example
How it works

Return a commit/version token after the write and carry it with the relevant session read. Route only to a replica whose applied position covers that token, wait within a deadline, or use the writer. Different endpoints may choose different freshness levels explicitly.

Walk through an example

A user saves a profile and immediately refreshes. A random read replica can show the old name unless routing honors the returned commit token.

Failure and recovery

Bound the waiting queue and writer fallback budget. If all eligible sources are unavailable, return a freshness error instead of silently weakening the guarantee the session requested.

Why this helps

A fast stale answer is still wrong when the caller explicitly requested its latest write.

What you give up

If the primary is unavailable, serve old data only under a permitted stale-read mode. Otherwise return an explicit freshness error.

Deep dive 3

What happens if a region fails?

Do not claim a fresh session read if the recovery region missed its write.

Read the explanation and worked example
How it works

A session commit token must remain interpretable after failover, including the writer's history/timeline identity. A remote replica cannot satisfy a lost commit merely by having a numerically large but unrelated local position.

Walk through an example

The user carries a token for a write that never reached the promoted region.

Failure and recovery

Reconcile the write identity if possible, or return an explicit freshness/recovery error; do not silently claim read-your-writes from a stale history.

Why this helps

Session guarantees extend beyond ordinary replica lag when authority changes.

What you give up

Cross-region synchronous commits reduce missing acknowledged writes but add network latency; asynchronous recovery requires a stated weaker promise.

Deep dive 4

Avoid overloading the primary with fresh reads

Read-your-writes must have a deadline and a capacity plan.

Read the explanation and worked example
How it works

Compare the requested commit token with replica progress before serving. Wait only within the caller's remaining deadline, and reserve a bounded primary-read budget for freshness-sensitive requests. repeated waits where possible rather than polling the same position aggressively.

Walk through an example

Thousands of clients refresh after a bulk update while replicas are delayed. Routing every request to the primary can turn a freshness problem into a writer outage.

Failure and recovery

Shed excess work with an explicit freshness error, show a permitted stale response only under a different declared mode, and monitor the oldest outstanding token.

Why this helps

A consistency guarantee includes what the service does when it cannot meet the guarantee promptly.

What you give up

More primary fallback improves success until it exhausts writer capacity; waiting preserves load isolation at the cost of latency.

Tradeoffs and alternatives

DecisionTradeoff / alternative and recovery implication
Compare the read with the session's saved versionRead-your-writes applies to the stated session. A stronger global ordering promise needs additional coordination, latency or reduced availability.
Wait briefly or choose a fresh-enough sourceIf the primary is unavailable, serve old data only under a permitted stale-read mode. Otherwise return an explicit freshness error.
What happens if a region fails?Cross-region synchronous commits reduce missing acknowledged writes but add network latency; asynchronous recovery requires a stated weaker promise.
Avoid overloading the primary with fresh readsMore primary fallback improves success until it exhausts writer capacity; waiting preserves load isolation at the cost of latency.

Production scars & failure modes

Failure investigation

A user reads their old profile immediately after a successful write.

Look for: Carry the required commit/version token and compare replica apply progress.

Recovery and invariant: Route to an eligible replica, wait within a deadline or use the primary. Return an explicit error if the requested guarantee cannot be met.

Component / failureImpactRecovery mechanismAlternative / tradeoff
Primary failure / raceA replica is 30 seconds behind immediately after the user changed their profile. Which reads can use it?Carry a session commit token and route to the writer or wait until the replica has applied it. Bound waits and return an explicit freshness error if needed.Read-your-writes is a session guarantee, not automatically global linearizability. Stronger reads cost latency or availability.
Recovery follow-upThe primary is unavailable. Explain which fields can be stale and which operation must reject.Carry a session commit token and route to the writer or wait until the replica has applied it. Bound waits and return an explicit freshness error if needed.State the guarantee you relax and how you detect recovery.

90-second interview summary

For replica lag, I would separate fast response from fresh response. The primary records commit order and each replica exposes how far it has applied that history. A reachable replica with two-millisecond latency can still violate a user's read-your-writes requirement.

After a successful write, the client carries a session commit token into the relevant read. The router chooses an eligible replica, waits within a deadline for it to catch up, or uses the primary under a bounded fallback budget. It does not silently weaken the session guarantee when no source qualifies.

Waiting and fallback both need capacity limits. A large wave of refreshes while replicas are delayed can overload the primary or fill the waiting pool, so excess requests receive an explicit freshness error unless a separately selected stale-read mode is allowed.

After regional promotion, the token must still refer to a compatible history. A numerically large position from another timeline is not proof that the original write survived. I would measure applied gaps, waiting age, primary fallback and missing-token recovery. The tradeoff is latency and availability versus explicit freshness, with the guarantee stated per request rather than assumed for every replica read.

Explain it without looking

Explain compare the read with the session's saved version

Reveal answer

The writer owns committed state and replicas report what they have applied.

A replica can answer quickly while still missing the user's latest change.

Read-your-writes applies to the stated session. A stronger global ordering promise needs additional coordination, latency or reduced availability.

Explain wait briefly or choose a fresh-enough source

Reveal answer

Carry the write's version token and route only to a source that covers it.

A fast stale answer is still wrong when the caller explicitly requested its latest write.

If the primary is unavailable, serve old data only under a permitted stale-read mode. Otherwise return an explicit freshness error.

Explain what happens if a region fails?

Reveal answer

Do not claim a fresh session read if the recovery region missed its write.

Session guarantees extend beyond ordinary replica lag when authority changes.

Cross-region synchronous commits reduce missing acknowledged writes but add network latency; asynchronous recovery requires a stated weaker promise.

Explain avoid overloading the primary with fresh reads

Reveal answer

Read-your-writes must have a deadline and a capacity plan.

A consistency guarantee includes what the service does when it cannot meet the guarantee promptly.

More primary fallback improves success until it exhausts writer capacity; waiting preserves load isolation at the cost of latency.

Revision checklist

Revision checklist

  • Reconstruct compare the read with the session's saved version: The writer owns committed state and replicas report what they have applied.
  • Reconstruct wait briefly or choose a fresh-enough source: Carry the write's version token and route only to a source that covers it.
  • Reconstruct what happens if a region fails?: Do not claim a fresh session read if the recovery region missed its write.
  • Reconstruct avoid overloading the primary with fresh reads: Read-your-writes must have a deadline and a capacity plan.
  • Name the authoritative state, boundary, retry identity and failure-domain durability guarantee.
  • Explain one alternative and exactly which guarantee you would relax.
  • Redraw the request and recovery paths without looking; mark what required a hint.

On this page
  1. Prompt
  2. Constraints
  3. Think first
  4. Staged reveal
  5. High-level design
  6. Problem statement
  7. Functional requirements
  8. Non-functional requirements
  9. Entities
  10. API design
  11. High-level design component walkthrough
  12. Engineering control room
  13. Deep dives — decisions, failures and recovery
  14. Tradeoffs and alternatives
  15. Production scars & failure modes
  16. 90-second interview summary
  17. Explain it without looking
  18. Revision checklist

Save & sync your Atlas progress

Sync your profile and topic progress across browsers, then return to the same study desk.

Google sign-in will appear here after its Azure provider is configured.

Architecture diagram