Rate limiting
0-day streakReview

Your progress

Level 1

0 XP100 XP to level 2
0day streak
0best streak
0topics started
0cards reviewed
    Review cards

    Progress is stored only in this browser. No account is required.

    Layer 3 · Go deeper · 8 min

    Go deeper

    Size it, build it, then make the calls an interviewer will push you on.

    Back of the envelope

    Size it up

    Tap through each step of the arithmetic.

    What does OTP abuse cost, and what do attempt limits buy?

      How many requests can a token bucket admit in t seconds?

        What happens when the database slows from 50 ms to 500 ms?

          How do retries multiply through five layers?

            Build-up · 5 steps

            A token bucket meets a burst

            Set to r = 5 a second with a burst of b = 5, fed the same trace: 14 requests in 0.7 s, then a steady 4 a second.

            Step 1 of 5

            A full bucket

            The bucket holds up to b = 5 tokens and refills at r = 5 a second, one every 200 ms. Store only the count and the last update time.

            4 interview moments

            You’re the candidate

            The interviewer pushes on the hard parts. Pick an approach and see how it holds up.

            1. Deep dive 1 of 4

              Interviewer

              “A public API must absorb the dozen calls an app screen fires at once, yet hold 50 a second long-run. Which algorithm?”

              Your move. Pick an approach:

            2. Deep dive 2 of 4

              Interviewer

              “Limit OTP sends to 5 per phone number per 15 minutes. Which algorithm fits?”

              Your move. Pick an approach:

            3. Deep dive 3 of 4

              Interviewer

              “The gateway runs 50 pods behind a round-robin balancer. Where do the per-key counters live?”

              Your move. Pick an approach:

            4. Deep dive 4 of 4

              Interviewer

              “The Redis behind your limiter goes down at peak. What should the limits do?”

              Your move. Pick an approach: