⚡THE SHORT ANSWER
By enforcing 'Read-Your-Own-Writes' consistency, routing queries for recently mutated records to the primary master for a brief cooldown window (or tracking database Log Sequence Numbers/GTIDs in client session tokens) while serving non-mutated reads from replicas.
Engineering Handbook & Failure Dynamics
6-Dimensional Architecture Breakdown⚙️1. Underlying Mechanism
Execution🎯2. Appropriate Use Context
Scope⚠️3. Production Failure Modes
P0 Risk📡4. Diagnostic Signals & Telemetry
Telemetry🛡️5. Prevention & Safeguards
Safeguards⚖️6. Architectural Trade-offs
Trade-offCase Study (TinyCTO In-Field Example)
TinyCTO Incident 064: A banking portal allowed users to transfer money, then redirected to the balance dashboard. Because the dashboard read from an asynchronous replica lagging by 400ms, the balance showed the old amount. Users panicked and submitted the transfer a second time. Implementing a 3-second Primary read pin post-transfer eliminated all duplicate transaction tickets.
Interactive Concept Drills
3 CardsWhat is 'Read-Your-Own-Writes' consistency?
How does GTID (Global Transaction Identifier) / LSN tracking provide causal read consistency?
What causes replication lag to spike suddenly under high write load?
Read Replica Lag & Read-Your-Writes Consistency — Technical FAQ
Should GET requests never be routed to the Primary database?
No. Critical operations (e.g., checkout authorization, password resets, or immediately following a POST mutation) should explicitly read from the Primary to prevent race conditions.
How can replication lag affect database connection pooling?
If queries wait for replicas to catch up or retry on stale data, connection holding times increase, exhausting connection pools in proxies like PgBouncer.
What is the simplest way to implement Read-Your-Own-Writes without database proxies?
Set a short-lived timestamp cookie (`last_write_at`) on any mutating HTTP response. If `now - last_write_at < 5s`, route subsequent application queries to the primary database.
🤖 AEO & Key Facts Summary
Key Architectural Facts
- ▸
Asynchronous replication offers high write performance because the Primary does not wait for replicas to acknowledge before committing to the client.
- ▸
Synchronous replication guarantees zero lag but degrades write latency to the slowest replica in the cluster.
Common Misconceptions
- ✗
Assuming read replicas automatically solve all database scaling bottlenecks; if write throughput saturates the single Primary, replicas cannot help.
Decision & Governance Guidance
Route 90% of non-critical read traffic to read replicas, but enforce session-pinned primary routing for the 5-second window immediately following any user data update.
Authoritative Sources & Standards
- [BOOK]Designing Data-Intensive Applications: Chapter 5 (Replication)— O'Reilly Media (2017)
- [OFFICIAL-DOC]Eventually Consistent - Revisited— All Things Distributed (2008)
