ArchitectAI resilience reviews are here. See what's new
Back to all articles
Low Level Design Sep 22, 2026 14 min read

Low Level Design: Parking Lot System with Factory & Strategy Patterns

A deep dive into the quintessential machine coding interview problem. Spot allocation algorithms, multi-level concurrency, vehicle factories, and fee strategies.

LLDDesign PatternsFactory PatternStrategy PatternConcurrency
HFHLDForge Architecture TeamLead Machine Coding Specialist

1. Requirements & Entity Modeling

A parking lot consists of multiple floors, each equipped with dedicated spot types: Motorcycle (Small), Compact (Medium), Large (Bus/Truck), and EV Charging spots. The system handles ticketing at entry gates and fee calculation at exit gates.

  • Vehicles: Motorcycle, Car, Van, Truck, EV Car
  • Spot Types: TwoWheeler, Compact, Large, Electric
  • Pricing Models: Hourly, Flat Rate, Time-of-Day Surge
  • Concurrency: Thread-safe spot allocation preventing double-parking

2. Applying Design Patterns: Strategy & Factory

We use the Factory Method Pattern to instantiate vehicle and spot objects based on sensor telemetry. The Strategy Pattern decouples fee calculation (HourlyFeeStrategy, SurgeFeeStrategy, WeekendFeeStrategy) from ticket checkout.

For spot allocation, a `ParkingStrategy` interface allows swapping between 'Nearest to Entrance' (min-heap) and 'Even Floor Distribution'.

3. Concurrency & Thread-Safe Spot Allocation

When multiple gates issue tickets simultaneously, two cars might be assigned the exact same parking slot. We protect slot allocation using fine-grained locks (e.g. `ReentrantLock` per floor or atomic compare-and-swap on slot status).

typescript
abstract class Vehicle {
  constructor(public licensePlate: string, public type: string) {}
}

class Car extends Vehicle {
  constructor(licensePlate: string) { super(licensePlate, 'CAR'); }
}

interface PricingStrategy {
  calculateFee(durationHours: number): number;
}

class HourlyPricingStrategy implements PricingStrategy {
  constructor(private hourlyRate: number) {}
  calculateFee(hours: number): number {
    return Math.ceil(hours) * this.hourlyRate;
  }
}

class ParkingSpot {
  private isOccupied: boolean = false;
  constructor(public id: string, public floor: number, public type: string) {}
  public occupy(): boolean {
    if (this.isOccupied) return false;
    this.isOccupied = true;
    return true;
  }
  public vacate() { this.isOccupied = false; }
}
Interactive Modeling ArchitectAI

Model this architecture on the HLDForge Canvas

Turn static box diagrams into living, collaborative systems. Drag and drop microservices, Kafka clusters, and cache tiers. Run automated SPOF detection and STRIDE threat modeling in real time.

HF

Written by HLDForge Architecture Team

Lead Machine Coding Specialist

The HLDForge Architecture Team publishes practical engineering guides, real-world case studies, and high-concurrency blueprints to help engineers build scalable and fault-tolerant software.

Free forever plan

Ready to master distributed system design?

HLDForge gives you the tools, templates, and AI reviews to design systems like a Staff Engineer. Get started free.

SOC 2 Type II · ISO 27001 aligned · SSO on every paid plan