Skip to main content
← PROBLEMS / LLD
An end-to-end domain learning journey

Design a Multi-Floor Smart
Parking Lot System (LLD).

A thread-safe multi-floor parking lot LLD uses per-floor min-heaps for O(log N) nearest-spot allocation, per-floor locks to prevent cross-gate races, and a Strategy pattern for extensible fee calculation.
Start the journey5 stages
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

To keep the architecture evolvable without sacrificing reliability, use per-floor locks with min-heaps for O(log N) spot assignment without global gate contention, and decouple pricing via a FeeStrategy interface.

TL;DR30-second simplified summary
▾

Core Mechanics: A multi-floor smart parking garage with multiple entry/exit gates must assign the nearest available compatible spot (Compact, Large/SUV, EV) in O(log N) or O(1) time without two entry gates ever issuing tickets for the same spot simultaneously.

Visual & Structural Flow: Depicts Multi-Gate Entry Race Prevention with Per-Floor Min-Heap & Lock (Entry Gate 1 -> Entry Gate 2 -> Floor 1 Heap -> Ticket Store); Per-Floor Min-Heap by SpotType & Distance (ParkingLot -> Floor 1 Heap -> Floor 2 Heap -> F1-01).

Trade-Offs & Production: A basic implementation iterates over a List<ParkingSpot> and hardcodes if (vehicle == EV) fee math inside ExitGate: O(N) Allocation: Scanning thousands of spots per entry degrades under rush-hour bursts. Production LLD structures the domain cleanly: O(log N) Nearest-Spot Heap: Each ParkingFloor maintains a min-heap (heapq / PriorityQueue) per SpotType ordered by.

Failure Modes & Application: The same indexed resource-pool + Strategy architecture appears across real systems: Cloud VM / Container Schedulers: Maintaining priority queues of available compute slots per availability zone.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Core LLD Behavioral Patterns: State, Strategy & Observer in Practice
Behavioral patterns—State, Strategy, and Observer—eliminate brittle if-else chains in Low-Level Design interviews and production systems by encapsulating lifecycle transitions, interchangeable algorithms, and event notifications behind clean interfaces.
DDD Aggregates, Value Objects & SOLID Principles for Clean LLD
Domain-Driven Design (DDD) pairs with SOLID principles to structure complex business domains around immutable Value Objects, consistency-enforcing Aggregate Roots, and dependency-inverted Repository interfaces.
Full walkthrough · 5 stages
01
STAGE 01 · WHY IT MATTERSL4 · FUNDAMENTALS

Why spot-indexing and gate concurrency matter in Parking Lot LLD.

Why this matters: The mechanism: understand how Why spot-indexing and gate concurrency matter in Parking Lot LLD works from first principles.

Think of Why spot-indexing and gate concurrency matter in Parking Lot LLD as the intuition layer for Design a Multi-Floor Smart Parking Lot System (LLD): The mechanism: understand how Why spot-indexing and gate concurrency matter in Parking Lot LLD works from first principles.

A multi-floor smart parking garage with multiple entry/exit gates must assign the nearest available compatible spot (Compact, Large/SUV, EV) in O(log N) or O(1) time without two entry gates ever issuing tickets for the same spot simultaneously.

02
STAGE 02 · IMPACTL5 · APPLIED DESIGN

What happens with linear scans and coarse global locks.

Why this matters: The problem: see what breaks without What happens with linear scans and coarse global locks under real concurrency or scale.

Scanning all spots linearly or locking the entire ParkingLot creates two bottlenecks:

  1. Double-Assigned Spots: Gate A and Gate B both read spot F2-14 as free and issue two tickets for it.
  2. Gate Contention: A single global lock on ParkingLot blocks Gate B on Floor 5 while Gate A is processing a ticket on Floor 1.
Concurrent Gate Allocation

Multi-Gate Entry Race Prevention with Per-Floor Min-Heap & Lock

Entry Gate 1Entry Gate 2Floor 1 HeapTicket Store1. acquire floor_1.lock -> pop min2. wait on floor_1.lock (or Floor2)3. assigned spot F1-01 (O(log N))4. issue Ticket(F1-01, entry_ts)

Per-floor locks serialize spot pops within a floor in O(log N) while allowing different floors to allocate in parallel.

Engineering Decision Framework
Problem
How to implement Design a Multi-Floor Smart Parking Lot System (LLD) without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
To keep the architecture evolvable without sacrificing reliability, use per-floor locks with min-heaps for O(log N) spot assignment without global gate contention, and decouple pricing via a FeeStrategy interface.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Design a Multi-Floor Smart Parking Lot System (LLD) experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
STAGE 03 · NAIVE SOLUTIONL5 · APPLIED DESIGN

Naive solution (and why if-else pricing + ArrayList scans fail).

Why this matters: The problem: see what breaks without Naive solution under real concurrency or scale.

A basic implementation iterates over a List<ParkingSpot> and hardcodes if (vehicle == EV) fee math inside ExitGate:

  • O(N) Allocation: Scanning thousands of spots per entry degrades under rush-hour bursts.
  • Open/Closed Violation: Adding weekend surge or EV kWh billing requires editing ExitGate and ParkingLot.
Lifecycle & Failure Recovery

Naive solution (and why if-else pricing + ArrayList scans fail)

admitsucceedbudget exceededInitializedProcessingInvariant MetDegraded Fallback
04
STAGE 04 · ENTERPRISE SOLUTIONL6 · SCALE & TRADE-OFFS

Enterprise solution: Per-Floor Min-Heaps + FeeStrategy + Ticket State.

Why this matters: Operational control: configure bounds, failure handling, and safe production defaults.

Production LLD structures the domain cleanly:

  • O(log N) Nearest-Spot Heap: Each ParkingFloor maintains a min-heap (heapq / PriorityQueue) per SpotType ordered by distance to the elevator/gate, guarded by a per-floor Lock.
  • Strategy Pattern for Pricing: ExitGate delegates fee calculation to a FeeStrategy (HourlyStrategy, EvChargingStrategy) injected at runtime.
  • Atomic Release on Exit: Paying the ticket marks it PAID and pushes the spot back into its floor's min-heap.
O(log N) Spot Indexing

Per-Floor Min-Heap by SpotType & Distance

ParkingLotRoutes by SpotTypeFloor 1 HeapFloor 2 HeapPage 0F1-01Page 2Page 3

1.Min-Heap Pop: Returns the closest available spot in O(log N) time.

2.Per-Floor Lock: Prevents two gates from popping the same spot concurrently.

3.FeeStrategy: Swaps hourly, flat-rate, or EV pricing without touching Gate classes.

4.Ticket Lifecycle: Tracks ACTIVE -> PAID to prevent duplicate exit releases.

Partitioning min-heaps by floor and spot type keeps allocation O(log N) and isolates lock contention.

class ParkingFloor:
    def __init__(self, floor_id: int):
        self._lock = threading.Lock()
        self._free_spots = {SpotType.COMPACT: [], SpotType.LARGE: []}
    def park(self, vehicle_type: SpotType) -> Optional[Spot]:
        with self._lock:
            return heapq.heappop(self._free_spots[vehicle_type]) if self._free_spots[vehicle_type] else None
public Optional<ParkingSpot> allocateSpot(SpotType type) {
    floorLock.lock();
    try {
        PriorityQueue<ParkingSpot> q = freeByType.get(type);
        return Optional.ofNullable(q.poll());
    } finally { floorLock.unlock(); }
}
05
STAGE 05 · SYSTEM DESIGN APPLICATIONSL7 · STAFF / PRINCIPAL

Where Heap Allocation & Strategy Patterns apply in System Design.

Why this matters: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

The same indexed resource-pool + Strategy architecture appears across real systems:

  • Cloud VM / Container Schedulers: Maintaining priority queues of available compute slots per availability zone.
  • EV Charging & Locker Networks: Thread-safe bay reservation with pluggable tariff strategies.
  • Warehouse Slot Assignment: Assigning nearest-to-dock bins in O(log N) under concurrent picker traffic.
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

How does using a per-floor min-heap with a per-floor lock improve over a single ParkingLot-wide lock and linear scan?

Recommended Learning Flow