The interview problem

Practice prompt

A reporting API may return data at most five seconds old. Design replica routing that enforces this promise during replication lag and primary failover.

Original practice, not a reported company interview. All worked numbers are illustrative. Interview date: not applicable. Written October 3, 2026.

1. Scope and assumptions

Define staleness against a proven applied commit frontier, not the last time a replica answered a health check. Assume the database provides a trustworthy frontier or a primary heartbeat whose ordered application can be observed.

2. Architecture and decisions

Read deadline → freshness requirement → replica frontier check → eligible read or wait → primary fallback

Track per-replica applied positions in the current replication epoch. Map a primary-issued ordered heartbeat to a conservative time bound, accounting for clock uncertainty. Require the serving replica to prove it has applied the needed frontier. A wall-clock timestamp supplied by an unsynchronized replica is insufficient.

Bound waiting by the request deadline. If no replica meets the promise, route to an authoritative source or return a freshness-unavailable error; do not silently relax the contract. After failover, invalidate old epoch assumptions and rebuild frontier knowledge. If read-your-writes is also required, include the client’s commit token as an additional condition.

3. Work through the example

At an illustrative reference time of 100 seconds, a five-second bound requires a frontier of at least 95. A replica proven through 97 qualifies; one through 93 does not. If the proof has one second of uncertainty, use its conservative lower bound: a reported 95.5 becomes 94.5 and fails.

4. Failure cases and trade-offs

A database with no recent writes may have an old last-transaction timestamp despite being caught up; ordered heartbeats distinguish inactivity from lag. Routing every lagged read to the primary can overload it. Bounded staleness trades freshness for scale only when fallback and overload behavior are explicit.

5. Validation and acceptance

Pause replication, create clock offsets and fail over during reads. Verify returned versions against a controlled write history. Monitor freshness rejections and fallback load as well as latency. Test idle periods to avoid false lag alarms.

6. Follow-ups and self-review

What changes for cross-region clocks? Reward a proven frontier, uncertainty margins, epoch invalidation and explicit unavailability when the bound cannot be met.

Sources and related practice

PostgreSQL documents asynchronous standby behavior; the freshness protocol here is a database-independent design requiring suitable frontier support.

Read the primary technical reference

Reference retrieved October 3, 2026. Retrieval date is not an interview or source publication date. The reference supports the named concept; scenario, architecture, examples and rubric are original.

Continue with Keep a user's reads from moving backward across replicas; Fail over a regional write service safely.

Continue your preparation

Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.