System Design

Start from a known-good design

Each template opens in the sandbox with its traffic preset. Trace its flows, push the load up, break a component — then change it and watch the numbers move.

  • Monolith with everything

    One codebase scaled all the way: LB, 8 servers, cache, replicas, CDN, queue + workers.

    • Every scaling move here works without microservices.
    • Stateless app servers (sessions in Redis, files in S3) make horizontal scaling possible.
    • The email goes through a queue, so a slow provider can’t stall checkout.

    Online shop13 components2,400 req/scost 40

  • Distributed, Multi-AZ

    Services per capability behind an API gateway, sharded write path, everything across two AZs.

    • Each service owns its data; checkout spans two databases (saga/outbox territory).
    • The gateway centralises auth and rate limits; tracing follows every request.
    • Headroom (N+1) lets the survivors carry the load when an AZ fails.

    Online shop22 components2,400 req/scost 160

  • URL shortener

    100:1 reads, a hot-key cache, a key-value table, and click analytics off the redirect path.

    • Redirects are a key lookup: cache-aside in front of a key-value store.
    • Click counting goes to a stream, never inside the redirect.
    • Codes: base62 of a unique ID (counter ranges per instance) avoids collisions.
    • 301 vs 302: 301 is cached by browsers (less load, but you lose click counts).

    URL shortener9 components5,000 req/scost 51

  • DNSClientsLoad balancerServiceCacheSQL databaseRead replica

    Rate limiter

    Token buckets in a shared Redis so limits hold across every API instance.

    • Per-instance counters fail as soon as there are two instances — share them.
    • Token bucket allows bursts; sliding window is smoother; fixed window has edge spikes.
    • Coarse limits at the edge (WAF/gateway), fine-grained per-user quotas in Redis.
    • Return 429 with Retry-After; fail open or closed when Redis is down? Decide explicitly.

    Rate-limited API7 components2,000 req/scost 43

  • Chat

    Socket servers, pub/sub fan-out between them, messages with sequence numbers, offline push.

    • Socket servers are stateful (they hold connections) — pub/sub connects them.
    • Messages get per-conversation sequence numbers so reconnecting clients catch up.
    • Presence is a TTL key refreshed by heartbeats.
    • Offline users get a push notification through a queue.

    Chat11 components3,000 req/scost 28

  • News feed

    Fan-out on write into a feed cache, media on a CDN, posts on a replicated DB.

    • Fan-out on write: precompute feeds when a post is created (fast reads).
    • Celebrities break it — fan out on read for accounts with huge follower counts (hybrid).
    • Feeds store post IDs; post bodies are hydrated from a replicated store.
    • Media goes through a CDN, never your API.

    News feed14 components2,000 req/scost 60

  • Notification system

    One API, a topic per request, a queue + workers per channel, a shared DLQ.

    • Idempotency keys stop duplicate notifications when callers retry.
    • One queue per channel: a slow SMS provider can’t delay emails.
    • Workers retry with backoff, then DLQ; providers get timeouts.
    • User preferences and quiet hours are checked before fan-out.

    Notification system17 components500 req/scost 47

  • Photo uploads

    Presigned direct uploads, S3 events → thumbnail workers, CDN for viewing.

    • Clients upload straight to object storage with presigned URLs.
    • Upload events trigger thumbnailing in the background.
    • Metadata in a DB, bytes in object storage, delivery through a CDN.
    • Validate files after upload (type, size, malware) — the client controls the bytes.

    Photo uploads11 components500 req/scost 32

  • Payments (AWS VPC)

    Idempotent checkout, provider calls with timeout + breaker via NAT, a double-entry ledger, webhooks.

    • Idempotency keys on every money-moving request.
    • Provider calls have a timeout, a circuit breaker and safe retries.
    • The ledger is append-only, double-entry, in a Multi-AZ database.
    • Webhooks are the source of truth for final status — verify signatures, process idempotently.
    • Compute and data live in private subnets; outbound calls leave via NAT.

    Payments14 components200 req/scost 41