Skip to lesson

What system design is (and is not)

ShopLite works for your friends. Then someone asks: "Will it survive the college fest sale?" Nobody can answer, because nobody wrote down what it must do or how well it must do it.

System design: the view from far away

System design is choosing the big parts of a software system, how they talk to each other and how they keep working as users grow, using written requirements and numbers.

Stage 5 is about ShopLite growing up. To plan that, first look at it from far away: boxes and arrows, not classes.

Text
High-level design (boxes and arrows):  [Customer's phone] --HTTPS--> [ShopLite server] --SQL--> [(MySQL database)]Low-level design (classes inside one box):  ShopLite server:  OrderController -> OrderService -> OrderRepository

High-level design (HLD) shows the boxes and the data flowing between them, at a given scale. Low-level design (LLD) zooms into one box and shows its classes, methods and patterns. Section 19 was low-level design: OrderService and the Strategy pattern. Here the questions are how many servers, where the data lives and what happens when one part fails.

In this course a diagram-in-words stands for the boxes you would draw on a whiteboard. [Name] is a running program ([Name x3] means three copies), [(Name)] is a data store and [[Name]] is a queue; in a quick sketch a plain [MySQL] is fine. A --> B means A calls B and waits for the answer, A ..> B means A hands work off and does not wait, and a label inside an arrow (--SQL-->) says what is sent. Every later module uses this notation; the lesson on drawing architecture diagrams in the last module practises it.

Functional requirements: what the system does

Functional requirement is one thing a user can do with the system, written as "who does what", such as "a customer places an order". Together the functional requirements define the features.

Start with the features. For ShopLite version 1 the list is short, and every line says who does what.

Example 1 · ShopLite functional requirements with a scope list

FunctionalRequirementsDemo.javaJava
import java.util.List;
record Feature(String id, String actor, String action, boolean inScope) {}
public class FunctionalRequirementsDemo {    public static void main(String[] args) {        List<Feature> features = List.of(                new Feature("FR1", "Customer", "browses products by category and searches by name", true),                new Feature("FR2", "Customer", "places an order for the products in the cart", true),                new Feature("FR3", "Customer", "tracks an order: PLACED, SHIPPED, DELIVERED", true),                new Feature("FR4", "Admin", "adds products and changes price and stock", true),                new Feature("-", "Customer", "writes product reviews with photos", false),                new Feature("-", "Seller", "lists their own products (marketplace)", false));
        System.out.println("In scope for version 1:");        for (Feature f : features) {            if (f.inScope()) {                System.out.println("  " + f.id() + ": " + f.actor() + " " + f.action());            }        }
        System.out.println("Out of scope for now:");        for (Feature f : features) {            if (!f.inScope()) {                System.out.println("  " + f.actor() + " " + f.action());            }        }    }}
Output
In scope for version 1:
  FR1: Customer browses products by category and searches by name
  FR2: Customer places an order for the products in the cart
  FR3: Customer tracks an order: PLACED, SHIPPED, DELIVERED
  FR4: Admin adds products and changes price and stock
Out of scope for now:
  Customer writes product reviews with photos
  Seller lists their own products (marketplace)

What this code does

  • Each Feature is one "who does what" line. The inScope flag splits version 1 from later ideas, so the list doubles as a scope agreement.
  • Reviews and a seller marketplace are real features, but leaving them out keeps the first design small enough to finish and explain.

An out of scope list is just as useful: it tells everyone, including an interviewer, what you are deliberately not building today. Written down, it is a promise that version 1 will be finished.

Common mistake: writing "the site is fast" in this list. Speed is a quality of the whole system, not a feature. It belongs in the next section.

Non-functional requirements: how well it must work

Non-functional requirement (NFR) is a quality of the whole system, such as how fast, how reliable or how big, written with a number you can check. Two shops can have the same features and very different NFRs.

Features say what ShopLite does. Qualities say how well. Each line in the example names one quality and a target.

Example 2 · ShopLite NFRs, each with a target

NonFunctionalDemo.javaJava
import java.util.List;
record Quality(String name, String target) {}
public class NonFunctionalDemo {    public static void main(String[] args) {        List<Quality> qualities = List.of(                new Quality("Latency", "product page answers in under 300 ms for 95% of requests"),                new Quality("Availability", "checkout works 99.9% of the time in a month"),                new Quality("Consistency", "stock never goes below 0; a paid order is never shown as unpaid"),                new Quality("Scalability", "handles 10x normal traffic on sale day by adding servers"),                new Quality("Durability", "a confirmed order is never lost; daily backups kept 30 days"),                new Quality("Cost", "servers cost under Rs 20,000 a month in year 1"));
        System.out.println("ShopLite non-functional requirements");        for (Quality q : qualities) {            System.out.printf("  %-13s %s%n", q.name(), q.target());        }    }}
Output
ShopLite non-functional requirements
  Latency       product page answers in under 300 ms for 95% of requests
  Availability  checkout works 99.9% of the time in a month
  Consistency   stock never goes below 0; a paid order is never shown as unpaid
  Scalability   handles 10x normal traffic on sale day by adding servers
  Durability    a confirmed order is never lost; daily backups kept 30 days
  Cost          servers cost under Rs 20,000 a month in year 1

What this code does

  • Every line names a quality and a target you can measure or check, such as 300 ms, 99.9% or Rs 20,000.
  • Notice that none of these is a feature. The same four features could have a target of 3 seconds or 300 ms, and that choice changes the design.

Six qualities come up again and again:

  • Latency: how long one request takes. Availability: the share of time the system works.
  • Consistency: every user sees correct, agreed data. Durability: saved data is never lost.
  • Scalability: more users handled by adding resources. Cost: the monthly bill.

Find the bug

Find the requirement nobody can check

Tap the line that has no number to check.

ShopLite's quality targets. Which line cannot be checked?

Round 1 of 3

Your turn: from "design a shop" to numbers

ShopLite's owner says only: "Make it ready for the fest sale." That is the whole prompt. Before you read on, write your own answers on paper:

  • Who uses it and what can they do? List three features and one you will leave out.
  • How well must it work? Give latency, availability and scale a number each.
  • How many users? If nobody tells you, which number will you assume, and how many page views a second does it give?
Take two minutes. A rough answer on paper is worth more than a perfect one kept in your head. The next section shows one good answer to compare with.

One good answer: numbers first, then a simple design

Compare with your list. A good answer asks first, writes numbers down, and only then draws boxes, each with a reason.

Text
Weak:   "I will use microservices, Kafka and Redis so it scales."Strong: "First the requirements: browse, order, track. I'll assume         1 lakh users a day, so about 115 page views a second at peak.         One server plus MySQL handles that. I'd add a cache for         product pages later; the cost is data that can be a few         seconds old."

For a fresher, an interviewer does not check that you know every tool. They watch how you think: do you ask before drawing, state numbers, and explain what each box costs? Names like Kafka or Kubernetes with no reason count against you.

Example 3 · Spotting vague requirements that have no number

VagueRequirementCheck.javaJava
import java.util.List;
public class VagueRequirementCheck {    static final List<String> VAGUE_WORDS = List.of("fast", "scalable", "always", "many", "quick", "secure");
    static boolean hasNumber(String text) {        for (char c : text.toCharArray()) {            if (Character.isDigit(c)) {                return true;            }        }        return false;    }
    static String check(String requirement) {        String lower = requirement.toLowerCase();        for (String word : VAGUE_WORDS) {            if (lower.contains(word) && !hasNumber(requirement)) {                return "VAGUE: \"" + word + "\" with no number";            }        }        return "OK";    }
    public static void main(String[] args) {        List<String> requirements = List.of(                "The site should be fast",                "Product page loads in under 300 ms for 95% of requests",                "The system must be scalable",                "Take 2,000 orders per minute on sale day",                "It should always be up",                "Checkout is available 99.9% of each month");
        for (String r : requirements) {            System.out.printf("%-56s %s%n", r, check(r));        }    }}
Output
The site should be fast                                  VAGUE: "fast" with no number
Product page loads in under 300 ms for 95% of requests   OK
The system must be scalable                              VAGUE: "scalable" with no number
Take 2,000 orders per minute on sale day                 OK
It should always be up                                   VAGUE: "always" with no number
Checkout is available 99.9% of each month                OK

What this code does

  • check flags a requirement that uses a word like "fast" or "always" but contains no digit. Those are the lines an interviewer will push back on.
  • The fixed versions say exactly what "fast" or "available" means, so you can later check whether a design meets them.

Example 4 · Turning "design a shop" into numbers

ShopNumbersDemo.javaJava
public class ShopNumbersDemo {    public static void main(String[] args) {        // Assumptions, written down and said aloud in the interview        long dailyUsers = 100_000;        double buyerShare = 0.05;      // 5 in 100 visitors place one order        int pagesPerUser = 20;        int peakFactor = 5;            // busiest hour vs the daily average        long secondsPerDay = 86_400;
        long ordersPerDay = Math.round(dailyUsers * buyerShare);        long viewsPerDay = dailyUsers * pagesPerUser;        double ordersPerSecond = (double) ordersPerDay / secondsPerDay;        double viewsPerSecond = (double) viewsPerDay / secondsPerDay;
        System.out.println("Orders per day:     " + ordersPerDay);        System.out.println("Page views per day: " + viewsPerDay);        System.out.printf("Orders per second:  %.2f on average%n", ordersPerSecond);        System.out.printf("Views per second:   %.1f on average, %.1f at peak%n",                viewsPerSecond, viewsPerSecond * peakFactor);        System.out.println("Reads per write:    " + viewsPerDay / ordersPerDay + " page views per order");    }}
Output
Orders per day:     5000
Page views per day: 2000000
Orders per second:  0.06 on average
Views per second:   23.1 on average, 115.7 at peak
Reads per write:    400 page views per order

What this code does

  • Four written assumptions give the size of the problem: about 116 page views a second at the busiest hour and fewer than one order a second on average.
  • The last line is the most useful: 400 reads for every write. A system that is read far more than written points the design towards fast reads, which later modules build on.

Check your own answer against the two examples: did "fast" get a number, and did you say your assumptions aloud, such as 1 lakh daily users? When the interviewer gives no number, a stated assumption lets them correct you and keeps the design concrete.

Predict the output

Which answer, which number?

Read the code and pick what it prints.

Round 1 of 2

Two openings for "Design a shop". Which one would an interviewer rate higher?

A: "I'll use microservices, Kafka and Redis so it scales."
B: "First the features and the numbers: browse, order, track,
about 1 lakh users a day. Then I'll draw the boxes."

Next step

Check your understanding

10 quick questions