Practical System Design

Labs / Chapter 7

The next read still returns the old address

Read a replica that has not applied the write and watch the old address come back. Then run choose_read_target. Without primary fallback the read should be unavailable. With fallback it should come from the primary. Catch a replica up and watch the router choose it again.

The system

Replica lag is 400 ms. This read ignored the policy and returned the old address.

readreplicatereplicate

Client

App

Replica candidate

Database

Primary

Not this read

Database

Replica A

400 ms behind

Database

Replica B

400 ms behind

choose_read_target

  1. # lag_ms = available = sample_is_current =
  2. target =
  3. def choose_read_target(policy, observations, request):
  4. candidates = [replica for replica in observations.replicas
  5. if replica.available
  6. and replica.sample_is_current()
  7. and policy.accepts(replica)]
  8. if candidates:
  9. return replica_admission.try_choose(candidates, deadline=request.deadline)
  10. if policy.allow_primary_fallback:
  11. return primary_fallback.try_admit(deadline=request.deadline)
  12. raise ReadTemporarilyUnavailable()
  1. Lag400 ms behind the write
  2. This readReplica. The old address comes back.

This read

Saved-address shown and primary share are both percents of this one read, not of the whole fleet.

Saved address 0 · Primary 0

The chart fills as the lab runs. % is the vertical unit.

  • Saved address
  • Primary
  • %