Where should fast-changing counts go: views, likes, scores, rate limits?
Applications like this: game leaderboards, like counts, view counters, API rate limits. This page is written the way I write a database design doc: the workload first, then where each kind of data goes and why, then how it grows, what breaks, and what I rejected.
| Dimension | This application |
|---|---|
| Writes | Very high, on a few hot keys. |
| Reads | Top N, my rank, the current count. |
| Read to write | Balanced or write-heavy. |
| Consistency | Approximate is usually fine. A like count can be a second behind. |
| Latency | Sub-millisecond per operation. |
| Growth | Small. One entry per player or per object. |
These incidents are why the choices below matter. Each one is written up with its numbers and sources.
Solid arrows: the application writes there. Dashed arrows: a copy fed from the source of truth (change data capture, an outbox, or a cache fill), which can be rebuilt from it.
| Data | Where it goes | Why |
|---|---|---|
| Leaderboards | Redis sorted sets | Rank queries are built in, and each update is O(log n) in memory. |
| Counters and rate limits | Redis INCR with EXPIRE | Atomic increments with no lock, and expiry built in. |
| Totals you must keep | The database, updated in batches | One write per minute per object instead of one per event. |
How each family of store behaves under traffic: Database families.
# leaderboard ZINCRBY lb:season7 50 player:42 ZREVRANGE lb:season7 0 9 WITHSCORES # top 10 ZREVRANK lb:season7 player:42 # my rank # fixed-window rate limit: 100 requests per minute per key MULTI INCR rl:api:key123:202611181305 EXPIRE rl:api:key123:202611181305 60 NX EXEC # allow the request only if the count returned is 100 or less
Pick a stage, then throw something at it. The numbers are a model to show the shape of each change, not a measurement; the measured numbers are in the lab notebooks.
| What happens | What you see | What I do |
|---|---|---|
| UPDATE counters SET n = n + 1 on one hot row | Lock waits, lock pile-up | Move the counter to Redis, or spread it across several rows and sum them. |
| KEYS * in production | Redis stalls for everyone | Use SCAN. |
| Counters with no TTL | Memory grows forever | Expire window keys. |
Cost. Small. A modest Redis node handles very high operation rates. The cost risk is memory from keys that never expire.
| Stage | Where it runs |
|---|---|
| Where I would start | Managed Redis or Valkey |
| When it grows | The same. MemoryDB-style durable options if the totals must survive a failover |
For a team without a dedicated database team. Who does which job in each option, and the full-cost comparison: Where to run the database.
The back-of-the-envelope numbers I would want before choosing anything. Move the assumptions to match your application. The link keeps your numbers, so a colleague sees the same ones.
Which database does my application need? What kind of application data goes in which database, and why, as design docs, plus the anti-patterns and the decisions behind them.