High Rate limiting Question 148 of 226

How would you design rate limiting for a public API using a token bucket in Redis?

Java Specialist · Speak this in 60–90 seconds · Faridabad & Delhi NCR

PICTURE THIS: A SENTENCE BECOMES TOKENS

The model does not read letters like humans. It reads these pieces, then predicts the next one.

Simple meaning

Each client key has a bucket of tokens that refill at a constant rate

1

WHY — Rate limiting instead of guessing?

Why interviewers care about Rate limiting:

This is a process

question about Rate limiting.

Panels listen for order,

trade-offs, and what you would actually do on a Backend project - not buzzwords.

Stay structured

Name the idea, why it exists, then one short example.

Close cleanly

End with when you use it and one common pitfall.

2

STEPS — What happens with tokens?

Before the model can read a sentence, it goes through these steps:

  1. 1
    Each client key has

    a bucket of tokens that refill at a constant rate

  2. 2
    a request consumes a

    token or gets 429.

  3. 3
    Redis holds the counter

    with a Lua script or INCR plus TTL so many app nodes share the limit.

  4. 4
    Context mix

    Token bucket allows short bursts

  5. 5
    a fixed window is

    simpler but clumpier at window edges.

  6. 6
    Decode

    IDs turn back into readable text.

3

EXAMPLE — See it in action

Let's see how a real sentence is tokenized (tokens may vary by model):

Input text
“Redis holds the counter with a Lua script or INCR plus TTL so many app nodes sha”
Tokenized output
Redisholdsthecounterwitha
Token IDs (example)
2987408337471632900

Note: Actual tokens and IDs depend on the tokenizer (e.g., GPT, Llama, etc.).

Key takeaway

Each client key has a bucket of tokens that refill at a constant rate a request consumes a token or gets 429.

Chat with us