Design a Parking Lot — LLD Walkthrough
The classic LLD interview, done the way they grade it
"Design a parking lot" tests object modelling, not algorithms. The method: clarify requirements → identify entities → draw the class model → name the patterns → handle the tricky bits (here: concurrency). Below is that flow.
1. Requirements (clarify first)
- Functional: multiple levels; spot types (compact / large / handicap / motorcycle); park & unpark; issue a ticket; compute a fee; find an available spot for a vehicle.
- Non-functional: concurrent entries (many gates), extensible to new vehicle/spot types, fast "find a spot."
2. The class model + the patterns it uses
- Composition:
ParkingLot 1..* Level 1..* ParkingSpot(the diamond ends). - Inheritance: abstract
Vehicle←Car/Motorcycle/Truck;ParkingSpotknows which vehicle sizes it fits. - Strategy:
PricingStrategy(hourly / flat / day-rate) andPaymentStrategy— swap without touching the lot. - Factory: build the right
Vehicle/Spotsubtype. - Singleton: one
ParkingLotinstance (with the thread-safety caveats from the Singleton lesson).
abstract class Vehicle { abstract VehicleSize size(); }
class ParkingSpot { SpotType type; boolean free; boolean fits(Vehicle v){ /* size rule */ } }
class Level {
private final List<ParkingSpot> spots;
// concurrency: two cars must not claim the same spot
synchronized Optional<ParkingSpot> assign(Vehicle v) {
return spots.stream().filter(s -> s.free && s.fits(v)).findFirst()
.map(s -> { s.free = false; return s; });
}
}
3. The tricky bit: concurrency
This is where senior candidates separate: two vehicles arriving at once must not be assigned the
same spot — the lost-update race again (see Concurrency, and the Ticketmaster seat-lock). Guard the
assignment (a lock per level, or an atomic compare-and-set on the spot's free flag). Don't lock the
whole lot — that kills throughput; lock at the spot/level grain.
Pitfalls
- God class: a
ParkingLotthat does everything — push behaviour to Level/Spot. - Ignoring concurrency — the #1 thing interviewers probe; mention the spot-assignment race.
- Hard-coding pricing/payment instead of Strategy — fails the extensibility question.
Takeaways
- LLD method: requirements → entities → class model → patterns → concurrency/extensibility.
- Parking lot = composition + Vehicle hierarchy + Strategy (pricing/payment) + Factory + Singleton.
- Call out the spot-assignment race and lock at the right grain — that's the senior signal.
🔨 Practice this
Reading isn't building. Build a Parking Lot → — implement this from an empty file in Go and Java with an O(1) per-size allocator, then write the concurrency test that fails the moment you drop the lock. That's the gap the interviewer probes.
Re-authored for this guide; UML class diagram hand-authored as SVG. Follows common LLD interview rubrics and GoF patterns. See also: Singleton, Strategy, SOLID, and (Concurrency) Race Conditions / (System Design) Ticketmaster.
🤖 Don't fully get this? Learn it with Claude
Stuck on Design a Parking Lot — LLD Walkthrough? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.
Build the mental picture, not memorization.
I just read a lesson on **Design a Parking Lot — LLD Walkthrough** (OO & Low-Level Design) and want to truly understand it. Explain Design a Parking Lot — LLD Walkthrough from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
Socratic — adapts to where you're stuck.
Teach me **Design a Parking Lot — LLD Walkthrough** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
Active recall exposes what you missed.
Quiz me on **Design a Parking Lot — LLD Walkthrough** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
Intuition + hook + flashcards for long-term memory.
Help me remember **Design a Parking Lot — LLD Walkthrough** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.