a partial success is the most dangerous thing to cache
Roblox tells my cache to keep nothing, so I cache their live player counts myself. The hard part was not the caching, it was one rule: a snapshot that came back missing a game is fine to show once and must never become the fallback a real outage serves.
The Roblox games endpoint answers every request with no-store. That is Roblox telling every cache between their servers and mine to keep nothing, which is fair for them and useless for me. The live player count on my projects page reads from that endpoint, and the same payload carries the visit totals that add up to the billion-plus plays across the Pogi Games catalogue. If I obeyed no-store, that badge would blank out or throw every time their API had a bad second, and their API has bad seconds.
So I cache it myself. The caching is the boring part. What matters is the two rules for what happens when a fetch fails, and the second one took a real bug to teach me.
serve the last good answer, and flag that it is old
Every successful pull gets stored as the last good snapshot, keyed by the exact set of games requested. When a later fetch fails, times out (I abort at 7 seconds), or comes back non-200, the client returns that stored snapshot with ok: false set on it:
} catch (e) {
const stale = lastGood.get(key);
const error = e instanceof Error ? e.message : "Roblox API error";
if (stale) return { ...stale, ok: false, error };
...
}The ok: false is the point. The number still renders, so nobody sees a zero or a broken card, but the flag rides along so the UI can mark it stale if it chooses to. The same move happens one level down: resolving a place id to its universe id is cached for a full day, and on failure I return the old id instead of null, because a place's universe id never changes. A stale id is a correct id.
This is already a position some engineers will argue with. Showing a sixty-second-old count with no visible warning is, strictly, showing something false. I think a count that is a minute stale is more honest than a dash where a number should be, as long as the code knows it is stale. Blank space reads as "this game is dead." A slightly old number reads as the truth, because it mostly is.
the rule that cost me a bug: only a whole answer counts
Here is the one I got wrong the first time.
A snapshot for the games list is built by resolving every game to a universe id, then batching those ids to the games API, 50 per request. Resolution can fail for a single game while every other game succeeds. When that happens the loop skips the missing one, sums what it has, and returns a valid-looking snapshot that is quietly short one game.
If I let that snapshot become the last good fallback, I have poisoned the well. The next time the API genuinely goes down, the fallback I serve is not the real total. It is the total minus whatever game happened to be flaky at write time. The counter would step down and stay down, and it would look completely fine.
The fix is one line:
if (stats.length === refs.length) lastGood.set(key, snapshot);A snapshot only earns the right to be the fallback when it is complete: every game asked for is a game returned. A partial result is fine to show once, right now, to whoever asked for it. It is never fine to remember. The same guard sits in the richer cards path as cards.length === ids.length.
That is the actual lesson, and it reaches past Roblox. A cache miss is loud; you notice a page that will not load. A partial success is silent. The failure that quietly erodes your fallback is the one that returned 200 and looked exactly like data.
not everything gets the all-or-nothing treatment
The complete-or-nothing rule is only for the numbers, the thing the page exists to show. The decoration is deliberately held to a lower bar. Game icons and 16:9 thumbnails each fetch inside their own try/catch, and on failure they resolve to null rather than take down the whole stat:
} catch {
// icons are non-critical: leave them null rather than fail the whole stat
for (const id of ids) if (!out.has(id)) out.set(id, null);
}A card with a live count and a missing icon is a fine card. A card with an icon and no count is a broken card. Knowing which fields are load-bearing, and letting the rest fail quietly, is most of what graceful degradation means in a file like this.
There is one more piece of the same discipline. Unavailable or unrated games come back from the API as a censored stub: id 0, name "[TITLE UNAVAILABLE]". That stub gets dropped before it touches any cache, because the only thing worse than not caching a game is caching a fake one.
None of this is clever. It is one file, a handful of Maps, and a rule I can say in a sentence: show the freshest thing you have, and only let a whole thing become the thing you fall back to.