Entity Framework Core Interview Question #196
How can read and write database workloads be separated?
Testing, Production Practices & Senior Real-World Scenarios Senior Advanced
Quick Interview Answer
High-scale systems may route writes to a primary database and selected read-only queries to replicas. This usually requires separate connection configuration or contexts and an understanding of replication lag. A read replica may not immediately contain a just-committed write, so workflows requiring read-your-own-write consistency should use the appropriate data source.
Detailed Explanation
High-scale systems may route writes to a primary database and selected read-only queries to replicas. This usually requires separate connection configuration or contexts and an understanding of replication lag. A read replica may not immediately contain a just-committed write, so workflows requiring read-your-own-write consistency should use the appropriate data source.
Code Example
// Example architecture:
// WriteDbContext -> primary database
// ReadDbContext -> read replica
// Route only consistency-tolerant reads to replicas.