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.
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.
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).
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.
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.
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.
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.
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.
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.