Share this chat
Anyone with the link can view this conversation.
For the Milka game I'll have 2,500 to 3,000 players hitting a live leaderboard at the same time, mostly in the lunch and coffee-break spikes. I don't want every page load to fire a DB query that ranks all the form responses. How do I keep the leaderboard live without hammering the database?
Quick question before I over-build this: is a cached leaderboard a dealbreaker for you? A few seconds of staleness, in exchange for the database barely being touched?
Cache is fine in principle, but I want it to feel dynamic: when a player answers, they should see their own position move, not wait for a refresh.
Then do both: a cached ranking for everyone, and an optimistic nudge for the player who just answered.
- Refresh the cache on a timer, not on requests. Recompute the full leaderboard every 30 seconds in the background and serve that. No page load ever recomputes, so nobody hits a cache miss, and the database sees one query every 30 seconds instead of thousands.
- Simulate the move locally on answer. The moment a player submits, update their cached score and slide them to their projected position right away, so it feels instant.
- Let the truth settle. On the next 30-second refresh, their real rank lands, reconciled against everyone else's latest answers.
Each player gets an instant, believable reaction, while the actual ranking stays cheap and consistent for all 3,000.
Amazing, that's exactly the feel I wanted.
Claude is an AI and can make does make mistakes. Please triple-check responses.