Free preview

Why Rate Limit

In one line: rate limiting is one of the few components that shows up in almost every design and in almost every real production incident. The reasons it exists are more varied than "stop attackers," and knowing all four makes you place it correctly.

Why we need one

Rate limiters act as a defensive layer to prevent excessive usage, whether intended or unintended. They protect services against application-layer abuse, such as denial-of-service (DoS) attacks and brute-force password attempts.

ScenarioWhat the rate limiter does
Preventing resource starvationSoftware errors or misconfigurations can trigger 'friendly-fire' denial of service incidents. Rate limiters prevent these events from exhausting system resources
Managing policies and quotasEnsure fair resource usage in multi-tenant environments. They enforce policies based on time duration or allocated quotas
Controlling data flowIn systems processing large data volumes, they regulate flow to prevent overloading specific machines, helping distribute the workload evenly
Avoiding excess costsControl operational costs by preventing runaway experiments or processes. Cloud providers use this to limit freemium tiers or cap billable usage

'Friendly fire' is the reason that actually justifies it in most systems

Everyone reaches for the attacker story first, but the first row is the one that fires in practice.

A retry loop with no backoff. A cron job accidentally scheduled every minute instead of every hour. A client library that reconnects aggressively after a deploy. A new integration that paginates by fetching everything. None of these are malicious, and every one of them can take a service down.

That reframes the component: a rate limiter is not primarily a security control, it is a reliability control. It protects you from your own callers, your own code, and your own operational mistakes.

It is also why "we're internal-only, we don't need rate limiting" is wrong. Internal callers are the ones with the most credentials, the highest throughput, and the least fear.

The fourth reason is business, not engineering — and it is why the design must be configurable

"Limit freemium tiers or cap billable usage" is a product requirement wearing an infrastructure costume, and it drives a real design constraint.

If limits were purely about protecting the service, one global number would do. But per-tier limits mean the limiter must support rules that differ per client, changeable without a deploy, because pricing changes on a business timeline rather than an engineering one.

That single requirement is why Lesson 5's design has a rule database with a background retriever rather than a constant in the code. Recognizing that a business requirement forced an architectural component is a strong observation to make in an interview.

Rate limiting is not DDoS protection — be precise about which problem you're solving

A rate limiter sits inside your infrastructure and works by identifying a client and counting its requests. That means the request has already arrived — it has consumed bandwidth, a connection, and some CPU before you rejected it.

Against a volumetric DDoS — millions of hosts saturating your uplink — the limiter is downstream of the problem, and it will fall over alongside everything else. That defence lives at the network edge: scrubbing, anycast, upstream filtering.

Where a rate limiter genuinely wins is application-layer abuse from identifiable clients: brute-force login attempts, scraping, one tenant crowding out another, a client stuck in a retry loop. State that distinction and you avoid the follow-up that catches people out.

Everyone reaches for the attacker story first, and the reliability case is the one that fires in practice. That reframing also answers "we're internal-only, we don't need one" — internal callers have the most credentials and the highest throughput, and no incentive to be gentle.

Where this chapter goes

LessonCovers
RequirementsFunctional and non-functional requirements, types of throttling, and placement strategies
High-level designAn overview of the rate limiter architecture
Detailed designThe specific building blocks and components
AlgorithmsThe algorithms that drive rate-limiting logic

Key takeaway

A rate limiter throttles traffic beyond a defined threshold. Four reasons to have one: preventing resource starvation (mostly from your own callers), enforcing quotas in multi-tenant systems, controlling data flow, and capping cost. It defends the application layer — not the network edge.

Interview signal by level

LevelWhat a strong answer sounds like
L4"It stops clients sending too many requests."
L5Gives more than one reason: "it protects against abuse, but also enforces per-tenant fairness and caps cost on metered resources."
Staff+Reframes it as reliability and scopes it honestly: "the case that actually fires is friendly fire — a retry loop without backoff, a misscheduled cron. So it's a reliability control, not a security one, and that's why internal-only services still need it. It also won't help against a volumetric DDoS, since the request has already consumed bandwidth by the time we count it — that defence belongs at the edge."

Next: what we're required to build, and where to put it.

Enjoying the preview?

Create a free account to unlock the rest of this course, the in-browser judge, and live AI mock interviews.

Sign up free to continue