How database copies help reads and why they can lag
What are a primary and a replica?
Databases handle two kinds of work: reads return data; writes change it. Here all writes go to the main database, the primary. A replica is a separate database that receives copies of its changes and can serve reads.
A catalog, for example, is read much more than it is edited. Sending some reads to replicas leaves primary with fewer requests and more write capacity. But a replica does not attract traffic automatically: the application must route reads to it.
Why a new write is not visible immediately
Time passes between a write to the primary and that write appearing on a replica. This is replication lag. It is not request response time: a replica may quickly return a value that has not yet updated.
Imagine a user changes their name and opens their profile a second later. With a three-second lag, a replica may still show the old name. Routing that read to the primary returns the value already written. Ordinary reads that tolerate a small delay can stay on replicas.
How load is distributed
At 1,000 operations per second and 90% reads, there are 900 reads and 100 writes. If they all reach a primary limited to 300 operations per second, it overloads.
Replicas add read capacity, but the primary still handles writes. Replica read share sets routing; another setting keeps read-after-write requests on primary. This offloads the main database without sending sensitive reads to lagging copies.
Checking freshness and capacity
Add a replica and first see whether primary load changes. Then adjust the routed read share. A replica receiving 0% of reads contributes no used capacity.
Sensitive reads occur one second after writes. If a replica with lag over one second serves them, they count as stale. Compare freshness, completed work and cost. Primary failure and electing a new primary are outside this lesson.
Task
1,000 operations/s: 90% reads, 10% writes. Each database handles 300 operations/s. One tenth of reads occur one second after a write and need fresh data.
Steady-state model over 60s: writes go only to the primary and have priority. Ordinary reads are split by the selected percentage; reads after writes can be pinned to the primary. Each replica serves an equal share of routed reads, up to 300/s. Without replicas, all operations go to the primary.
- Split the initial traffic into reads and writes and locate the primary’s overload.
- Add replicas from the panel and route some reads to them.
- Compare load distribution and read-after-write freshness; check the budget.