The Real Fullstack

The Replica That Lied

The update returned 200 OK. Why does the next page show the old value?

Ingénieur senior8 minSimulateur de fluxDéfi de code
postgresqlspring-bootaws-rdshttp

Ce défi n'est pas encore traduit en Français. Vous lisez la version anglaise.

Mission:Show users their own writes immediately, even when the replica lags, without sending most reads back to the primary.Contexte · Objectifs d'apprentissage ▾

Tallow Cloud moved read-only queries to a PostgreSQL read replica to offload the primary. Since then, users sometimes see their old profile right after saving it — and submit the change again. Replication lag is usually tens of milliseconds but spikes during backups.

Mission: Show users their own writes immediately, even when the replica lags, without sending most reads back to the primary.

Objectifs d'apprentissage

  • Explain asynchronous replication lag.
  • Implement read-your-writes consistency.
  • Weigh primary load against freshness and latency.
SimulationSimulé
BrowserProfile APIPrimaryRead replica
Lancer la simulation

Lancez la simulation pour voir la sortie.

Simplification

One write followed by one read 150 ms later; 8% of reads come from users who wrote in the last few seconds. Modèle pédagogique — les chiffres illustrent un comportement, ce ne sont pas des benchmarks.

Concepts

Défis liés

Références