Serving 56,000 game pages without a database meltdown: the boring caching choices that work

Serving 56,000 game pages without a database meltdown: the boring caching choices that work

Running a browser games portal with more than 56,000 game pages teaches you one lesson fast: the interesting engineering is not the game itself, it is everything around it. A game page is small. Fifty-six thousand of them, requested in unpredictable spikes whenever a game gets shared, is a different problem. The choices that kept our site stable are boring, and that is exactly why they work. First, treat game pages as static content. A game listing does not change every minute. Its title, description and category are stable, and the game file itself changes rarely. So we serve pages that are built ahead of time rather than assembled from a database on every request. The database still exists, but it is not in the hot path for a normal page view. When a page does not need fresh data, do not ask the database for it. That single decision removes the most common failure mode for a content-heavy site: a traffic spike turning into a database queue. Second, load the game only when the visitor asks for it. A game file can be far larger than the page around it, and loading it eagerly for every visitor wastes bandwidth and slows the first paint. Our pages load the light shell first: title, description, thumbnail and controls. The game itself starts when the visitor presses play. Visitors who are just browsing never pay the cost of a game they never play, and visitors who do play get a page that already feels fast. Third, cache aggressively and invalidate deliberately. Static pages, thumbnails and game files all carry long cache lifetimes, served through a CDN so repeat visits and nearby visitors do not all hit the origin. The trade-off is staleness: when a game file or description changes, the old version can linger. We handle that by versioning changed assets rather than clearing the whole cache. A new game file gets a new path, so old pages keep working and new pages pick up the new file immediately. Blanket cache purges are a last resort, not a routine. Fourth, keep the page itself light. This is the least glamorous work and the most valuable. Every script, tracker and widget on a game page competes with the game for the visitor's device, and many of our visitors play on modest hardware or phones. We keep our own page code small, defer anything that is not needed for the first view, and test pages on a low-end device, not just a fast developer machine. A page that feels instant on a flagship phone and sluggish on a three-year-old phone is not a fast page. Fifth, skip accounts where accounts add nothing. Our games need no sign-up and no download, and that is a product choice as much as a technical one. No login system means no session database, no password resets and no account-related failure modes on the critical path. Visitors play immediately, and the site has fewer moving parts to break. Accounts make sense for saved progress and social features, but they are not free, and a portal that does not need them should not pay for them. What still breaks? Cache invalidation, as always. A changed game that keeps serving the old file is the bug we watch for most, and it is usually a versioning mistake, not a traffic problem. The other recurring issue is a single popular game swamping one cache node, which is a reminder that even a good cache needs monitoring. We watch for sudden spikes per game, not just total traffic, because one viral game behaves very differently from steady growth across the catalogue. None of this is novel, and that is the point. Static pages, lazy loading, long caches with versioned assets, light pages and fewer moving parts will carry a large catalogue further than any clever real-time architecture. If you run a content-heavy site, start with the boring choices. They are boring because they have already survived everyone else's traffic spikes, including ours. You can see the result at GameZiko, a free browser games portal with 56,000+ HTML5 games, no downloads and no sign-ups.

Original Source

Read the full article at Dev →

KhanList aggregates and links to publicly available news content. We do not host full articles from third-party sources. Always verify important information with original sources.