Skip to lesson

System design thinking practice

A review of this module. Skip it if you feel confident; the next module does not need it.

Fix the mistakes

The slips that cost marks in this module. Spot each one, then check the fix.

Most fresher design answers repeat the same four mistakes. Each section below shows one, a test you can run in your head, and a small Java program that runs the same test with numbers.

Mistake 1: mixing features and qualities

One bullet list that holds "customer adds to cart" and "cart loads in 200 ms" hides the qualities. The example keeps two lists and counts them.

Example 1 · Two lists: functional and non-functional

RequirementSorter.javaJava
import java.util.List;
record Req(String text, boolean functional) {}
public class RequirementSorter {    public static void main(String[] args) {        List<Req> reqs = List.of(                new Req("Customer adds a product to the cart", true),                new Req("Cart page answers in under 200 ms at p95", false),                new Req("Admin uploads up to 5 photos per product", true),                new Req("Orders survive the loss of one disk", false),                new Req("Customer applies a coupon code at checkout", true),                new Req("Site handles 3,000 orders a minute on sale day", false));
        int f = 0;        int n = 0;        System.out.println("Functional (what users do):");        for (Req r : reqs) {            if (r.functional()) {                System.out.println("  " + r.text());                f++;            }        }        System.out.println("Non-functional (how well, with a number):");        for (Req r : reqs) {            if (!r.functional()) {                System.out.println("  " + r.text());                n++;            }        }        System.out.println(f + " functional, " + n + " non-functional");    }}
Output
Functional (what users do):
  Customer adds a product to the cart
  Admin uploads up to 5 photos per product
  Customer applies a coupon code at checkout
Non-functional (how well, with a number):
  Cart page answers in under 200 ms at p95
  Orders survive the loss of one disk
  Site handles 3,000 orders a minute on sale day
3 functional, 3 non-functional

What this code does

  • Each Req carries a flag set by the quick test, so the program prints the two lists separately and counts them.
  • "Admin uploads up to 5 photos" has a number but is still functional: it is something a user does. The number is part of the feature, not a quality of the system.

Quick test: if "a user can..." fits in front of it, it is functional. If it has a target such as ms, % or Rs, it is non-functional. Review: What system design is (opens in a new tab)

Find the bug

Find the quality hiding in the feature list

Select the line that is wrong.

ShopLite's feature list. Tap the line that is not a feature.

Round 1 of 2

Mistake 2: picking nines without counting minutes

"We need 99.99%" sounds safe, but it allows only about 4 minutes of downtime a month. The example picks the lowest target that fits what each app can tolerate.

Example 2 · Picking the lowest target that fits the tolerable downtime

AvailabilityPicker.javaJava
public class AvailabilityPicker {    static final double[] TARGETS = {99.0, 99.5, 99.9, 99.95, 99.99};    static final double MINUTES_PER_MONTH = 30 * 24 * 60;
    // The lowest target whose downtime fits what the business can tolerate.    static double pick(double tolerableMinutes) {        for (double t : TARGETS) {            double down = (100 - t) / 100 * MINUTES_PER_MONTH;            if (down <= tolerableMinutes) {                return t;            }        }        return TARGETS[TARGETS.length - 1];    }
    static void show(String app, double tolerableMinutes) {        double t = pick(tolerableMinutes);        double down = (100 - t) / 100 * MINUTES_PER_MONTH;        System.out.printf("%-26s can lose %5.0f min/month -> %s%% (%.1f min allowed)%n",                app, tolerableMinutes, t, down);    }
    public static void main(String[] args) {        show("Attendance report (staff)", 480);        show("Fest registration", 250);        show("UPI-style payments", 25);    }}
Output
Attendance report (staff)  can lose   480 min/month -> 99.0% (432.0 min allowed)
Fest registration          can lose   250 min/month -> 99.5% (216.0 min allowed)
UPI-style payments         can lose    25 min/month -> 99.95% (21.6 min allowed)

What this code does

  • pick walks the targets from lowest to highest and returns the first whose monthly downtime is within what the app can tolerate.
  • The attendance report gets 99.0% and payments get 99.95%. Choosing 99.99% for every app would multiply the cost for no benefit.

Start from the business: how many minutes a month can this app be down before it really hurts? A staff-only report can lose hours; a payment app cannot lose more than a few minutes. Overshooting costs money, undershooting costs users. Review: Latency, throughput and availability (opens in a new tab)

Mistake 3: missing the single point of failure

Freshers often add three app servers and stop, leaving one load balancer and one database. The example scans three architectures for parts that are critical and have one copy.

Example 3 · Scanning three architectures for single points of failure

SpofScan.javaJava
import java.util.ArrayList;import java.util.List;
public class SpofScan {    // Each part is written "name:copies:critical", for example "MySQL:1:yes".    static List<String> spofs(String architecture) {        List<String> found = new ArrayList<>();        for (String part : architecture.split(", ")) {            String[] f = part.split(":");            int copies = Integer.parseInt(f[1]);            boolean critical = f[2].equals("yes");            if (critical && copies == 1) {                found.add(f[0]);            }        }        return found;    }
    public static void main(String[] args) {        String a = "load balancer:1:yes, app:2:yes, MySQL:1:yes";        String b = "load balancer:2:yes, app:3:yes, cache:1:no, MySQL:2:yes";        String c = "load balancer:2:yes, app:3:yes, MySQL:2:yes, payment gateway:1:yes";
        System.out.println("A: " + spofs(a));        System.out.println("B: " + spofs(b));        System.out.println("C: " + spofs(c));    }}
Output
A: [load balancer, MySQL]
B: []
C: [payment gateway]

What this code does

  • Each part is written name:copies:critical. A part is reported when it is critical and has one copy.
  • B has no SPOF because the cache is not critical. C has copies of everything it runs, but the outside payment gateway is still a single dependency.

Walk the request path from the user to the data and ask of every box: is it critical, and how many copies are there? Also check for two critical parts sharing one machine, and for outside services such as a payment gateway, which you cannot copy and can only plan around. Review: How systems grow (opens in a new tab)

Predict the output

Which design survives a crash?

Read the code and pick what it prints.

Which ShopLite design has no single point of failure?

A: [LB x2] --> [App x3] --> [MySQL x1]
B: [LB x1] --> [App x3] --> [MySQL primary + standby]
C: [LB x2] --> [App x3] --> [MySQL primary + standby]

Mistake 4: an answer with no structure

A weak answer jumps to tools. A strong one follows the six steps in order, in one or two sentences each, and ends with a trade-off.

Text
Weak:   "Microservices, Kafka and MongoDB, so it scales."Strong: Requirements: search, order, track.        Estimate: about 120 page views per second at peak.        API: GET /products, POST /orders, GET /orders/{id}.        Data: tables products, orders, order_items.        Design: [Phone] --> [App] --> [MySQL]        Trade-off: one app; gave up separate scaling; team of three.

Example 4 · A rough check for the six steps in an answer

AnswerScorer.javaJava
import java.util.ArrayList;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;
public class AnswerScorer {    // A very rough check: does the outline mention each of the six steps?    static final Map<String, String> STEP_WORDS = new LinkedHashMap<>();
    static {        STEP_WORDS.put("clarify", "requirement");        STEP_WORDS.put("estimate", "per second");        STEP_WORDS.put("API", "get /");        STEP_WORDS.put("data model", "table");        STEP_WORDS.put("high-level design", "-->");        STEP_WORDS.put("trade-off", "gave up");    }
    static List<String> missing(String answer) {        String lower = answer.toLowerCase();        List<String> gaps = new ArrayList<>();        for (Map.Entry<String, String> e : STEP_WORDS.entrySet()) {            if (!lower.contains(e.getValue())) {                gaps.add(e.getKey());            }        }        return gaps;    }
    public static void main(String[] args) {        String weak = "I will use microservices, Kafka and MongoDB --> it will scale.";        String strong = "Requirements: search, order, track. About 120 views per second at peak. "                + "GET /products, POST /orders. Tables: products, orders, order_items. "                + "[Phone] --> [App] --> [MySQL]. We chose one app; we gave up separate scaling.";
        List<String> w = missing(weak);        List<String> s = missing(strong);        System.out.println("Weak answer:   " + (6 - w.size()) + "/6, missing " + w);        System.out.println("Strong answer: " + (6 - s.size()) + "/6, missing " + s);    }}
Output
Weak answer:   1/6, missing [clarify, estimate, API, data model, trade-off]
Strong answer: 6/6, missing []

What this code does

  • missing looks for one marker word per step, such as "per second" for the estimate or "gave up" for a trade-off. It is a rough self-check, not a real grader.
  • The weak answer only has an arrow; the strong one mentions every step in five short sentences.

The example is a rough self-check: it looks for one marker phrase per step. Use the real six steps as your checklist in an interview. Review: Trade-offs and the interview approach (opens in a new tab)

Module quiz

Questions from the whole module. Your first answer is your score.

Problems

Graded easy to hard, using everything from this module.

Try each one yourself first. Use the hint if you get stuck. Mark it as done when it works.

Exercise 1· Easy

Label each requirement F (functional) or N (non-functional). One line each, like 1: F.

  1. Customer filters products by price range.
  2. Search results return in under 300 ms at p95.
  3. Customer cancels an order before it ships.
  4. Order data is backed up every night and kept 30 days.
  5. Admin sees a daily sales report.
  6. The site handles 20,000 users at once on sale day.
  7. Customer gets an SMS when the order ships.
  8. Servers cost under Rs 30,000 a month.
  9. Checkout is available 99.9% of each month.
  10. Customer saves up to 3 delivery addresses.
Expected output
1: F
2: N
3: F
4: N
5: F
6: N
7: F
8: N
9: N
10: F

Exercise 2· Easy

Print how many minutes of downtime 99.95% allows in a 7-day week and in a 30-day month, with one decimal, in the format shown.

Expected output
99.95% allows 5.0 min a week
99.95% allows 21.6 min a month

Exercise 3· Medium

Reuse pick from Example 2. A library catalogue can tolerate 900 minutes of downtime a month, ShopLite checkout 60 minutes, and an ambulance booking app 5 minutes. Print the target for each.

Expected output
Library catalogue: 99.0%
ShopLite checkout: 99.9%
Ambulance booking: 99.99%

Exercise 4· Medium

Name every single point of failure in each architecture, or write none. One line each.

  • A) [Phone] --> [one Nginx] --> [App x3] --> [MySQL primary + standby]
  • B) [Phone] --> [LB x2] --> [App x2] --> [one MySQL]; product photos on the same MySQL server
  • C) [Phone] --> [LB x2] --> [App x3] --> [MySQL primary + standby]; one SMS provider for OTP login
Expected output
A: Nginx (the only load balancer)
B: MySQL (one copy, and it also holds the photos)
C: the SMS provider: if it is down, nobody can log in with OTP

Exercise 5· Medium

ShopLite's checkout path is: load balancer (99.99%), two app servers in parallel (99.9% each), MySQL (99.95%) and an outside payment gateway (99.9%). Print the app tier availability, the whole path and the downtime per 30-day month.

Expected output
App tier (2 copies): 99.9999%
Checkout path:       99.840%
Downtime per month:  69 min

Exercise 6· Medium

Read the numbers and say which growth step ShopLite needs next, and why, in one or two sentences each.

  • a) 1 app server at 88% CPU, MySQL at 35%.
  • b) 4 app servers at 40%, MySQL at 90% CPU, mostly the same product queries.
  • c) Everything below 50%, but checkout p95 is 4 seconds because invoices are built inside the request.
Expected output
a: Add app servers behind a load balancer; the app CPU is the bottleneck and MySQL has room.
b: Cache the popular product reads (then read replicas if needed); more app servers would only push more load onto MySQL.
c: Move invoice building to a queue with a background worker; checkout should save the order and answer at once.

Exercise 7· Hard

Rewrite this weak answer using the six steps, one or two sentences per step, ending with a trade-off. Prompt: "Design an online exam portal for our college (3,000 students, exams start at 10 AM)." Weak answer: "I'd use microservices on Kubernetes with MongoDB and Kafka so it can scale to millions."

Expected output
Clarify: students log in, see the paper, answer MCQs and submit; staff create papers and see results; out of scope: video proctoring. NFR: no answer lost, save under 1 second.
Estimate: 3,000 students start at 10:00 and save an answer every 30 seconds, so about 100 saves a second during the exam.
API: GET /exams/{id}, PUT /exams/{id}/answers/{questionId}, POST /exams/{id}/submit.
Data model: exams, questions, students, answers (one row per student and question).
High level: [Browser] --> [Load balancer] --> [App x2] --> [MySQL primary + standby].
Deep dive: a student's browser losing the network mid-exam; answers are saved one by one, so on reconnect nothing is lost.
Trade-off: We chose one application and MySQL; we gave up scaling to millions; because 3,000 students need about 100 writes a second, which one database handles easily.

Exercise 8· Hard

Each part now records the machine it runs on. Print the single points of failure, then, for any machine that runs more than one of them, print which parts are lost together if it dies. Parts: Nginx (1 copy, critical, vm-1), MySQL (1, critical, vm-1), app (2, critical, vm-2,vm-3), Redis cache (1, not critical, vm-4).

Expected output
Single points of failure: [Nginx, MySQL]
If vm-1 dies, we lose [Nginx, MySQL] together

Interview questions

Questions interviewers ask on this topic.

Finish up

Mark complete & continue

Next: Project: ShopLite requirements and baseline architecture