KatInterview

Per-User Throttling for a Multiplayer Game API at Scale

System DesignModel answer
MediumModel answerSystem Designrate-limitingdistributed-systemsredis

Last updated

Design a distributed service that caps each user's request volume per rolling minute across many app servers, rejecting excess calls with HTTP 429 while staying fast and available.

Throttle Abusive Traffic on a Game Backend

You are building the throttling layer for the backend of a large online game. Peak load is in the millions of requests per second. Each request carries a user_id, and every user must stay within a quota, for example 100 requests per minute, measured over a rolling window.

What the system must do

  1. Track each user's request volume over a rolling time window and block requests that exceed the quota.
  2. Reject blocked requests with HTTP 429 Too Many Requests.

Quality attributes

  • Latency: the check must add very little time to each request.
  • Scalability: throughput must grow with traffic, with no sharp degradation.
  • Accuracy vs. availability: being slightly imprecise is acceptable. Under extreme load, prefer staying fast and available over being perfectly exact.

What to cover in your answer

  • Which limiting algorithm you choose (fixed window, sliding window, token bucket, leaky bucket, or a variant) and why.
  • Where counters live and how you handle heavy concurrent access to them.
  • How many application servers share state and stay consistent enough.
  • What happens when the limiter or its backing store fails.

State your assumptions about scale (peak requests per second, active users, number of servers) and use them for rough capacity estimates.

Hints

Hint 1

Do an estimate first: peak requests per second, active users per minute, and bytes of state per user. These numbers should decide between storing every timestamp and storing just a couple of counters.

Hint 2

A check-then-increment done as two separate calls is racy when many servers hit the same key. Think about how to make the decision and the update a single atomic step, and how to keep one user's data on one shard.

Hint 3

Not every request needs a network call to the shared store. Consider what a server can remember locally about users who are already blocked, and how far local counts can drift if they are synced periodically.

Hint 4

Decide ahead of time what the limiter does when the store is unreachable, and whether that answer should differ between a browsing endpoint and a purchase or login endpoint.