System DesignVol. 12 · Part XII
0 / 0

Shelves / System Design

SD·135

System Design Projects

Eight build-it-yourself projects that turn the tiffin centre into a measured, defensible system design: requirements as executable checks, a capacity model checked against measurements, a load-balanced and failure-tested service tier, a caching layer with consistency rules, a scaled data tier with replicas and partitions, reliable messaging and events, a resilient and well-shaped API, and a multi-tenant, multi-region design review, each with milestones, measurable definitions of done and stretch goals.

12 topics · ~7 min read · 5-question quiz
Updated Suggest a correction

How to approach the projects

One system, designed and proved

The labs in this volume measured one building block at a time. These projects design the tiffin centre (customers, kitchens, riders, payments, and now other kitchen chains as tenants) end to end, and prove each design decision with a measurement or a test. Everything runs on a laptop or a small cluster: Go, Java or Python services; PostgreSQL with replicas; Redis; HAProxy or Envoy; NATS or Kafka; etcd; k6, wrk and Toxiproxy; and a diagramming tool for the design documents.

# Project Main chapters Roughly
1 Requirements you can run Start Here, 121 a weekend
2 A capacity model that matches reality 122, 124 1 week
3 A service tier that survives failures 123, 125 1 week
4 Caching with written consistency rules 126, 129 1 week
5 A data tier ready for 10× 127, 129 1–2 weeks
6 Events that never get lost 128, 131 1–2 weeks
7 An API that's fast, safe to retry and evolvable 130, 132 1 week
8 Multi-tenant, multi-region design review 133, 134, Case Studies 1–2 weeks

New to system design? Do them in order; each builds on the last. Experienced? Do project 1 and then pick the project for the part of your own systems you trust least.

The working method

  1. Design document first, following the case-study method: requirements, estimates, API and data model, architecture, deep dives, failure modes, evolution.
  2. Every box earns its place with a requirement and a number; record decisions as ADRs.
  3. Prove it: each project's definition of done is a measurement or a test you can rerun.
  4. Break it on purpose: kill processes, add latency, partition networks, overload tenants.
  5. Keep the cost in view: machines, storage, replicas and operational effort for each choice.

The eight projects

Project 1: requirements you can run

Goal. The tiffin centre's functional and non-functional requirements written down and checked automatically.

Milestones. Users, workflows and core operations as use cases → NFRs with measures, thresholds and conditions (latency, availability, durability, idempotency, isolation) → explicit non-goals and constraints → an NFR check suite like chapter 121's (hard kills, retries, load thresholds) running in CI → ADRs for the first three trade-offs.

Done when. At least eight NFRs each have an automated check; a deliberately broken version (in-memory orders, no idempotency key) fails the right checks; the suite runs in under five minutes.

Stretch. Add a conflicting-requirements review: find two requirements that can't both hold as written and resolve them with a design change recorded in an ADR.

Project 2: a capacity model that matches reality

Goal. A spreadsheet or script that predicts QPS, storage, bandwidth and instance counts, validated against measurements.

Milestones. Traffic model from users and behaviour, with peaks → measured per-instance capacity for each service (k6 against one instance) → measured storage per row including indexes, and replication and retention multipliers → instance counts at target utilisation, for today and for 10× → the shared step (lock, primary, hot key) that limits scaling, found with a USL-style measurement.

Done when. Predicted and measured throughput for 1, 2 and 4 instances agree within 15%; predicted and measured storage for 1 million orders agree within 20%; the model names the first component that breaks at 10× and why.

Stretch. Fit σ and κ for one service and predict the concurrency where throughput peaks; verify it.

Project 3: a service tier that survives failures

Goal. Stateless services behind redundant load balancing, with measured failover.

Milestones. Services stateless, sessions in a shared store → two load balancers with a floating IP or DNS failover → least-connections or power-of-two balancing, active and passive health checks, connection draining on deploy → etcd (or another consensus store) for configuration and leader election where needed → a failure drill script: kill an instance, a load balancer, an etcd member, the etcd leader.

Done when. At steady load, killing any single instance costs fewer than 0.1% failed requests; a rolling deploy causes zero errors; failover times for each component are measured and written down; an availability calculation from those numbers meets the target in project 1.

Stretch. Add outlier detection (passive ejection of slow instances) and show a slow-but-alive instance being removed automatically.

Project 4: caching with written consistency rules

Goal. Caches that make reads fast without ever serving data that must be fresh.

Milestones. Measure key skew from access logs → a table of every cached item with its staleness rule (TTL, invalidate on write, never cached) → cache-aside with jittered TTLs and stampede protection for hot keys → invalidation on write via the outbox/CDC from project 6 → per-tenant keys → cache-loss drill: flush Redis at peak and watch the database.

Done when. p50 for cached reads is under 1 ms; database read load drops by the measured hit ratio; a hot key's expiry under 500 concurrent readers causes at most a handful of database queries; a price change appears within its documented staleness bound; the database survives a full cache flush at peak.

Stretch. Add an in-process near-cache in front of Redis and measure the extra speed-up and the new staleness bound.

Project 5: a data tier ready for 10×

Goal. The database layer scaled for the 10× plan, with consistency preserved where it matters.

Milestones. Indexes and queries tuned from EXPLAIN ANALYZE → read replicas with read-your-writes handled (sticky primary reads or LSN waits) → orders partitioned by month with automated creation and archiving → invariants protected (slot stock, wallet) with constraints, atomic updates or serializable transactions with retries → a sharding plan (key, routing, resharding, cross-shard queries) written but not yet built.

Done when. No user ever fails to see their own order after placing it, in a test that reads immediately from replicas under write load; monthly archiving drops a partition in under a second; the oversell and lost-update tests from chapters 116 and 129 pass under 50 concurrent clients; the sharding plan says exactly which queries become cross-shard.

Stretch. Build the sharding plan with Citus (or two PostgreSQL instances and a routing layer) and measure a cross-shard query against a single-shard one.

Project 6: events that never get lost

Goal. Every state change that others need is published reliably and consumed exactly once in effect.

Milestones. Event catalogue (types, owners, schemas, versions) → transactional outbox in each producing service, relay with SKIP LOCKED (or Debezium) → idempotent consumers with inbox tables → per-order ordering via partition keys → retries, max deliveries and a dead-letter queue with a replay tool → the order saga (placed → paid → cooking → ready → delivered) with compensations.

Done when. With crashes injected in producers, relays and consumers at 5%, a reconciliation query finds zero orders missing from the kitchen and zero duplicate side effects across 10,000 orders; a poison message lands in the DLQ without blocking others; a schema change ships with old and new consumers running together.

Stretch. Replace polling with CDC and measure end-to-end event latency at p50 and p99.

Project 7: an API that's fast, safe to retry and evolvable

Goal. Public and internal APIs designed for real clients, failure and change.

Milestones. OpenAPI for the public API, gRPC or typed contracts internally → cursor pagination everywhere → batch endpoints for screens (no N+1) → idempotency keys for every POST that changes money or orders → ETags for reads and If-Match for updates → deadlines propagated across services; retries at one layer with jitter and a budget → problem-details errors; a deprecation policy with sunset headers.

Done when. Deep pagination stays under 5 ms at a million rows; the busiest screen needs one request; a retried payment never double-charges, including concurrent retries; a three-service chain sends at most 1× extra load to a failing dependency (no amplification); a breaking change ships through expand and contract with contract tests (Volume 11) passing throughout.

Stretch. Offer the same queries over GraphQL with DataLoader and cost limits, and compare request count and latency for the menu and order screens.

Project 8: multi-tenant, multi-region design review

Goal. A design for selling the platform to other kitchen chains across India and Europe, reviewed like a real architecture proposal.

Milestones. Tenancy model (pooled, bridge, silo tiers) with RLS and per-tenant limits implemented for the pooled tier → noisy-neighbour test (one tenant at 150% of capacity) → region strategy: home regions per tenant, residency for EU tenants, async DR with stated RPO/RTO → a failover drill between two "regions" (two clusters with Toxiproxy latency) → a design document reviewed against the case-study checklist by someone else.

Done when. A cross-tenant test suite proves zero leaks through every endpoint; the small tenant's p95 is unchanged while the big tenant is throttled; commits stay local-region fast; a region failover meets the stated RPO and RTO in a drill; the reviewer's findings are resolved or recorded as accepted risks.

Stretch. Cost the design: machines, storage, cross-region transfer and replicas per tenant tier, and price the tiers so each covers its cost.

Tracking your progress

Portfolio checklist

Keep the design documents, ADRs, capacity model, tests, drill scripts and measurements in Git, with a README per project. System design evidence is numbers behind each decision: "8 NFRs as CI checks; model vs measured throughput within 9%; instance kill → 0.04% errors; cache p50 0.3 ms with documented staleness; 0 lost orders in 10,000 with 5% crashes; deep page 0.4 ms at 1 M rows; retries add ≤1× load; 0 cross-tenant leaks; region failover RPO 2 s, RTO 4 min" is what makes the portfolio credible.

Mapping to mastery levels

Completing projects 1–3 with their checks puts you at L2 across the volume. Doing their stretch goals and explaining every mechanism is L3–L4. Designing and defending projects 4–8 (consistency per data item, data-tier evolution, event reliability, API evolution, tenancy and regions) is L5 work, the level senior and staff system design interviews probe.