LLD Case Study: Parking Lot
Design the classic parking lot: floors, spot types, vehicle types, tickets, fee calculation and concurrent spot allocation.
Intermediate · about 4 hours · difficulty 3/5
Learn first: Approaching an LLD Problem: Requirements, Entities and UML
The parking lot is the "hello world" of LLD rounds. It looks simple, which is exactly why interviewers use it to test structure and extensibility.
Typical requirements
- Multiple floors, each with spots of different sizes (bike, car, truck; maybe EV charging spots).
- Entry and exit gates issue and close tickets.
- Fees depend on vehicle type and duration (first hour flat, then per hour; different rules on weekends).
- Show available spots per floor on a display board.
Core classes
- ParkingLot (holds floors, gates; often a single instance).
- ParkingFloor has many ParkingSpots; each spot has a type and an occupied flag.
- Vehicle (abstract) with Bike, Car, Truck, or simply a VehicleType enum.
- Ticket: id, vehicle, spot, entry time, exit time, status.
- EntryGate / ExitGate, DisplayBoard, Payment.
Where patterns help
- Strategy for spot allocation (nearest to gate, lowest floor first, spread evenly).
- Strategy for fee calculation (hourly, flat, weekend pricing). New pricing means a new class, not edited code.
- Factory for creating vehicles or spots.
- Observer for updating display boards when spots change.
Concurrency
Two entry gates may try to assign the same spot. Options: synchronise allocation per floor, use atomic compare-and-set on the spot's occupied flag, or keep a concurrent queue of free spots per type. Mention it before you are asked.
Pitfalls
- Hardcoding fee logic inside the Ticket or Gate class.
- Using deep inheritance for spot types when an enum plus a size rule is enough.
- Forgetting lost tickets, overstays and full-lot handling.
You are ready to move on when you can code a parking lot in under an hour where adding a new vehicle type or pricing rule touches only one or two new classes.
Key concepts
- Floors, spots and vehicle types
- Ticket lifecycle
- Spot allocation strategy
- Fee calculation strategy
- Concurrent allocation
- Display board with Observer
- EV charging spots extension
Mini project
Implement a parking lot in Java, Python, Go or TypeScript with pluggable allocation and pricing strategies, thread-safe parking from 4 concurrent gates, and tests covering full lot, overstay and a new vehicle type added later.
Check yourself
Two gates call park() at the same instant and both see spot 12 as free. Describe two ways to make sure only one gets it.
Free resources
- Awesome Low Level Design (parking lot and more) (GitHub)
- Strategy pattern (Refactoring.Guru)
- Java concurrency tutorial (Oracle)