Design API Gateway System

API gateway platform inspired by Envoy/Kong-style gateways: local JWT validation with cached signing keys, a control plane pushing versioned routes, weighted canary routing, distributed token-bucket rate limiting, circuit breakers and async access logs. A teaching design.

Functional requirements

  • Terminate TLS and accept client requests for multiple backend APIs.
  • Authenticate requests (JWT/OAuth/API keys) and attach identity to the request context.
  • Authorize requests (RBAC/ABAC) based on route, method, tenant, and user.
  • Route requests to the correct internal service based on host/path/headers.
  • Apply per-tenant quotas and per-user/IP rate limits.
  • Emit access logs, metrics, and traces with correlation IDs.
  • Support safe configuration updates (new routes, policy changes) with rollback.

Non-functional requirements

  • p95 gateway added latency should be under 15ms; p99 under 40ms under normal load.
  • 99.9% availability for the gateway tier (multi-AZ; no single point of failure).
  • Graceful degradation under overload (shed best-effort work before failing core routing/auth).
  • Strong security posture: input validation, WAF rules, least-privilege, secrets hygiene.
  • High observability: debug a single request end-to-end within minutes (trace + logs + metrics).
  • Config changes should propagate safely within minutes with auditability and rollback.

How the design evolves

Stage 1: One Proxy Checking Every Token in the Database

See why authenticating every call against a database doesn't fit a 50 ms budget.

What was missing: Nothing yet.

Why that's risky: Every API call becomes a database query before any real work happens, and one proxy carries 100K calls per second.

What gets added: One proxy that looks up each caller's token in the identity database and forwards the request.

Trade-offs: Revocation is instant, but the identity database is on every request's critical path.

Stage 2: A Gateway Fleet with Local Token Validation

Authenticate without a database call per request.

What was missing: Every call queried the identity database.

Why that's risky: Routes live in each gateway's config file, so a change means redeploying the fleet, and new backend versions can't be tried safely.

What gets added: An edge load balancer with TLS and WAF, a stateless gateway fleet that validates JWTs locally with the auth service's public signing keys (JWKS) and looks up API keys in a cache, and an auth service that issues tokens, rotates keys and answers revocation checks.

Trade-offs: A locally validated token stays valid until it expires unless the revocation list catches it, so tokens are short-lived (minutes).

Stage 3: Control Plane, Pushed Route Table and Canaries

Change routing safely without redeploying gateways.

What was missing: Routing was baked into gateway config files.

Why that's risky: One client can still send unlimited requests and starve everyone else.

What gets added: A control plane that stores versioned routes, policies and quotas and pushes them to every gateway, where they are swapped atomically in memory; weighted routing sends a small share of traffic to a canary version of a backend.

Trade-offs: Pushed config is eventually consistent: for a few seconds some gateways may run the previous version.

Stage 4: Distributed Rate Limiting

Enforce per-tenant quotas across the whole fleet.

What was missing: No quotas: one tenant could starve all others.

Why that's risky: Gateways write access logs synchronously, and nobody can see per-route errors or trace a slow request.

What gets added: A distributed rate limiter with token buckets per tenant and API key in Redis; each gateway takes a small local allowance so most requests skip the round trip.

Trade-offs: Local allowances allow a tenant to slightly exceed its quota for a moment, in exchange for not paying a Redis call per request.

Stage 5: Async Access Logs, Tracing and Circuit Breakers

Record every call without slowing it, and see and contain failures.

What was missing: Logging was synchronous and failures were invisible.

Why that's risky: Remaining risk is regional: the fleet runs in several regions behind global DNS or anycast.

What gets added: Gateways write access log entries and trace spans to a buffer without waiting; ingesters batch them into object storage and compute per-route metrics. Circuit breakers stop forwarding to a backend that keeps failing, and dashboards alert on latency, errors and breaker trips.

Trade-offs: Logs arrive seconds after the call; under extreme load the buffer may sample rather than drop requests.

Frequently asked questions

JWT validation vs token introspection — which should the gateway use?

JWT validation is fast and avoids an auth dependency in the hot path (good for p99). Introspection enables immediate revocation and central control but adds latency and creates a dependency. Many production systems use JWT validation with short token TTLs plus a revocation mechanism for high-risk cases.

How do you do rate limiting without making the limiter a bottleneck?

Scope limits correctly (per-tenant/user/key), keep checks O(1), and avoid a single centralized counter. Common approaches: sharded counters in Redis, local leaky-bucket with periodic sync, or tiered limiting (edge coarse limit + gateway fine limit).

Where should timeouts/retries live — gateway or services?

Both, but with clear budgets. The gateway should enforce an overall deadline and avoid unbounded retries. Services often need their own timeouts/circuit breakers for downstream dependencies. The key is preventing retry storms and respecting a per-request latency budget.

PRISM
System Design Interview
Round 1 of 4 · Architecture Design · 60:00 remaining
PRISM logo PRISM logo
Problems
AI Interview
Interview Challenges
Build & Stress Test NEW
System Architectures
Design & Fix NEW
Interactive Roadmap
System Design Guides Interview Prep Guide
Problems
Today's mission
Notifications
    Theme
    Pricing Community NEW Send feedback Report a problem NEW
    Sign in
    Theme
    Community NEW Send feedback Report a problem NEW
    All problems
    Phase
    Build & Stress Test
    Phase 01: Thinking in Systems
    Upcoming

    Components

    User
    CDN
    Load Balancer
    Server
    Cache
    Database
    Blob Storage
    Search Index
    Queue
    Worker
    Rate Limiter
    Service
    API Gateway
    Reverse Proxy
    WebSocket Server
    Third-party API

    Inspector

    Notes
    Use clear names so your design intent is easy to understand.
    Good
    Name by business meaning
    "Order API", "Restaurant Service"
    Avoid
    Generic names = zero signal
    "Server 1", "API", "Queue"
    A short description for each component makes feedback much better.
    100%
    Start by identifying:
    • Users & entry points
    • APIs & services
    • Databases & storage
    • Traffic flow & scale

    Round 1 of 4 Architecture Design

    Run a simulation to see results.

    Time Remaining
    60:00
    System Design Interview

    What are the core functional requirements?
    What are the key non-functional constraints?

    Questions

    Start Evaluation to unlock questions.

    EVALUATE MODE

    Test yourself like it's the real thing.

    A structured 4-module evaluation that mirrors how top companies assess system design candidates.

    Architecture Design
    Draw your system on the canvas. Define components, connections, and data flow.
    FR & NFR Requirements
    Answer functional and non-functional requirement questions about your design.
    MCQ Round
    Multiple choice questions testing your depth on the chosen system.
    Tradeoff Analysis
    Justify your design decisions and defend your architectural tradeoffs.
    AI Report Generated
    Choose a Problem
    No problem selected
    • 30 min
    • 45 min
    • 60 min
    Round 2 of 4
    MCQ Round
    Answer multiple-choice questions based on your design.

    Exit Interview?

    You're in the middle of an interview session. Leaving now will end your current attempt.

    Your progress will be saved.

    Open a saved design

    Select a design to load into the canvas.

    My Evaluations

    Your past evaluation sessions

    Here’s a simple request flow that follows the expected layer order.

    External User
    →
    Edge CDN → API Gateway → Load Balancer
    →
    Compute App Servers / Services
    →
    DataAccess Cache
    →
    Storage Database / Search Index
    →
    Async Queue → Worker

    Tip: keep arrows moving forward through layers (Edge → Compute → Storage). Avoid sending storage back to compute.

    Evaluation Instructions

    Read the rules carefully before starting. The test auto-submits on refresh.

    Before you start

    • Build your architecture on the canvas. The timer starts when you click Start Evaluation.
    • Don't forget to answer Functional Requirement and Non Functional Requirements.
    • When satisfied with your design, click Next to lock it and view the questions.
    • Please answer final step questions to complete the evaluation.

    Dos

    • Do read each question carefully before answering.
    • Do include required components to maximize component coverage.
    • Do save a copy of your design if you want to keep it before submission.

    Don'ts

    • Don't refresh or close the tab during an active evaluation — this will auto-submit your answers.
    • Don't switch app modes or open another tab while the evaluation is running.
    • Don't attempt to edit the design after clicking Next; the workspace will be locked.

    All the best!!

    Confirm

    Input

    Notice

    Evaluation Report
    Report a problem

    Evaluation Complete

    Generating Your Report

    Hang tight — our AI is evaluating your design…

    Did you know?

    Loading…

    Share feedback

    Tell us what worked well and what we can improve.

    Let's personalize this

    Answer a couple of quick questions so we can tailor your journey and missions.

    Your welcome gift: of Full PRISM Access

    Your Pro access starts as soon as you press Start my journey.

    SYSTEM BRIEF

    System Constraints

    What the system must do — every item is a user-facing behaviour your architecture must support.

      ↑ Engineering Constraints

      These are the failure modes you must design against — latency SLAs, durability targets, traffic ceilings.

        ⇆ Architecture Constraints

        Core Concepts to Master

        Your Journey
        PHASE – –
        0 / 0 0%
        0
        Mock Interview Checklist

        Pick a topic to start

        Explore concept overviews, real-system examples, key tradeoffs, and interview talking points for each roadmap section.

        Phase Mastered

        You've conquered this phase. These are the skills you now own:

          +500 XP

          Company Interview Paths

          Progress Summary