Start here · Intro

What is low-level design?

What low-level design is, how it differs from system design, the two kinds of LLD interview (OOD discussion and machine coding), and how this course is laid out.

BeginnerInterview priority: High45 min
On this page
  1. The problem: code that works on day one and fights you on day ninety
  2. The idea: zoom into one box and design the classes inside
  3. The same checkout, designed
  4. LLD and system design: two zoom levels
  5. The kinds of LLD interview
  6. A method you can repeat in every round
  7. How this course is organised
  8. Where this breaks
  9. When a little design is enough
  10. In the interview
  11. Quiz

The problem: code that works on day one and fights you on day ninety

A small online shop writes its checkout in one class. OrderManager adds up the cart, charges the card, emails a receipt and updates stock. It is 200 lines, it works, and it ships.

Then the change requests arrive. "Add PayPal." "Also send an SMS." "Students get 10% off." "The tax rate changed." Each one is a few lines, and each one goes into the same class, because that is where everything lives:

void checkout(String paymentType) {
    double total = calcTotal();
    if (isStudent) total = total * 0.9;           // added in March
    if (paymentType.equals("card")) {
        // 40 lines of card code
    } else if (paymentType.equals("paypal")) {    // added in April
        // 40 lines of PayPal code
    }
    sendEmail(customer);
    if (wantsSms) sendSms(customer);              // added in May
    updateStock(items);
}

Three months later the class is 400 lines. Every change means reading most of it to find the right spot, every change risks breaking a feature that has nothing to do with it, and two developers working on two features edit the same file and collide.

One giant class: every change edits it

  1. Any design works on day one. The real test is change. Your boss says: “add PayPal”. If one giant class does everything, you must open it, read hundreds of lines, edit them, and hope nothing else breaks.

Nothing here is a bug. The code does what it should. The problem is shape: how the code is split up decides how expensive every future change is. Deciding that shape on purpose is low-level design.

The idea: zoom into one box and design the classes inside

In system design you draw boxes: phones, load balancers, an order service, a database. Low-level design (LLD) zooms into one of those boxes and asks how the code inside it should be organised.

Low-level design zooms into one box

  1. In system design you drew big boxes: phones, servers, databases. Low-level design zooms into one of those boxes and asks a different question: how should the code inside be organised?

Inside, object-oriented code is made of classes. A class bundles some data (its fields) with the things it can do (its methods). At run time the program creates objects from those classes, and the objects work by calling each other's methods. An interface is a promise of which methods a class has, without saying how they work.

Classes hold data and behaviour, and call each other

  1. Inside, the code is split into classes. A class is a small machine with its own data, called fields, and things it can do, called methods.
  2. Classes work together by calling each other’s methods. You can picture each call as a little message: Order asks Payment to take 42 dollars, then asks Email to send a receipt.

So an LLD answer is a set of decisions:

  • Which classes exist, and what each one is responsible for.
  • What each class knows (its fields) and what it can do (its public methods).
  • How they relate: who holds a reference to whom, who creates whom, what is shared.
  • Where the seams are: which parts are likely to change, and the interfaces that let them change without disturbing the rest.

What "good" means

Any design works on the day it is written. A good one keeps working as requirements change. Four properties to aim for:

PropertyThe question to askSign it is missing
Easy to changeDoes a new requirement touch one or two small places?Every feature edits the same big class
Easy to testCan I test the price maths without a real card or email server?Tests need a database and a network to run
Easy to understandCan a newcomer guess where a feature lives from the class names?Names like Manager, Helper, Utils that hold everything
Correct under concurrencyWhat happens if two requests touch the same object at once?Two cars are given the last parking spot

Two words you will hear in every LLD discussion describe the first three:

  • Cohesion: how closely the contents of one class belong together. High cohesion means a class has one clear job. PriceCalculator is cohesive; OrderManager above is not.
  • Coupling: how much one class depends on the details of another. Low coupling means you can change one class without editing its neighbours.

The target is always high cohesion, low coupling. Most of this course (encapsulation, interfaces, SOLID, the design patterns) is a collection of techniques for getting there.

The same checkout, designed

Here is the shop again, split into small classes. Each thing that is likely to vary (how we take payment, how we notify, which discounts apply) sits behind a small interface. CheckoutService coordinates the steps but knows none of the details.

The good design: PayPal is one new class

  1. In a good design the same change touches one small place, often just one brand-new class. Nothing that already works gets edited, so nothing that already works can break.
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

// What varies sits behind small interfaces
interface PaymentMethod { void pay(BigDecimal amount); }
interface Notifier { void send(String to, String text); }
interface DiscountRule { BigDecimal apply(BigDecimal subtotal); }

record Item(String name, BigDecimal price, int qty) {
    BigDecimal lineTotal() { return price.multiply(BigDecimal.valueOf(qty)); }
}

class Order {
    private final String customerEmail;
    private final List<Item> items = new ArrayList<>();

    Order(String customerEmail) { this.customerEmail = customerEmail; }
    void addItem(Item item) { items.add(item); }
    List<Item> items() { return List.copyOf(items); }
    String customerEmail() { return customerEmail; }
}

// One job: work out what the customer owes
class PriceCalculator {
    private final BigDecimal taxRate;
    private final List<DiscountRule> rules;

    PriceCalculator(BigDecimal taxRate, List<DiscountRule> rules) {
        this.taxRate = taxRate;
        this.rules = List.copyOf(rules);
    }

    BigDecimal total(List<Item> items) {
        BigDecimal sum = BigDecimal.ZERO;
        for (Item i : items) sum = sum.add(i.lineTotal());
        for (DiscountRule r : rules) sum = r.apply(sum);
        return sum.multiply(BigDecimal.ONE.add(taxRate)).setScale(2, RoundingMode.HALF_UP);
    }
}

class CardPayment implements PaymentMethod {
    private final String cardToken;
    CardPayment(String cardToken) { this.cardToken = cardToken; }
    public void pay(BigDecimal amount) { System.out.println("Card " + cardToken + " charged " + amount); }
}

class EmailNotifier implements Notifier {
    public void send(String to, String text) { System.out.println("Email to " + to + ": " + text); }
}

// Coordinates the steps; knows none of the details
class CheckoutService {
    private final PriceCalculator prices;
    private final PaymentMethod payment;
    private final Notifier notifier;

    CheckoutService(PriceCalculator prices, PaymentMethod payment, Notifier notifier) {
        this.prices = prices;
        this.payment = payment;
        this.notifier = notifier;
    }

    BigDecimal checkout(Order order) {
        BigDecimal total = prices.total(order.items());
        payment.pay(total);
        notifier.send(order.customerEmail(), "Thanks! You paid " + total);
        return total;
    }
}

// Change requests arrive as new classes
class PayPalPayment implements PaymentMethod {
    private final String account;
    PayPalPayment(String account) { this.account = account; }
    public void pay(BigDecimal amount) { System.out.println("PayPal " + account + " charged " + amount); }
}

class StudentDiscount implements DiscountRule {
    public BigDecimal apply(BigDecimal subtotal) { return subtotal.multiply(new BigDecimal("0.90")); }
}

public class Main {
    public static void main(String[] args) {
        Order order = new Order("asha@example.com");
        order.addItem(new Item("Notebook", new BigDecimal("4.50"), 2));
        order.addItem(new Item("Pen", new BigDecimal("1.25"), 4));

        PriceCalculator prices = new PriceCalculator(new BigDecimal("0.18"), List.of());
        new CheckoutService(prices, new CardPayment("tok_42"), new EmailNotifier()).checkout(order);
        // Card tok_42 charged 16.52

        // "Add PayPal" and "10% student discount": two new classes, plus this wiring
        PriceCalculator studentPrices = new PriceCalculator(new BigDecimal("0.18"), List.of(new StudentDiscount()));
        new CheckoutService(studentPrices, new PayPalPayment("asha@pp"), new EmailNotifier()).checkout(order);
        // PayPal asha@pp charged 14.87
    }
}

Counting the cost of the four change requests

The worked example: ship the same four requests against each design and count what you touch.

Change requestOne giant classSmall classes
Add PayPalEdit OrderManager (new branch)New PayPalPayment; one wiring line
Also send an SMSEdit OrderManagerNew SmsNotifier; one wiring line
10% student discountEdit OrderManagerNew StudentDiscount; one wiring line
Change the tax rateEdit OrderManagerChange one configuration value
Old classes edited4 edits to the same 400-line class0 (only the setup code that builds the objects)
Re-testEverything in checkout, four timesThe new class, plus one end-to-end test

Notice the honest detail in the right-hand column: something still changes, namely the place where objects are created and plugged together (often called the composition root: main, a factory, or a dependency-injection container). Good design does not make change free. It moves change to small, predictable places.

LLD and system design: two zoom levels

Both are "design", but they answer different questions with different tools. Interviewers expect you to stay at the right level.

System design (HLD)Low-level design (LLD)
The questionWhich machines and services, and how does data flow between them?Which classes inside one program, and how do they collaborate?
Building blocksServices, databases, caches, queues, load balancersClasses, interfaces, enums, methods, design patterns
Drawn asBoxes and arrows between serversClass diagrams, sequence diagrams, state diagrams
Worries aboutScale, latency, availability, consistency across machinesResponsibilities, coupling, extensibility, thread safety inside one process
NumbersRequests per second, terabytes, millisecondsRarely; occasionally time complexity of a key method
Typical prompt"Design WhatsApp""Design a parking lot", "Implement an LRU cache"
OutputA diagram and a spoken justificationA class design, and often working code

The boundary is not sharp. A parking lot LLD still asks "what if two gates assign the same spot?", which is a concurrency question; a WhatsApp HLD still has an API, which is an interface. A useful rule: if the answer involves a network hop, it is HLD; if it lives inside one process, it is LLD.

The kinds of LLD interview

"LLD round" means different things at different companies. Ask the recruiter which one you are getting, because they reward different things.

FormatLengthWhat you produceWhat they grade
Object-oriented design (OOD) discussion45–60 minRequirements, a class diagram on a whiteboard, the key method signatures, maybe one method in codeClear entities and responsibilities, sensible relationships, how the design absorbs a new requirement
Machine coding60–120 min (90 is common)A working program in an IDE, usually in-memory, with a small driver or tests that you run and demoCode that runs; clean separation; extensibility when they add a requirement midway; naming; error handling
Component implementation30–60 minOne self-contained class with real logic: an LRU cache, a rate limiter, a thread-safe counterCorrectness, complexity, edge cases, thread safety
Refactoring / code review30–60 minImprovements to a messy piece of code you are givenSpotting smells, naming the principle each one breaks, changing it safely

Machine coding rounds are especially common at Indian product companies (Flipkart, Swiggy, Razorpay and many others run them), and are also used elsewhere under names like "pair programming" or "practical coding". Typical problems: parking lot, Splitwise, snake and ladder, elevator, vending machine, a library system, a rate limiter, a ride-sharing matcher.

A method you can repeat in every round

The same five steps work for an OOD discussion and for machine coding; only the time spent on each changes.

StepWhat you doOOD discussion (45 min)Machine coding (90 min)
1. ClarifyAsk about scope, actors, rules and what is out of scope; write the agreed list5 min5–10 min
2. EntitiesNouns in the requirements become candidate classes; verbs become methods5 min5 min
3. RelationshipsWho has whom, who creates whom; sketch a class diagram10 min5–10 min
4. SeamsFor each thing that will vary, an interface (often a known pattern)10 min5 min
5. Build and stressCode the core flow end to end, then concurrency and extensions15 min (walk through, code one method)60 min (code, run, demo, extend)

Step 2 in practice: nouns and verbs

Take one requirement: "A parking lot has several floors. Each floor has spots for motorbikes, cars and trucks. A vehicle enters, gets a ticket and parks in a free spot of its size. On exit the driver pays by the hour."

  • Nouns: parking lot, floor, spot, vehicle, ticket, driver, payment, hour.
  • Verbs: enter, issue ticket, park, find free spot, exit, pay, calculate fee.

Then filter. "Hour" is a value, not a class. "Driver" carries no behaviour we need, so drop it. Spot sizes and vehicle types are a fixed set, so they become an enum (a type with a fixed list of named values, like SpotSize.SMALL). "Pay by the hour" is a rule that will obviously change (weekend rates, flat fees), so it goes behind an interface such as PricingStrategy (the Strategy pattern). The result is a first cut: ParkingLot, Floor, Spot, Vehicle, Ticket, SpotSize (enum), PricingStrategy. The full answer is in Design a parking lot.

How this course is organised

The course builds from single objects up to complete designs. Each chapter has this reading page plus an interactive version you can play with.

The road map: objects, SOLID, patterns, full designs

  1. That is what this course is about: code that is easy to change, test and understand. We’ll learn objects, the five SOLID rules, fourteen classic design patterns, and then design real things like a parking lot and an elevator, favourite interview questions.
PartLessonsYou will be able to
Object-oriented basicsClasses and objects, Encapsulation, Inheritance vs composition, Interfaces and polymorphism, Class diagrams, SOLID principlesModel a problem as classes, protect their rules, and explain your choices with a diagram
Patterns for creating objectsSingleton, Factory, BuilderControl how and where objects are made
Patterns for structureAdapter, Decorator, Facade, Proxy, CompositeFit classes together and wrap them without rewriting
Patterns for behaviourStrategy, Observer, Command, State, Template method, Chain of responsibilitySwap, notify, queue and sequence behaviour
Design it yourselfParking lot, vending machine, elevator, movie ticket booking, and moreRun a full machine coding or OOD round

Code is in Java and Python throughout. Java is the most common language in LLD rounds and its types make designs explicit; Python shows the same ideas with less ceremony. Use whichever you will interview in.

Where this breaks

When a little design is enough

LLD effort should match the life expectancy of the code:

  • Scripts and one-off jobs: a 50-line data migration that runs once needs clear names, not interfaces.
  • Prototypes: when you are still discovering what the product is, rewriting is cheaper than designing.
  • Framework-shaped CRUD: a typical create-read-update-delete endpoint in Spring or Django already has a structure (controller, service, repository). Follow it rather than inventing your own.

Design pays off when code will be changed by several people over months, which describes most production code and every interview problem.

In the interview

Your turn: find the classes

Requirement: "A library lends books to members. A book can have several copies. A member may borrow at most five copies at once, for 14 days. Late returns are fined 10 cents per day. Librarians can add books and see overdue loans." Write the nouns and verbs, filter them, and list your classes with one responsibility each. Which rule is most likely to change?

Compare with our answer
  • Nouns: library, book, copy, member, loan, day, fine, librarian.
  • Verbs: lend (borrow), return, add book, list overdue, calculate fine.
  • Filter: "day" is a value; "fine" is an amount computed from a loan, not a stored thing (or a small value). Book and copy are different: a Book is the title (ISBN, author), a BookCopy is the physical item that is lent.
  • Classes: Book (title data), BookCopy (one physical copy, available or not), Member (identity, current loans), Loan (which copy, which member, due date, returned date), Library or LendingService (borrow and return, enforcing the five-loan limit), FinePolicy (an interface: 10 cents a day today).
  • Most likely to change: the fine and the loan limits, so put them in a policy object rather than hard-coding them in Loan.

A strong answer mentions: Book vs BookCopy as separate classes · Loan as its own class linking member and copy · the five-loan rule enforced in one place · fine calculation behind an interface or policy · "day" and "fine" as values, not classes · librarian as a role or permission rather than a separate class hierarchy.

Your turn: the requirement changes

A team's NotificationManager has sendEmail(), sendSms() and sendPush(), and a notify(user, type) method with a three-way if/else. Product now wants WhatsApp messages, and users should be able to choose more than one channel. What is wrong with the current shape, and what would you change?

Compare with our answer
  • Every new channel edits NotificationManager and its if/else, so the class has many reasons to change (low cohesion) and the chain grows forever.
  • Extract a Channel interface with send(user, message); one class per channel (EmailChannel, SmsChannel, PushChannel, WhatsAppChannel).
  • The notifier holds a list of channels per user (from their preferences) and loops over it, so "more than one channel" needs no new branches.
  • Channel choice is built in one place (a map from name to channel), not scattered through the code.
  • Failure handling: one channel failing (SMS gateway down) should not stop the others; catch per channel and log or retry.

A strong answer mentions: one interface for channels · one class per channel · a list of channels instead of a type switch · choice kept in one place · independent failure per channel.

Low-level design on one page
  • LLD = the classes inside one program: responsibilities, relationships, interfaces. HLD = the services and machines between programs.
  • Goal: easy to change, test and understand, and correct under concurrency. High cohesion, low coupling.
  • Interview formats: OOD discussion (diagram + key methods), machine coding (running code in 60–120 min), component implementation (LRU, rate limiter), refactoring.
  • Method: clarify → nouns and verbs → relationships → interfaces for what varies → build the core flow → concurrency and extensions.
  • Nouns become classes only if they have behaviour or identity; values become fields or enums.
  • Change should land as a new class plus wiring in the composition root, not as edits to working classes.
  • Don't over-engineer: abstract what is named as variable; get one flow running first.
  • Always ready: "what if two requests hit this at once?" and "how would you test it?"
Interactive labPractise it: ship four change requests against both designsOpens in the ByteAtlas lab. Your progress is saved in this browser.
Check what stuck

1. In a design review, which of these questions belongs to low-level design rather than system design?

2. You have 90 minutes in a machine coding round to build a Splitwise-style expense sharer. What should you aim to have by the end?

3. Changing the wording of the receipt email forces a team to re-test card payments, because both live in one class. What does this point to?

4. A well-designed checkout needs to accept PayPal. What should the change look like?

5. From "members borrow copies of books, at most five at a time", which first cut of classes is strongest?

6. A candidate spends 70 minutes of a 90-minute round building interfaces, factories and builders, and has no running code. What was the core mistake?

7. During an OOD discussion of a parking lot the interviewer asks: "Two gates call findFreeSpot() at the same moment. What happens?" What are they checking?

Score 60% or more and the lesson is marked complete.

Passing the quiz also marks it complete. Progress is saved in this browser only.