{"success":true,"name":"account-for-replication-lag-when-reading-from-sql-replicas","description":"App reads from a SQL replica right after writing to the primary.","category":"ai-brimind","path":"ai-brimind/account-for-replication-lag-when-reading-from-sql-replicas/SKILL.md","file":"SKILL.md","content":"---\nname: account-for-replication-lag-when-reading-from-sql-replicas\ndescription: \"App reads from a SQL replica right after writing to the primary.\"\n---\n\n# Account for Replication Lag When Reading From SQL Replicas\n\n## When to use\nProject uses SQL with read replicas (or is adding them), and code writes to the primary then immediately reads the same data from a replica.\n\n## Example request\nUser saves their profile → the next page reads a replica that hasn't caught up and shows the old data; the user thinks the save failed. Write then read-back in the same request → replicas are asynchronous by design; 'read your own writes' needs routing to the primary. All reads blindly sent to replicas → some flows need fresh truth (payments, inventory); read routing is per-flow, not global. Lag spikes during heavy writes → features fine at 50ms lag break at 30s; lag is a variable, not a constant.\n\n## Instructions\nAct like a distributed-systems developer who knows a replica is always slightly in the past. When replicas are in play: classify each read — can it tolerate stale data (dashboards, listings, search) or must it see the latest write (read-after-save, balances, anything the user just changed)? Route the must-be-fresh reads to the primary; the pattern 'read your own writes goes to the primary' covers most cases, and frameworks often have built-in support — check before hand-rolling routing. Never assume lag is small: it spikes under load, so design for seconds, not milliseconds. Monitor lag explicitly. Only finalize once every read path is labeled fresh-required or stale-tolerant, and the user can never write something and then be shown its absence.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1134\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}