Intermediate · 7 min read · updated 14 November 2026
Quick answer
How do you design a parking lot in a low-level design interview?
Model a ParkingLot made of Levels, each holding ParkingSpots of a size, and Vehicles created by a factory. Parking asks a spot-allocation strategy for a free spot that fits and issues a Ticket; leaving frees the spot and asks a pricing strategy for the fee. Lock the find-and-take step so two gates never book one spot.
A parking lot is the classic warm-up of the machine-coding round: small enough to code in an hour, rich enough to show classes, relations, two patterns and one concurrency bug.
Requirements
Several levels, each with spots of three sizes: small, medium, large.
Three vehicle types: a bike fits any spot, a car a medium or large one, a truck only a large one.
Park: give the vehicle a free spot that fits and issue a ticket.
Leave: free the spot and charge a fee by type and hours.
Report when a level (or the lot) is full.
Out of scope unless asked: payments, reservations, several gates at once.
Classes and relations
The parking lot's classes, one relation at a time
Start from the noun the requirements open with: one ParkingLot, the class the gates talk to. It parks a vehicle (returning a ticket) and takes a ticket back (returning the fee).
0:01 / 0:18Step 1 of 5
Transcript · 5 steps
Composition: a lot owns its levels, a level its spots. See UML class diagrams.
Association: a spot holds 0..1 vehicle; a ticket points at a vehicle and a spot.
The lot depends only on two interfaces, so it stays closed for modification (SOLID).
Parking a vehicle
The spot strategy here is best fit: lowest level first, then the smallest free spot that fits, so large spots stay free for trucks.
Best fit at work: every vehicle into the spot the strategy chose
Two levels, five spots of three sizes. The spot strategy is best fit: try the lowest level first, and on it take the smallest free spot the vehicle fits in.
0:01 / 0:27Step 1 of 9
Transcript · 9 steps
park(KA-04, CAR): the gate, the lot, the strategy and the levels
A car with plate KA-04 reaches the entry gate, which calls the lot. VehicleFactory turns CAR into a vehicle that needs a medium spot.
0:01 / 0:20Step 1 of 8
Transcript · 8 steps
The patterns used
Pattern
Where
Why
Strategy
SpotStrategy (best fit, nearest gate)
Change the allocation rule without editing the lot
Concurrency at the gates: finding and taking a spot must be one atomic step.
Two gates, two free spots: a race without a lock, none with one
Two cars reach two gates at the same moment, and two medium spots are free. Each gate runs the same code: find the first free spot, then mark it taken.
0:01 / 0:16Step 1 of 5
Transcript · 5 steps
Persistence: the same rule as a conditional update, UPDATE spot SET vehicle = ? WHERE id = ? AND vehicle IS NULL, retried if no row changed.
Display boards: free counts per level and size, updated on park and leave; an Observer fits.
Payments: a Payment with cash, card and UPI behind one interface, taken at the exit gate.
Faster search: a free list per size per level instead of scanning every spot.
Interview questions
Why put allocation behind an interface? The rule is the part most likely to change, and the lot should not be edited for it.
Should ParkingLot be a Singleton? One lot per process is fine, but injecting the instance keeps tests independent.
How do you stop double booking? Lock the find-and-take step, or use a conditional database update.
Where does the fee logic live? In a pricing strategy that reads the ticket's entry time and vehicle type.
How would you find a spot in O(1)? Keep a queue of free spots per size per level.
ParkingLot, Level, ParkingSpot, Vehicle (with its type), Ticket, and two strategy interfaces: one that picks a spot and one that prices a stay. Gates, payments and display boards are added when the interviewer asks for them.
Which design patterns are used in a parking lot system?
Strategy for spot allocation and for pricing, so either rule can change without touching ParkingLot. Factory to create vehicles and know which spot size each needs. Singleton is often suggested for the lot, but passing one instance in is easier to test.
How do you handle two cars taking the last spot at the same time?
Make finding and taking a spot one atomic step: a lock around it in a single process, or a conditional update such as setting the spot taken only where it is still free in a database. The second gate then re-reads and gets another spot or none.
How is the parking fee calculated?
The ticket records the entry time. On exit, a pricing strategy computes the fee from the vehicle type and the hours parked, for example hours times an hourly rate with a one-hour minimum. Flat, weekend or first-hour-free rules are other implementations of the same interface.
How do you support multiple floors or levels?
The lot holds a list of levels and the allocation strategy walks them in order, lowest first, or by distance from the entry gate. Each level can report whether it is full, which feeds the display boards at the gates.
How do you design a parking lot in a low-level design interview?
Model a ParkingLot made of Levels, each holding ParkingSpots of a size, and Vehicles created by a factory. Parking asks a spot-allocation strategy for a free spot that fits and issues a Ticket; leaving frees the spot and asks a pricing strategy for the fee. Lock the find-and-take step so two gates never book one spot.
A parking lot is the classic warm-up of the machine-coding round: small enough to code in an hour, rich enough to show classes, relations, two patterns and one concurrency bug.
Requirements
Several levels, each with spots of three sizes: small, medium, large.
Three vehicle types: a bike fits any spot, a car a medium or large one, a truck only a large one.
Park: give the vehicle a free spot that fits and issue a ticket.
Leave: free the spot and charge a fee by type and hours.
Report when a level (or the lot) is full.
Out of scope unless asked: payments, reservations, several gates at once.
Classes and relations
The parking lot's classes, one relation at a time.
Start from the noun the requirements open with: one ParkingLot, the class the gates talk to. It parks a vehicle (returning a ticket) and takes a ticket back (returning the fee).
A lot is made of levels and a level of spots, each with a size. Both are composition: a spot does not exist outside its level, nor a level outside its lot.
A spot holds at most one Vehicle. VehicleFactory is the one place that turns a type into a vehicle and the spot size it needs, so a new type changes one class.
A Ticket records which vehicle went into which spot and when, so leaving needs only the ticket: it frees the spot and prices the stay.
The two rules that change most sit behind interfaces: which spot to pick (best fit, nearest the lift) and how to charge (hourly, flat, weekend). Swapping one never touches ParkingLot.
Composition: a lot owns its levels, a level its spots. See UML class diagrams.
Association: a spot holds 0..1 vehicle; a ticket points at a vehicle and a spot.
The lot depends only on two interfaces, so it stays closed for modification (SOLID).
Parking a vehicle
The spot strategy here is best fit: lowest level first, then the smallest free spot that fits, so large spots stay free for trucks.
Best fit at work: every vehicle into the spot the strategy chose.
Two levels, five spots of three sizes. The spot strategy is best fit: try the lowest level first, and on it take the smallest free spot the vehicle fits in.
KA-01 (bike) fits any spot; best fit takes level 1's smallest free one that fits, S1.
KA-02 (car) fits a medium or large spot; best fit takes level 1's smallest free one that fits, M1.
KA-03, a truck, fits only a large spot, so it takes L1. Every spot on level 1 is now taken: the next vehicle's search moves on to level 2.
KA-04 (car) fits a medium or large spot; best fit takes level 2's smallest free one that fits, M1, because level 1 has none left.
KA-02 leaves after 3 hours. The ticket frees level 1 spot M1 and the hourly pricing strategy charges 3 × 20 = 60.
KA-05 (car) fits a medium or large spot; best fit takes level 1's smallest free one that fits, M1.
KA-06 (truck) fits only a large spot; best fit takes level 2's smallest free one that fits, L1, because level 1 has none left.
KA-07 is a truck and the only large spots are both taken, so best fit returns nothing and the gate turns it away — the display board should already say "full" for trucks.
park(KA-04, CAR): the gate, the lot, the strategy and the levels.
A car with plate KA-04 reaches the entry gate, which calls the lot. VehicleFactory turns CAR into a vehicle that needs a medium spot.
The lot does not search itself: it asks its spot strategy. Swapping BestFit for another strategy changes this one arrow's target.
Best fit starts at the lowest level and asks for the smallest free spot of medium size or larger.
Level 1 has nothing free: the bike, the first car and the truck took S1, M1 and L1.
So the strategy moves on to level 2 and asks the same question.
Level 2 answers M1, its smallest free spot that fits a car; L1 stays free for a truck.
The strategy returns the spot. The lot marks it taken and writes a ticket with the plate, the spot and the entry hour.
The gate prints the ticket and lifts the barrier: KA-04 is parked in level 2 spot M1.
The patterns used
Pattern
Where
Why
Strategy
SpotStrategy (best fit, nearest gate)
Change the allocation rule without editing the lot
Concurrency at the gates: finding and taking a spot must be one atomic step.
Two gates, two free spots: a race without a lock, none with one.
Two cars reach two gates at the same moment, and two medium spots are free. Each gate runs the same code: find the first free spot, then mark it taken.
Without a lock the two steps interleave: gate A reads M1 as free, and before it writes, gate B reads the lot and also sees M1 free.
Both gates write: KA-08 and KA-09 are both assigned M1 while M2 stays empty. That is a double booking, the race interviewers ask about.
With a lock around find-and-take, gate A holds it, reads M1 free and takes it; gate B must wait, so it cannot read a stale lot.
A releases the lock, B takes it, reads the lot again and finds M2 the first free spot. Each car gets its own spot; the critical section is just those two steps.
Persistence: the same rule as a conditional update, UPDATE spot SET vehicle = ? WHERE id = ? AND vehicle IS NULL, retried if no row changed.
Display boards: free counts per level and size, updated on park and leave; an Observer fits.
Payments: a Payment with cash, card and UPI behind one interface, taken at the exit gate.
Faster search: a free list per size per level instead of scanning every spot.
Interview questions
Why put allocation behind an interface? The rule is the part most likely to change, and the lot should not be edited for it.
Should ParkingLot be a Singleton? One lot per process is fine, but injecting the instance keeps tests independent.
How do you stop double booking? Lock the find-and-take step, or use a conditional database update.
Where does the fee logic live? In a pricing strategy that reads the ticket's entry time and vehicle type.
How would you find a spot in O(1)? Keep a queue of free spots per size per level.
ParkingLot, Level, ParkingSpot, Vehicle (with its type), Ticket, and two strategy interfaces: one that picks a spot and one that prices a stay. Gates, payments and display boards are added when the interviewer asks for them.
Which design patterns are used in a parking lot system?
Strategy for spot allocation and for pricing, so either rule can change without touching ParkingLot. Factory to create vehicles and know which spot size each needs. Singleton is often suggested for the lot, but passing one instance in is easier to test.
How do you handle two cars taking the last spot at the same time?
Make finding and taking a spot one atomic step: a lock around it in a single process, or a conditional update such as setting the spot taken only where it is still free in a database. The second gate then re-reads and gets another spot or none.
How is the parking fee calculated?
The ticket records the entry time. On exit, a pricing strategy computes the fee from the vehicle type and the hours parked, for example hours times an hourly rate with a one-hour minimum. Flat, weekend or first-hour-free rules are other implementations of the same interface.
How do you support multiple floors or levels?
The lot holds a list of levels and the allocation strategy walks them in order, lowest first, or by distance from the entry gate. Each level can report whether it is full, which feeds the display boards at the gates.