Let’s talk
Back to the lesson: The stale redirect

Level 6 of 6 / you are the scheduler

The stale redirect

sho.rt/g8 points to old-site.com and its cached copy in Redis has just expired. A visitor opens the link at the same moment the owner changes it to new-site.com. Redirects read the cache and fill it from Postgres on a miss; edits update Postgres, then delete the cached copy.

Your goal: make one of these false

  • The cache never disagrees with the databasenot checked yet
Visitorapi-1
  1. const hit = await redis.get("link:g8");
  2. if (hit) return "SERVED_FROM_CACHE";
  3. const target = await db.query("SELECT target …");
  4. await redis.set("link:g8", target, "EX", 86400);
  5. return "REDIRECTED";
no local variables yet
Ownerapi-2
  1. await db.query("UPDATE links SET target = $2 …");
  2. await redis.del("link:g8");
  3. return "SAVED";
no local variables yet

Database

postgres.target
"old-site.com"
redis.link:g8
null

What happened

  1. Step a request to begin.
0 steps · 0 switches · par 2
Next in the trackThe vanity alias race