Back to the lesson: The stale redirect Next in the trackThe vanity alias race
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
- const hit = await redis.get("link:g8");
- if (hit) return "SERVED_FROM_CACHE";
- const target = await db.query("SELECT target …");
- await redis.set("link:g8", target, "EX", 86400);
- return "REDIRECTED";
no local variables yet
Ownerapi-2
- await db.query("UPDATE links SET target = $2 …");
- await redis.del("link:g8");
- return "SAVED";
no local variables yet
Database
- postgres.target
- "old-site.com"
- redis.link:g8
- null
What happened
- Step a request to begin.
0 steps · 0 switches · par 2