Database / Google Spanner Database Interview questions
How does directed reads improve read latency in multi-region Spanner?
By default, some read paths in a multi-region instance can end up routed toward the leader region even when a closer replica could have served them, because the client isn't explicitly telling Spanner where it prefers to read from. Directed reads let the client specify a preferred replica type (read-write or read-only) and a preferred region or set of regions for a given request.
// Client option example (conceptual) options.directedReadOptions = { includeReplicas: { replicaSelections: [{ location: "us-east4", type: "READ_ONLY" }] } };
With that hint, Spanner routes the read to a nearby read-only replica instead of the leader whenever the request's consistency requirements (like bounded staleness) allow it, cutting the network hop that would otherwise cross to a distant leader region. This is most valuable for read-heavy services with a geographically distributed user base, where consistently steering reads to the nearest healthy replica meaningfully reduces tail latency without changing the transaction's correctness guarantees.
More Related questions...