The Retry That Forgets
This client library pins each user to one replica so that a user always reads their own writes. Reads started failing during a replica restart, so a retry was added.
const replicas = [r0, r1, r2, r3];
function pinned(userId) {
return replicas[hash(userId) % replicas.length];
}
async function readProfile(userId) {
try {
return await pinned(userId).get(`profile:${userId}`);
} catch (err) {
const alt = replicas[Math.floor(Math.random() * replicas.length)];
return await alt.get(`profile:${userId}`); // retry
}
}
Writes still go to the leader and replicate asynchronously. What did the retry cost, and what restores the guarantee?
Sign in to answer questions and track your progress
Sign In