Design an API Rate Limiting & Auth Gateway

Hard45 min
1 / 30
System design answer

Design an API Rate Limiting & Auth Gateway

Hard45 min30 sections
understanding•10 min read

Problem Statement: The Enforcement Point Every Request Must Cross

Frames the gateway as a consolidated policy-enforcement plane, not a load balancer with extra steps.

Problem statement

Design an API Rate Limiting & Auth Gateway: a single consolidated entry point that sits in front of every public and partner-facing microservice. Every inbound request must be authenticated (JWT, OAuth2 access tokens, API keys, or mutual TLS), authorized against coarse scopes, checked against multiple rate limits (per IP, per credential, per user, per tenant plan), admitted or rejected with correct semantics, enriched with routing and experiment headers, and logged for usage analytics and billing.

The trap in this question is treating the gateway as "just a load balancer." A load balancer distributes traffic; this system decides whether traffic is allowed to exist. It is the last line of defense where a bad decision is cheap (drop a request) and the first place where every downstream service's availability, quota correctness, and identity story collapse into one code path that must add almost no latency and never become a single point of failure.

Why this problem is distinctive

Three properties separate it from ordinary backend design:

  1. Every request pays the toll. If the gateway adds 10 ms p99, every API in the company just got 10 ms slower. The entire auth and rate-limit decision must fit inside a latency budget measured in single-digit milliseconds, which forces aggressive caching and local decisioning.
  2. It is a multi-tenant policy engine. Ten thousand tenants with different plans, custom rules, negotiated quotas, and burst allowances means the system evaluates a program per request, not a constant. Rules are data, pushed by a control plane, hot-reloaded without restarts.
  3. It must degrade with intent. When its dependencies fail (Redis, the identity provider, the config store), the gateway must choose between fail-open (availability first, some overage risk) and fail-closed (security first, outage risk) per signal, and those choices must be explicit design decisions, not accidents.

Public operating anchors

The category is real and enormous. Cloudflare reported handling a peak of roughly 78 million HTTP requests per second across its network in 2023, and its rate limiting product enforces rules across millions of domains at that edge scale. GitHub documents a primary REST limit of 5,000 requests per hour per authenticated user and a points-based budget of 5,000 points per hour for GraphQL, showing two different quota models in one public API. Stripe's public documentation describes tiered rate-limit categories with different ceilings per endpoint class. These are published product behaviors that anchor our design assumptions; every internal number in this answer is an explicit assumption unless attributed.

The four planes

  1. Inline enforcement plane: TLS termination, route matching, authentication, authorization, rate limiting, concurrency admission, header injection, upstream forwarding. This path must be fast, stateless-ish, and survive dependency loss.
  2. Control plane: tenants, plans, API keys, rate-limit rules, scopes, policy bundles, signed distribution, rollout and rollback.
  3. Counter and usage plane: distributed counters, quota ledgers, usage streams, analytics, billing exports, developer-portal usage views.
  4. Abuse and learning plane: anomaly aggregation, reputation, adaptive thresholds, incident evidence, rule tuning.

A strong answer keeps these planes separate: the inline plane degrades without weakening enforcement, the control plane can be down for minutes without affecting in-flight requests, and the learning plane never changes live rules without an explicit, reviewable promotion.

Key Highlights

  • •The gateway is a policy decision engine on the critical path of 100% of traffic, not a load balancer.
  • •Auth + rate-limit decision must complete inside a single-digit-millisecond p99 budget.
  • •Rules are data: multi-tenant policy bundles pushed from a control plane and hot-reloaded.
  • •Cloudflare (roughly 78M rps peak in 2023), GitHub (5,000 req/hr REST, points-based GraphQL), and Stripe (tiered categories) anchor the public reality.
  • •Four planes: inline enforcement, control, counters/usage, abuse/learning.
Say It In The First Minute
State that this is a policy decision engine on the critical path of 100% of traffic, not a load balancer. That single framing separates your answer from the majority.
Do Not Ignore The Toll
Every millisecond the gateway adds is paid by every API behind it. An answer that never names a latency budget for the auth + limit decision misses the core tension of the question.

Section Rescue Kit

Buzzwords to use:

Policy Decision PointLast Known Good

Safe statements:

  • "Before drawing boxes, let me separate what must run inline on every request from what can be eventually consistent."
  • "I will treat the gateway as four planes so that a failure in one never silently breaks another."
Design an API Rate Limiting & Auth Gateway - System Design | WinJob | WinJob