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.
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.
Space Allocation Strategy
Compare how different allocation strategies fill the lot. Watch vehicles park under each strategy and observe the resulting distribution patterns.
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.
Capacity Estimation
Estimate throughput, revenue, and infrastructure requirements for a parking lot system based on configuration parameters.
System Architecture
High-level architecture showing how entry/exit sensors, controllers, and backend services interact to manage the parking lot in real time.
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.