Lesson 13 of 32Technical rounds
Object-Oriented (Low-Level) Design Round
Turn a prompt like 'design a parking lot' into clear classes, working core code and good answers to the extension and concurrency follow-ups.
"Design a parking lot." You have 45 minutes, a shared editor, and an interviewer who will not tell you what a parking lot needs. This is the object-oriented design round, also called low-level design (LLD) or machine coding. It is common at Amazon, Microsoft, Uber and many companies outside big tech, and it often replaces system design for junior and mid-level candidates. It tests the skill you use most at work: turning fuzzy requirements into classes and interfaces that someone else can read, test and extend. This lesson gives you a process, then works the parking lot end to end in runnable Python, including the follow-ups that decide the grade.
What the round is, and is not
You design the classes, their responsibilities and their interfaces for a bounded system, then code the core paths. Typical prompts: parking lot, elevator system, vending machine, library management, deck of cards, an in-memory file system, a rate limiter class, a snake game, a splitwise-style expense sharer.
It is not system design. There are no load balancers, databases or replicas unless the interviewer brings them up. If you start drawing servers, you have misread the round. Think "the code inside one service" rather than "the services".
It is also not a pattern quiz. Interviewers are not counting how many patterns you name. They score roughly this:
- Requirements: did you pin down scope before designing?
- Modelling: are the entities sensible, with clear responsibilities and no god class?
- Interfaces: are method names and signatures clear, and do they hide internals?
- Working code: do the core use cases actually run?
- Extensibility: when the interviewer adds a requirement, how much code has to change?
- Communication: do you explain trade-offs as you go?
The process
| Minutes | Step | Output |
|---|---|---|
| 0–5 | Clarify use cases | A short list of in-scope actions, and what is out |
| 5–10 | Entities and responsibilities | Nouns become candidate classes, each with one job |
| 10–15 | Relationships and interfaces | Who owns whom, the public methods and their signatures |
| 15–35 | Code the core paths | Enums, data classes, the main service class, a demo |
| 35–45 | Extensions and concurrency | How new requirements fit; what breaks with two callers |
Clarify use cases. For a parking lot, ask: Which vehicle types? Which spot sizes, and can a small vehicle use a big spot? One level or several? How is pricing calculated: hourly, flat, by vehicle? Is payment in scope, or just the fee? Do we need a display of free spots? Then say what you will leave out: "I'll skip payment processing and reservations, and treat the clock as an input so it is easy to test."
Entities and responsibilities. Underline the nouns: vehicle, spot, ticket, lot, pricing. For each, say its one job. A Spot knows whether a vehicle fits. A Ticket records who parked where and when. A PricingStrategy turns a duration into a fee. The ParkingLot coordinates. If one class ends up doing everything, that is the god class interviewers look for.
Relationships. Default to composition: the lot has spots and has a pricing strategy. Use inheritance only for a real "is a" relationship where subclasses are interchangeable. A classic weak answer is class Car(Vehicle), class Truck(Vehicle), class Motorcycle(Vehicle) with no behaviour difference between them. If the only difference is a size, a size field on one Vehicle class is simpler and adding a new vehicle type stops needing a new class.
ParkingLot is the only class callers talk to. It coordinates; it does not know how fees are calculated.
The worked example: a parking lot in Python
Agreed scope: three sizes (motorcycle, compact, large); a vehicle fits any spot at least its size; pick the smallest spot that fits; hourly pricing per started hour with a one-hour minimum, varying by vehicle size; leave by ticket id and get the fee; refuse cleanly when full. Time is passed in as minutes so the demo is deterministic.
Press Run (⌘ Enter) to see what happens.What to say about the choices as you write them:
IntEnumfor size makes "fits" a plain comparison,vehicle.size <= self.size. A plainEnumwould need a lookup table. Saying why you chose the type is a quiet signal of experience.- Frozen dataclasses for
VehicleandTicket: they are values that should never change after creation, and freezing them makes them hashable and safe to share. - Money in integer cents, never floats.
0.1 + 0.2is not0.3in binary floating point, and fee bugs are the kind that reach customers. - The clock is an argument.
nowis passed in instead of calling the system clock inside the class, so tests are deterministic. This is dependency injection at its simplest. - Private attributes (
_spots,_active) keep callers on the public methods. The lot's internals can change without breaking anyone. - A specific exception for a full lot rather than returning
None, so callers cannot accidentally ignore it.
The spot choice is a deliberate policy: smallest fitting spot first. It keeps large spots free for large vehicles, but it is not perfect, and interviewers like to poke at it.
What does this print?
spots = [("L1", 3), ("M1", 1), ("C1", 2)]
spots.sort(key=lambda s: s[1])
taken = set()
def park(size):
for sid, cap in spots:
if sid not in taken and size <= cap:
taken.add(sid)
return sid
return None
print(park(1), park(1), park(3), park(2))Patterns where they earn their keep
Interviewers like patterns that solve a stated problem and dislike patterns added for decoration. The Behavioral Patterns and Creational Patterns lessons cover these in depth; here is when each one naturally appears in an LLD round.
- Strategy when a rule has several versions that change independently: pricing, spot assignment (smallest fit, nearest the exit), elevator scheduling. The parking lot above takes any
PricingStrategy, so adding a tariff never touchesParkingLot. That is the open/closed principle from SOLID Principles in practice. - State when an object behaves differently depending on its mode and only some transitions are legal: vending machine (idle, has money, dispensing), elevator (idle, moving up, moving down, doors open), order lifecycle.
- Observer when other parts must react to an event without the source knowing who they are: a display board updating free-spot counts, notifications when a book you reserved is returned.
- Factory when creation logic is non-trivial or chosen at run time: building the right
PricingStrategyfrom a config string, creating levels with a given layout. - Singleton: be careful. "There is only one parking lot" is a common reason given, but a module-level instance or simply creating one and passing it in does the same job and stays testable. Saying that is a better answer than reaching for the pattern.
Apply SOLID as a check, not a ceremony. Single responsibility: can you describe each class without "and"? Dependency inversion: does ParkingLot depend on the PricingStrategy interface rather than a concrete class? Do not add interfaces for things with exactly one implementation and no plan for a second.
Match each requirement to the pattern that fits it best.
The vending machine: State with a discriminated union
State shows up in the vending machine and elevator prompts. In TypeScript, a discriminated union is the cleanest way to write it: each state is a type with its own data, and the compiler checks that you handle every case. A machine with money has a credit; an idle machine cannot, so there is no invalid "idle with 150 cents" state to worry about.
Pressing a button in idle has no edge, so nothing happens. No money, no item.
Press Run (⌘ Enter) to see what happens.The Python equivalents: an Enum for the state names plus a transition table, or one small class per state behind an abc.ABC when each state has real behaviour. In either language, mention that a pure next(state, event) function is trivially testable, which is a design argument in itself.
The concurrency follow-up
Almost every LLD round ends with some version of: "Two cars arrive at two gates at the same moment. Can they get the same spot?" With a naive design, yes. Finding a free spot and claiming it are two separate steps, and the other gate can run between them. This is a check-then-act race.
Press Run (⌘ Enter) to see what happens.Car A has silently vanished from the unsafe version: it holds a ticket for a spot that someone else is in. Three fixes, in order of how far they scale:
- A lock around find-and-claim, as
ParkingLot.parkdoes withthreading.Lock. Simple and correct inside one process. The cost is that every park waits for the lock, which is fine at parking-lot speeds. - Finer-grained locks, such as one per level, so gates on different levels do not block each other. More throughput, more complexity, and a deadlock risk if code ever takes two locks in different orders.
- Compare-and-set in the database once there are several servers:
UPDATE spots SET vehicle = :plate WHERE id = :id AND vehicle IS NULL, then check that exactly one row changed. If zero changed, someone beat you to it, so pick another spot and retry. An in-process lock cannot protect you across machines; the database row can.
Name the trade-off and stop. You do not need to build a distributed system; you need to show you saw the race and know which tool fits which scale.
Extension questions, and how to answer them
After the core works, expect two or three "what if" questions. Answer each by saying which class changes and which does not. That is the evidence your design is extensible.
- "Add electric-vehicle charging spots." Add a
charging: boolcapability onSpotand aneeds_chargingonVehicle; extendfits(). Pricing could add a charging fee through a new strategy or a decorator around the existing one.ParkingLot.parkdoes not change. - "Multiple levels, and a display per level." Introduce
Level, which owns its spots; the lot owns levels. The display subscribes to spot-freed and spot-taken events (Observer). - "Monthly pass holders park free." A new pricing strategy that checks a pass registry, or a check before pricing. Ask whether passes reserve a spot; that changes the model.
- "Lost ticket." Look up the active ticket by plate (add an index from plate to ticket id) and charge a fixed lost-ticket fee as policy.
Put the steps of an object-oriented design round in order.
- Tap the steps below in the right order.
Common mistakes
- Coding before scoping. Ten minutes into a class hierarchy for payment methods that were never in scope.
- A god class.
ParkingLotthat calculates fees, prints receipts, sends emails and validates plates. - Inheritance for data. Subclasses that differ only in a field.
- Getters and setters for everything. Expose behaviour (
park,leave), not raw fields to be changed from outside. - Patterns without problems. A singleton, an abstract factory and a visitor in a design that needs none of them.
- Never running anything. A diagram and stubs with
passscore below a smaller design that actually works. - Floats for money, and wall-clock time inside the class. Both make bugs and make tests flaky.
- low-level design (LLD)
- An interview round where you design classes, responsibilities and interfaces for a bounded system and code the core paths.
- composition
- Building an object from other objects it owns or uses, a has-a relationship, preferred over inheritance in most designs.
- god class
- One class that has taken on most of the system's responsibilities, making it hard to read, test and change.
- discriminated union
- A TypeScript union of object types sharing a literal tag field, so the compiler can narrow and check every case.
- check-then-act race
- A bug where a condition is checked and then acted on in separate steps, letting another caller change things in between.
- compare-and-set
- An atomic operation that writes a new value only if the current value is still the expected one, reporting whether it succeeded.
- IntEnum
- A Python enum whose members are also integers, so they can be ordered and compared directly.