Design a Parking Lot

OOP Class Design, Space Allocation Algorithms, Pricing Strategies, and Real-Time Occupancy Tracking

The parking lot system is a classic OOP + system design hybrid question frequently asked at FAANG interviews. It tests your ability to model real-world entities into clean class hierarchies while also addressing system-level concerns. Key challenges include: modeling vehicle types (cars, SUVs, motorcycles) with different space requirements, space allocation strategies (nearest entrance, even distribution, type clustering), pricing tiers with hourly rates, daily maximums, and peak surcharges, payment processing at exit gates, real-time occupancy tracking with display boards, entry/exit gate management handling concurrent arrivals, and multi-floor support with per-floor availability. A large airport parking structure manages 10,000+ spaces across multiple floors with 20,000+ vehicles per day.

Parking Lot Simulator

A visual 6x5 grid of 30 parking spaces. Color-coded by type: compact (blue), regular (green), large (yellow), handicapped (purple). Park vehicles and watch occupancy change in real time.

Compact Regular Large Handicapped Occupied
Total Spaces30
Occupied0
Available30
Occupancy0%
Click a button to park or remove a vehicle

OOP Class Diagram

The class hierarchy models the parking lot domain. Each class has clear responsibilities and relationships. Subtypes inherit from base classes, following the Open/Closed Principle.

ParkingLot
- floors: ParkingFloor[]
- entryGates: Gate[]
- exitGates: Gate[]
- capacity: int
+ addFloor()
+ getAvailableSpots()
+ issueTicket()
|
ParkingFloor
- floorNumber: int
- spots: ParkingSpot[]
- displayBoard: DisplayBoard
+ getAvailableSpots(type)
+ updateBoard()
|
ParkingSpot
- id: string
- type: SpotType
- isOccupied: bool
- vehicle: Vehicle
+ assignVehicle(v)
+ removeVehicle()
Vehicle
- licensePlate: string
- type: VehicleType
+ getType()
Ticket
- id: string
- entryTime: DateTime
- exitTime: DateTime
- spot: ParkingSpot
- vehicle: Vehicle
+ getDuration()
PaymentProcessor
- rates: PricingTier[]
+ calculateFee(ticket)
+ processPayment()
|
Spot Types
CompactSpot
RegularSpot
LargeSpot
HandicappedSpot
Vehicle Types
Car
SUV
Motorcycle

Space Allocation Strategy

Compare how different allocation strategies fill the lot. Watch vehicles park under each strategy and observe the resulting distribution patterns.

Fills spots closest to the entrance first. Minimizes walking distance but creates congestion near entry points.
Select a strategy and park vehicles to see the pattern

Pricing Calculator

Calculate parking fees with tiered pricing. First hour is a flat rate, subsequent hours have an hourly rate, and a daily maximum cap applies. Vehicle type and peak hours affect the total.

First hour (flat)$5.00
Additional hours$8.00
Vehicle multiplier1.0x
Peak surcharge$0.00
Daily maximum cap$40.00
Total$13.00

Capacity Estimation

Estimate throughput, revenue, and infrastructure requirements for a parking lot system based on configuration parameters.

Total Spaces600
Daily Vehicles3,264
Peak Concurrent510
Gate Throughput204/hr
Annual Revenue$4.8M
Entry Gates Needed2
Exit Gates Needed2
Avg Revenue/Space$8,000

System Architecture

High-level architecture showing how entry/exit sensors, controllers, and backend services interact to manage the parking lot in real time.

Entry Gate Sensor
Gate Controller
Parking Service
spot lookup
Space Manager
issue/validate
Ticket Service
fee calc
Payment Service
Database
Display Board
Exit Gate

Key Design Decisions

Spot Assignment

Nearest available minimizes walk time but creates congestion near entrances and uneven wear. Optimized distribution spreads vehicles evenly across floors, reducing congestion and improving traffic flow. At scale, use a min-heap per spot type for O(log n) assignment.

Payment Model

Pay-on-exit is traditional: calculate fee from ticket duration at the gate. Pre-pay requires estimating duration upfront with potential refund/surcharge. Support subscriptions (monthly pass holders) with RFID tags that auto-open gates. Integrate with mobile payment for ticketless entry.

Concurrency

Multiple vehicles arriving simultaneously at different gates must not be assigned the same spot. Use optimistic locking with version checks on spot assignment: UPDATE spots SET vehicle_id = ? WHERE id = ? AND version = ?. For high-throughput lots, use a centralized assignment queue to serialize spot allocation.

Scalability

Single lot: monolithic service with local DB is sufficient. Multi-lot platform: need centralized management with per-lot microservices. Edge computing at each lot for gate decisions (sub-100ms response) with cloud sync for analytics and billing. Use event sourcing to track all state changes for audit trails.

The parking lot design question tests OOP modeling, concurrency handling, and real-world system constraints. Practice explaining the class hierarchy, allocation trade-offs, and scaling strategy.