AlgoViz

What an LLD interview tests

easy 40 min

A low-level design round gives you one vague sentence and about 45 minutes.

Video lesson · Chapter 1 of 6

Make a prediction

0:00 / 5:00

What an LLD interview tests

1:05Reel

Theory

Read or listen first. About 2 min.

What it is

A low-level design interview (LLD, also called object-oriented design) asks you to design the inside of one program: classes, what each class knows, what it does, and how the objects talk to each other. Often you write the main methods as real code.

The prompt is short on purpose: a parking lot, a chess game, a bike share station. Missing details are part of the test. So are the rules that nobody mentions, such as two people who want the last bike.

The program usually runs in one process and in memory. No servers, no load balancer, no database schema, unless the interviewer asks. That is the line to system design.

Why it exists

Most daily work is not a puzzle with a clever trick. It is a change to a program that other people also change. The round looks at exactly that: can you split a problem so that the next change stays small?

It also shows how you work with people. You ask, you decide, you say why, and you react when somebody finds a hole. A finished answer without reasons shows less than a smaller answer that you can defend.

Remembered solutions help only while the prompt is the remembered one. The first follow-up question ends that. A way of working fits a vending machine, a chess board and a control room alike, because all of them have things, owners, rules and states. The details still differ, and you must look at them.

A short history

  1. 1989

    Kent Beck and Ward Cunningham present CRC cards at OOPSLA: one paper card per class with its responsibilities and collaborators. It is still the fastest way to talk a design through.

  2. 1994

    Design Patterns by Gamma, Helm, Johnson and Vlissides gives names to 23 recurring designs. Interviewers and candidates use these names as a short language.

  3. 1997

    The Object Management Group adopts UML 1.1 in November. Class diagrams get one common notation.

Words to know

Prompt
The one or two sentences you get at the start.
Scope
What you agreed to build, and what you agreed to leave out.
Entity
A thing in the problem with its own identity or rules, such as a bike or a ride.
Responsibility
Something one class promises to know or to do.
Invariant
A statement that must always be true, such as: a bike has at most one rider.
Policy
A rule that is expected to vary, such as the price.
Lifecycle
The states a thing goes through, and the moves that are allowed.
Trace
Walking through your code by hand with concrete values.
Follow-up
A new requirement near the end, to see what your design does with it.

How it works

Step through the idea, or press Play.

Step 1 of 4

Ask. Turn one sentence into a short list

Understand it

Start here

A chair, please

Noor walks into the workshop of Sam, who builds furniture, and asks for a chair. What Sam does in the next minutes is the whole interview.

Sam, Noor and the chair
A chair, please.

Frame 2 is the most common way to fail: good work on the wrong chair.

The test

Five things they look at

The score sheet behind the questions

  • Scope

    Did you find the missing rules, and agree on what to leave out?

  • Owners

    Does every fact and every rule live in one class that you can name?

  • Correctness

    Does the code keep its invariants, also in the strange cases?

  • Change

    When a new rule arrives, how many classes do you open?

  • Talk

    Can a listener follow you, interrupt you and get a reason?

Companies use their own sheets and words. These five are our summary of what a design round can show at all. Ask your recruiter which format you will get.

Where each signal appears

Talk is not one step. It is the line between the two people.

The border

LLD is not system design

The same product, two rounds

Low-level designSystem design
UnitClasses and methodsServices, stores and queues
Runs onOne process, unless told otherwiseMany machines
Bike shareWho may start a ride? What happens at a full station?How do 10,000 stations report their state?
NumbersHow many threads, how many items in memoryRequests per second, bytes per day
Two at onceA lock around check and changeA transaction or a conditional write
ResultA class diagram and working codeAn architecture and its trade-offs
Typical missDrawing load balancersListing private fields

One sentence moves you to the right side: I assume one process and in-memory data, with several threads. Is that right? If they want a city-wide system, the round has changed, and you ask which part they want to see.

Which round am I in?

Formats

Four shapes of the round

FormatTypical lengthYou hand overSpend more onSpend less on
Talk and diagram35 to 60 minClasses, relations, method namesOwners, reasons, follow-upsSyntax
Design and code45 to 60 minA sketch and the main methodsThe core path, a traceGetters, menus, printing
Build and run60 to 120 minA program that runs, often with testsA small end-to-end version earlyRare patterns
Take homeHours to daysA repository with a READMETests, names, a short decision listExtra features
Lengths are typical, not a promise. Read the invitation and ask.

Two ways to prepare

Memorize forty answers, or learn one method

One way of working

  • One order of steps for every prompt
  • The same five questions find the parts
  • A variation changes one part
  • A step you practised often still works when you are nervous

Remembered solutions

  • Forty designs to keep alive
  • A new prompt leaves you with nothing
  • A follow-up does not fit the remembered picture
  • Under pressure the details are the first to go

Practice problems still matter. Solve them to train the method, then throw the solution away and solve them again with a changed rule.

The lens

Things, rules and states

Many LLD prompts share one shape. A container holds items. A manager takes the requests and keeps the two consistent. Some rules vary, and we call them policy. Some things go through states, and we call that lifecycle.

The common shape, on a bike share

Station- docks: int- bikes: Map<Id, Bike>+ put(bike)+ take(): Bike

1/5C: container

What holds things? A Station has a limited number of docks. The limit is a rule, so it needs an owner.

has (lives on)uses

Stations and bikes live on without each other, so the diamonds are hollow.

C.I.M.P.L., said like simple

  1. 1

    Container: what holds the resources?

    A board, a lot, a shelf, a map. Look for a capacity or a position.

  2. 2

    Item: what is the resource?

    A piece, a car, a book, a cache node. Look for identity.

  3. 3

    Manager: who takes the request?

    A controller, a game, a service. Look for a rule that spans several objects.

  4. 4

    Policy: what logic varies?

    Pricing, dispatch order, payment method, eviction. When you hear several ways to do X, think of Strategy, or of a plain value if only a number differs.

  5. 5

    Lifecycle: which states exist?

    Idle to active to complete, available to occupied, pending to processing to done. When behaviour changes with status, think of State. When only a check changes, an enum and a table are enough.

The bike's lifecycle

There is no arrow from Riding to Repair. A broken bike is docked first. If you want the arrow, that is a requirement to agree on.

The lens on two more prompts

LibraryFood delivery
ContainerShelf, sectionRestaurant menu
ItemBook copyDish, order
ManagerLending deskOrder service
PolicyLending rules: how long, how manyDelivery fee, discounts
LifecycleOn shelf, borrowed, returnedPlaced, cooking, on the way, delivered
NeitherA member is an actor, not a held itemA courier is an actor with an own lifecycle
More prompts with patterns and data structures: the master matrix. Practise the reading on the problem analyzer.

A weak answer

It runs, and it fails the round

Same prompt: people take a bike at one station and return it at another. Here is an answer that many write in the first five minutes. Read it as the interviewer does.

The weak shape: one class, no owners

BikeSystem+ bikes: Map<Id, List>+ capacity: Map<Id, int>+ action(kind, rider, station, bike, now)

1/2One class

BikeSystem has public maps and one method for everything. No class is called Ride, so nobody owns the rule: one rider per bike.

uses

What the interviewer sees

Short and quick to write. Each beat is a note on the score sheet.

class BikeSystem:    def __init__(self):        self.bikes = {}          # id -> [status, station, rider, start]        self.capacity = {}       # station -> docks    def action(self, kind, rider, station, bike, now):        b = self.bikes[bike]        if kind == "start":            b[0] = "riding"            b[2], b[3] = rider, now            return None        if kind == "finish":            minutes = now - b[3]            b[0], b[1] = "docked", station            return minutes * 20

Lines 3 to 4

Facts are stored as positions in a list. b[2] has no name, so a reader must remember that it is the rider. Public too: any caller can change it.

1 of 5

A strong answer

The same prompt with owners

Agreed scope: take a bike at a station, return it at any station with a free dock, pay by the minute after a free time, one ride per rider, several screens at once. Out: payment, reservations, maps.

Bike share, from the item upwards

Start with the class that depends on nothing. It can be read and tested alone.

from dataclasses import dataclassfrom enum import Enumfrom threading import Lockfrom typing import Protocolclass BikeState(Enum):    DOCKED = "docked"    RIDING = "riding"    REPAIR = "repair"class Refused(Exception):    """A rule said no. The caller can show the reason."""_NEXT = {    BikeState.DOCKED: {BikeState.RIDING, BikeState.REPAIR},    BikeState.RIDING: {BikeState.DOCKED},    BikeState.REPAIR: {BikeState.DOCKED},}class Bike:    def __init__(self, bike_id: str):        self.id = bike_id        self._state = BikeState.DOCKED    @property    def state(self) -> BikeState:        return self._state    def move_to(self, new: BikeState) -> None:        if new not in _NEXT[self._state]:            raise Refused(f"{self.id}: {self._state.value} to {new.value}")        self._state = new

Lines 7 to 10

Three states with names. A wrong state is now a typo that fails, not a silent string.

1 of 5

A refused return

30 minutes, 10 free, 20 cents each: 400 cents. Time for the detour would be added.

The interviewer asks: now we sell a day pass. What do you change?

BreaksA flag in finish
How
finish(..., has_pass) with a branch for the fee.
Limit
Every screen must know about passes, and the next offer is another flag.
Choose when
Never.
WorksA second PricingRule chosen per rider
How
The service asks a PricingBook for the rule of this rider.
Limit
One more class. The choice must be made at the start of the ride, or a pass that ends during it changes the price.
Choose when
Two or three offers.
StrongThe ride keeps its rule
How
start picks the rule and stores it in Ride. finish asks ride.pricing. New offers are new rules.
Limit
The ride gets one more field, so old rides need a default.
Choose when
Prices that change over time. You also say what stays: bike, station, lock.

Scoring

How the notes become a result

Four signals, weak to strong

SignalWeakEnoughStrong
ScopeStarts at onceAsks, writes a listFinds the rule that decides the design, and cuts scope aloud
OwnersOne class or thirtyEach class has one jobCan say for every rule who keeps it, and which nouns were rejected
CorrectnessHappy path onlyHandles refusalsNames invariants, traces a race, fixes a bug alone
ChangeRewriteOne class and some editsShows the lines that stay, and refuses abstractions nobody needs
TalkSilent or a speechExplains choicesGives reason and cost, and uses hints at once
What is expected at which level: junior, mid and senior answers.

A bug is not a fail. A bug that you find in your own trace is often a plus. A hint is not a fail either. A hint that you argue away without thinking is.

The same minute, two candidates

  1. Interviewer

    Two people tap start at the last bike at the same moment.

  2. You

    Weak: that will probably never happen. Strong: good case. start holds the lock while it takes the bike and records the ride. The second call finds no bike and gets a refusal. Let me trace it with one bike and two riders.

  3. Interviewer

    Would you put the lock into the bike?

  4. You

    A lock in the bike protects one bike. My rule is about a rider, a bike and a station together, so the lock belongs to the class that sees all three.

Where the points leak

Plan

How to prepare with this course

  1. 1

    Learn the order

    The 5-step execution flow gives you a clock. Practise with a real timer.

  2. 2
  3. 3

    Know few patterns well

    Strategy, State, Observer, Factory and Decorator cover much. Learn when not to use each.

  4. 4

    Solve, change, solve again

    Take parking lot. Next day solve it again with one changed rule.

  5. 5

    Talk aloud

    Record five minutes. If you cannot hear a reason after a decision, add the word because.

Summary

The whole topic in one minute.

The round scores five things: agreed scope, clear owners, correct code, a design that takes change, and talk that another person can follow.

C.I.M.P.L. is a way to look at a prompt: container, item, manager, policy, lifecycle. It finds candidates for classes. Your requirements decide which of them stay.

  • One vague sentence, about 45 minutes, one process: classes, code, proof, change.
  • Five signals: scope, owners, correctness, change, talk.
  • C.I.M.P.L. finds candidates: container, item, manager, policy, lifecycle.
  • Policy can be a value, lifecycle can be an enum. Patterns must earn their place.
  • Say each invariant and name the class that keeps it.
  • Check and change under one lock, or say that there is one thread.
  • A found bug and a used hint are good signs.

Sources