Interview: rate limit is 2/min, 30 requests get through
Fixed windows, per-pod counters and a missing route. Then Redis goes down: fail open, fail closed, or fall back to the database and risk a cascade?
More on Ticket interviews
- Database Interviews in the AI Era: The Ticket Format
- Interview: the same job runs twice
- Deadlock Interview Question: Find and Fix It in SQL
- Slow Query Interview: One Keyword Made It 40× Slower
- Interview: “just add an index” slowed ingestion
- Interview: “I changed my name, refresh shows the old one”
- Interview: importing 10M rows takes six hours
- Interview: everything got slow and the disk keeps growing
- Lost Update Interview: Wallet Balance Wrong Under Load
- Interview: API p99 jumps 10× every night at 2 am
- Interview: profile lookups got 40× slower, writes are fine
- Interview: inserts stall, and only one page is hot
- Interview: the write succeeded, the next read shows an empty cart
- Interview: inventory stayed locked after the coordinator restarted
- Interview: for four minutes, both regions took orders
- Interview: shoes show a 0% discount, then the report crashes
- Interview: March gained $50 after the deploy, and the months don’t add up
- Interview: the new branch’s dashboard takes 38 seconds
- Interview: the index is right there, make Postgres use it
- Interview: warehouse and checkout overwrite the same order
- Interview: the bestsellers report now takes nine minutes
- Interview: an analyst query locked checkout
- Interview: the member is active and the email went out twice
- Interview: one shard is at 96% CPU and the other is idle
- Interview: the menu is slow, and the proposal is event sourcing
- Interview: four dashboards disagree about whether the database is slow
- Interview: checkout got slow the hour the warehouse job started
- Interview: the query is fast in staging and slow in production
- Interview: login looks up an email and reads the whole customers table
- Interview: the proposal splits one database into three shards
- Interview: the order page joins four tables on every view
- Interview: every page view is a read-write query on the leader
- Interview: Sarah and John both debit version 1
- Interview: the CTO read a blog post and wants to move Postgres to MySQL
- Interview: one table takes 50,000 writes a second, another feeds dashboards. Which engine for each?
- Interview: EU users wait on the ocean for every write, can both regions take writes?
- Interview: users search cars by color, but the table is sharded by car id
- Interview: we added a fourth node and most of the data moved
- Interview: two people book the same room at noon, both get a confirmation
- Interview: everything is on the strongest consistency and far requests crawl
- Interview: the order is saved, the message to search and email never left
- Interview: rename a column on a 600 GB table while 30 servers keep serving traffic
- Interview: orders go to 16 shards in 2 regions, what should the order id be?
- Interview: one celebrity posts, and every timeline in the app slows down
- Interview: 5,000 customers share one database, and one of them slows down everyone
Keep learning
Overview
Fixed window Sliding window Requests on a timeline with windows color-mix(in srgb, #3b6fd8 10%, transparent) color-mix(in srgb, #3b6fd8 4%, transparent) color-mix(in srgb, #2f8f5b 10%, transparent) A sliding window always looks at the last 60 seconds, so the burst at the boundary is cut to 2. Now scale out: each server keeps its own counter in memory
Rate limit is 2/min, yet 30 requests reach the database
Fix a broken limiter and make it work across servers. Then defend what happens when Redis goes down. fixed vs sliding window Redis + Lua cascading failure hot rows One user hits the database 30 times a minute, not 2. Each server counts alone, and windows reset at the boundary. One shared, atomic sliding-window counter in Redis, plus a failure plan.
Rate limiting doesn’t work during traffic spikes
Platform team In spikes, one user hits the database 30 times a minute. Database CPU jumps at the same time. 2 / min 30 / min API pods 3 → 15 (autoscale) Restated: about 15× too many requests get through. It gets worse as we add servers.
Where is the limiter, and where is it used?
In-memory Map (one per pod) and a fixed window.
Four questions, three bugs
Does rate limiting exist? search for rateLimit Yes, as Express middleware. Is it used on every route in the ticket? read routes.ts No. /export has no limiter at all. Is the algorithm right? read rateLimit.ts Fixed window. Boundary bursts allow 2× the limit. Does it hold when we scale out? see where the counter lives No. Each pod (server) has its own Map. 15 pods allow 15× the limit. Missing route bug 1 Fixed window Resets at :60, so bursts double. bug 2 Per-pod counter Each server counts alone. bug 3 2 / min × 15 pods each counts alone 30 / min what the DB sees How a limit of 2 turns into 30.
Specify the algorithm, the store and the failure policy
Fixes all three bugs: algorithm, shared state, missing route. Atomic check, one clock, so pods cannot disagree.
“Redis is down. Now what?”
Sliding log, sliding counter or token bucket: which one, and what does each cost? memory · CPU Pick by memory, accuracy and whether bursts are OK. Sliding log: one timestamp per request. Exact, but memory grows with the limit. Sliding counter: two weighted counters per user. About 1% error. Common in production. Token bucket: tokens plus last refill time. Allows short bursts, then a steady rate. memory per user exact vs approximate bursts allowed? Small memory Allows bursts Sliding log Sliding counter Token bucket Why does it have to be one Lua script, and not INCR then EXPIRE? Two pods read the same count, both add one, and both allow. Crash between INCR and EXPIRE: the key never expires. That user is blocked forever. Lua runs as one step on Redis and uses its clock (TIME). key with no expiry single clock separate commands: can interleave Lua script: runs as one step Redis is down. Fall back to the database? cascading failure Only briefly. It turns every request into a locked database write. A busy user’s row becomes a hot row (everyone waits on it). The pool runs out. The same database serves checkout. Time-box the fallback and add a local limiter first. writes per request shared blast radius Redis dies DB counters a write per request Hot row lock queue Pool empty Checkout down A cascading failure: the load moves, it does not vanish. Redis is not down, just slow (300 ms). What happens? Slow is often worse than down: every request waits 300 ms. Threads and connections fill up while they wait. Use a timeout of a few ms. Count timeouts as failures. A circuit breaker (auto cut-off switch) stops calling Redis, then probes later. breaker states slow is worse than down call Redis skip Redis, use fallback try one call Circuit breaker states. Success in half-open closes it again. What does the limiter cost on the happy path? One Redis round trip per request, often under 1 ms. Plus a few cheap sorted-set operations. At huge traffic, pre-check with a small local bucket in each pod. latency budget
Redis is down. There is no single right answer. Defend one.
What does the limiter do while Redis is unavailable? Fail open: allow everything No user sees an error. But the spike that killed Redis now hits the database unlimited. DB load Blast radius The database is safe, but /search and /export are down. Fine if the limit guards something critical. Fall back to DB counters Accurate, but every request is a locked write on a hot row. Minutes of this can sink checkout. Local limiter per pod (limit ÷ pods) Each pod enforces its share in memory. Approximate, but no shared dependency and the database stays safe. Time-boxed DB fallback, then fail closed Use the DB for at most ~10 s while Redis restarts. Still down? Turn the feature off, not the database.
Have one ready
Tell me about a dependency outage that spread to other systems. What failed, and why. Retries, fallbacks, shared DB, thread pools. Timeouts, breaker, load shedding, flag. What stops a repeat.
Did you show these?
Found all three bugs Drew the boundary burst on a timeline Atomic Redis check (Lua), one clock Blast radius and cascading failure Timeouts + circuit breaker for slow Redis
More courses
- Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
- Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
- React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
- System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
- NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
- Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
- Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
- AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
- Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
- TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
- CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
- Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
- Docker — What an image is, why layers cache, and how containers find each other on a network.
- Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
- Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
- AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
- Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.