SQL & Relational Databases (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
Primary-Replica Topology and Replication Lag Mitigation.
senior Levelsql-databasesAdvanced Internals
In Simple Words:
- Primary handles all
WRITEoperations and streams changes to Read Replicas. - Replication Lag: Asynchronous replication introduces a delay ($\Delta t \approx 50\text{ms} - 5\text{s}$) where replicas lag behind the primary.
- Read-Your-Own-Writes Pattern: If a user updates their profile, route that specific user's reads to the Primary database for the next 5 seconds (or until replica LSN reaches the commit LSN), while routing anonymous traffic to read replicas.