
Low-Level Design Interviews: Modeling a System in Code
A low-level design interview (also called object-oriented design or machine coding) asks you to turn a small real-world system into classes, interfaces and working code: a parking lot, a vending machine, an elevator, a library checkout. It shows up most for software engineering roles at companies with large, long-lived codebases, often at mid level and above. This lesson gives you a repeatable flow, the principles and patterns that matter, and a worked parking lot you can reuse as a template.
SmartIntervu does not have a dedicated low-level design format yet. The closest practice today is a coding interview where the data-structure design is most of the work, linked at the end.
What the interviewer is judging
Scale and servers are not the point here. The interviewer wants to see whether your code would survive the next six months of feature requests. In practice they look for:
Clear requirements: you pin down what the system must do before modeling it, and you say what you are leaving out.
Good boundaries: each class has one job, and you can say what that job is in a sentence.
Extensibility: adding a new vehicle type or pricing rule means adding code, not editing ten places.
Working core code: not every class, but the central flow, written cleanly enough to run.
Communication: you explain why a class exists and why the arrows point the way they do.
The flow
Most low-level design rounds run 45 to 60 minutes. Work in this order and say each step out loud.
Clarify (5 minutes). Ask what the system must do, who uses it, and what is out of scope. Write the agreed use cases as a short list.
Find the entities (5 minutes). Underline the nouns in the use cases: vehicle, spot, ticket, gate, payment. Drop the ones that are only attributes (a color is not a class).
Assign responsibilities (5 minutes). For each entity, one sentence: what does it know, and what does it do? If the sentence needs "and" twice, split the class.
Draw relationships (5 minutes). Which classes own others, which only use them, and where an interface should sit between two classes so either side can change.
Define interfaces (5 to 10 minutes). Write the method signatures for the core flow before any bodies.
Code the core (15 to 20 minutes). Implement the main use case end to end. Leave secondary classes as signatures.
Extend (remaining time). The interviewer will add a requirement. Show that your design absorbs it with a new class rather than a rewrite.
SOLID, by what each principle prevents
Reciting the acronym earns nothing. Knowing what goes wrong without each principle does.
Single responsibility prevents the class that changes for every reason. If
ParkingLotcomputes fees, assigns spots and prints receipts, every pricing change risks breaking spot assignment.Open/closed prevents the growing
switchon type. Adding an electric-vehicle rate should mean a new class, not anothercasein a fee function that every test depends on.Liskov substitution prevents subclasses that break their parent's promises. If
CompactSpot extends Spotbut throws onfits(vehicle)for motorcycles, code written againstSpotbreaks.Interface segregation prevents classes forced to implement methods they cannot support. A
PaymentMethodinterface withrefund()forces cash payments to fake it; split refundable methods out.Dependency inversion prevents high-level logic from being welded to one implementation. The lot should depend on a
PricingStrategyinterface, not onHourlyPricingdirectly, so you can swap or test it.
Four patterns worth knowing cold
You do not need the whole catalog. These four cover most interview problems, and each has a clear cue.
Strategy. Cue: one behavior with several interchangeable versions (pricing rules, spot-selection rules, sorting policies). Put each version behind one interface and inject the one you need.
State. Cue: an object whose allowed actions depend on its current mode (a vending machine that is idle, has money, or is dispensing; an elevator moving up, down or idle). Each state becomes a class, which removes
if (state === ...)checks from every method.Observer. Cue: several parts of the system must react when something happens, and the thing that happens should not know about them (a display board updates when a spot frees up; a notification fires when a ticket is paid).
Factory. Cue: creating the right subtype depends on input, and you do not want that decision scattered (build the right
Vehiclefrom a license-plate scan, or the rightSpotfrom a floor plan).
Tip
Name the pattern only after you have explained the problem it solves: "Pricing varies by vehicle and time of day, so I'll put it behind an interface. That's the strategy pattern." Leading with the pattern name sounds memorized.
Worked example: a parking lot
Clarify
Agreed use cases: a vehicle enters, gets a ticket and is assigned the nearest free spot that fits it; a vehicle exits, pays a fee based on time parked and vehicle size, and frees the spot; a display shows free spots per size. Vehicles are motorcycles, cars and vans. Spots are small, medium and large. Out of scope: reservations, multiple entrances competing for the same spot, and payment processing details.
Entities and responsibilities
Vehicle: knows its plate and size.Spot: knows its id, size and whether it is occupied; answers whether a vehicle fits.Ticket: records which vehicle is in which spot and since when.SpotSelector: picks a free spot for a vehicle (a strategy, because "nearest" may change to "cheapest" or "closest to the elevator").PricingStrategy: computes the fee for a ticket (a strategy, because rates change).ParkingLot: coordinates entry and exit. It owns spots and active tickets and delegates every decision.
Core code
type Size = 1 | 2 | 3; // small, medium, large
class Vehicle {
constructor(readonly plate: string, readonly size: Size) {}
}
class Spot {
private occupiedBy: Vehicle | null = null;
constructor(readonly id: string, readonly size: Size) {}
get isFree(): boolean {
return this.occupiedBy === null;
}
fits(vehicle: Vehicle): boolean {
return this.isFree && vehicle.size <= this.size;
}
park(vehicle: Vehicle): void {
if (!this.fits(vehicle)) throw new Error(`Spot ${this.id} cannot take ${vehicle.plate}`);
this.occupiedBy = vehicle;
}
release(): void {
this.occupiedBy = null;
}
}
class Ticket {
constructor(
readonly vehicle: Vehicle,
readonly spot: Spot,
readonly enteredAt: Date,
) {}
}
interface SpotSelector {
select(spots: readonly Spot[], vehicle: Vehicle): Spot | null;
}
interface PricingStrategy {
feeCents(ticket: Ticket, exitedAt: Date): number;
}
// Spots are stored nearest-first, so the first fit is the nearest.
class NearestFitSelector implements SpotSelector {
select(spots: readonly Spot[], vehicle: Vehicle): Spot | null {
return spots.find((spot) => spot.fits(vehicle)) ?? null;
}
}
class HourlyPricing implements PricingStrategy {
constructor(private readonly centsPerHourBySize: Record<Size, number>) {}
feeCents(ticket: Ticket, exitedAt: Date): number {
const ms = exitedAt.getTime() - ticket.enteredAt.getTime();
const hours = Math.max(1, Math.ceil(ms / 3_600_000));
return hours * this.centsPerHourBySize[ticket.vehicle.size];
}
}
class ParkingLot {
private readonly ticketsByPlate = new Map<string, Ticket>();
constructor(
private readonly spots: readonly Spot[],
private readonly selector: SpotSelector,
private readonly pricing: PricingStrategy,
) {}
enter(vehicle: Vehicle, now: Date): Ticket {
const spot = this.selector.select(this.spots, vehicle);
if (spot === null) throw new Error("Lot full for this vehicle size");
spot.park(vehicle);
const ticket = new Ticket(vehicle, spot, now);
this.ticketsByPlate.set(vehicle.plate, ticket);
return ticket;
}
exit(plate: string, now: Date): number {
const ticket = this.ticketsByPlate.get(plate);
if (ticket === undefined) throw new Error(`No active ticket for ${plate}`);
const fee = this.pricing.feeCents(ticket, now);
ticket.spot.release();
this.ticketsByPlate.delete(plate);
return fee;
}
}Walk the interviewer through the choices. Sizes are ordered numbers, so "fits" is one comparison and a motorcycle can use a car spot. ParkingLot makes no decisions itself: spot choice and pricing are injected, which is dependency inversion and the strategy pattern at once. Money is in integer cents to avoid floating-point rounding. Time is passed in rather than read from the clock, which makes enter and exit trivially testable: a car that stays 2 hours 10 minutes at 300 cents an hour is charged ceil(2.17) = 3 hours, or 900 cents.
Handling the extension
Interviewer: "Add electric vehicle charging spots. EVs prefer them, and charging costs extra."
A design that absorbs this shows its value. You add, rather than edit:
A
ChargingSpot extends Spotthat also records energy delivered.An
EvFirstSelector implements SpotSelectorthat tries free charging spots that fit before falling back toNearestFitSelector.A
ChargingPricing implements PricingStrategythat wraps another strategy and adds the energy cost: it calls the innerfeeCentsand adds the charging fee on top. Wrapping one strategy in another this way is the decorator pattern.
ParkingLot does not change at all. Say that explicitly; it is the moment the interviewer is waiting for.
The display board is the natural observer extension: Spot (or the lot) publishes "spot freed" and "spot taken" events, and the board subscribes, so neither knows how the other works.
Going further
Two follow-on lessons build on this one: Concurrency in low-level design, for when the interviewer asks what happens with two threads, and a full walkthrough of an elevator system that uses the state and strategy patterns together.
Mistakes that cost points
Starting with classes before use cases. You end up modeling things nobody asked for. Instead, agree on three to five use cases first.
A god class. One
ParkingLotclass with 20 methods. Instead, give each decision its own collaborator.Inheritance for everything.
Car extends Vehicle extends Assethierarchies with nothing to inherit. Prefer composition and interfaces; use inheritance only when the subtype truly is a specialized parent.Patterns for their own sake. A factory with one product is noise. Use a pattern when you can name the change it protects against.
No code. Diagrams alone are not enough in most rounds. Get the core flow written and runnable.
Ignoring concurrency when it is in scope. If the interviewer adds multiple entrances, two cars can claim the same spot. Say where you would lock, or make spot assignment atomic.
Practice it
Spend 15 minutes modeling a vending machine on paper with the flow above: use cases, entities, one-sentence responsibilities, then the state pattern for idle, has-money and dispensing. Then practice the closest format on SmartIntervu:
Design an LRU Cache: a coding interview where choosing and justifying the data structures, then writing them cleanly, is the whole exercise.
Practise this in a mock interview
Try what this lesson covers out loud: the AI interviewer asks one of these questions, follows up, and scores your answer.
- Two SumCoding · Easy
- Design an LRU CacheCoding · Medium
- Deploy Services in Dependency WavesCoding · Medium
- Flag Overlapping Maintenance WindowsCoding · Medium
Read next
- Concurrency in Low-Level Design Interviews
Spot the check-then-act races concurrency adds to a design, fix them with the right tool (concurrent collection, lock, atomic, read-write lock or bounded queue), avoid deadlock with lock ordering, and answer the multi-server follow-up.
8 min read
- Design an Elevator System: A Low-Level Design Walkthrough
Walk an elevator design end to end: requirements, entities, a state-pattern state machine, LOOK stop ordering, a cost-based dispatch strategy, extensions without a rewrite, and concurrency.
9 min read
