Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 97

    System Design Basics

    System design is a structured conversation: clarify requirements, estimate scale, draw boxes, choose data stores, then deep-dive on failure modes.

    Course progress0%
    Focus
    12 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    System design is a structured conversation: clarify requirements, estimate scale, draw boxes, choose data stores, then deep-dive on failure modes. For TechLearningPRO Orders on Spring Boot 3 / Java 21, that conversation turns into concrete choices — Postgres for the ledger of checkouts, Redis for hot SKU reads, Kafka for async fulfillment events, and an API gateway for auth and rate limits.

    Interview whiteboards and production RFCs share the same vocabulary: RPS, p99, consistency, caching, partitioning. The difference is that Orders must ship — estimates drive pool sizes, topic partitions, and SLO alerts, not just slides.

    This lesson gives you the repeatable template used for both senior interviews and Orders architecture reviews.

    Purpose of this lesson

    Apply a seven-step system-design template to TechLearningPRO Orders so estimates, APIs, and failure plans stay explicit under Boot 3.

    Understanding the topic

    Interview-and-real-life template — same steps, different fidelity.

    • 1. Clarify — functional + non-functional (latency, durability, compliance).
    • 2. Estimate — RPS, storage growth, bandwidth, peak vs average.
    • 3. High-level — clients → gateway → Orders → DB / cache / queue.
    • 4. Data model — schema, indexes, partitioning keys.
    • 5. APIs — endpoints, idempotency keys, error envelopes.
    • 6. Deep dives — cache invalidation, outbox, search, ML where relevant.
    • 7. Ops — failures, monitoring, deploy/rollback.

    Step-by-step explanation

    1. Write Orders FR/NFR: place order, cancel, list history; p99 < 300ms for GET; strong consistency on payment confirm.
    2. Estimate Black Friday: 2k place-order RPS peak, 50M order rows/year, average payload 2 KB.
    3. Draw boxes: CDN → Gateway → Orders pods → Postgres primary/replica → Redis → Kafka.
    4. Define POST /api/orders with Idempotency-Key and problem-details errors; document failure paths.

    Informative example

    Orders capacity sketch (interview-grade, production-useful).

    bash
    // Back-of-envelope for TechLearningPRO Orders
    Peak place-order RPS: 2_000
    Avg request size: 2 KB → ingress ≈ 4 MB/s
    Orders retained 3 years: ~150M rows
    Row width ≈ 500 B → ~75 GB + indexes (~2×) ≈ 150 GB
    Postgres: primary + 1 replica; partition by created_month if scans hurt
    Redis: sku:{id} TTL 5m; cache hit target ≥ 90% on catalog reads
    Kafka: orders.placed, 12 partitions, retention 7d
    Boot 3 pods: HPA on CPU + p99 latency; Java 21 virtual threads for I/O fan-out

    Real-world use

    A TechLearningPRO architecture review once approved 'just add Redis' without RPS math. Under a flash sale, cache stampede hit Postgres and checkout p99 spiked to 8s. Re-running estimates forced a request coalescing lock, a higher Redis TTL for immutable SKU fields, and gateway rate limits — the same steps a good system-design interview would have surfaced.

    Security implications

    Scale designs must not weaken tenancy or auth.

    • Partition and cache keys include tenant/org where data is private.
    • Gateway auth before fan-out; never expose internal service ports publicly.
    • Keep credentials in env/secret stores — never in diagrams pasted into tickets as real values.

    Best practices

    • Always state assumptions and units (RPS, GB, ms).
    • Prefer boring technology that the team can operate (Postgres + Redis + Kafka).
    • End every design with monitoring: SLOs, alerts, and a rollback story.

    Common mistakes

    • Jumping to microservices before a single Orders bounded context is clear.
    • Ignoring write path consistency while over-optimizing read caches.
    • Designing for average load and melting on peak.

    Advanced interview questions

    Interview Prep

    Practice concise answers, then expand each card for the explanation.

    3 questions
    1BeginnerQuestionWhat is the first step in a system design interview?+

    Answer

    Clarify functional and non-functional requirements and constraints before drawing boxes.
    2IntermediateQuestionWhy estimate scale early for Orders?+

    Answer

    RPS and storage shape DB choice, caching, partitioning, and pod counts — without numbers every decision is guesswork.
    3IntermediateQuestionHow do you handle peak vs average traffic?+

    Answer

    Size for peak with headroom, use autoscaling and rate limits, and shed non-critical work under overload.

    Hands-on exercise

    Lab. Design Orders for 10× Black Friday. Deliver: (1) FR/NFR list, (2) capacity sheet, (3) sequence diagram for idempotent place-order, (4) three failure modes with mitigation. Timebox 45 minutes; present trade-offs out loud.

    Summary

    Use the seven-step template for interviews and Orders RFCs alike. Next: turn estimates into a repeatable backend optimization playbook.

    Ready to mark this lesson complete?Track your journey across the entire course.