Design a parking lot

Design the classes for a multi-floor car park that assigns spots, issues tickets and charges fees.

Why interviewers ask it

It's the classic first LLD question: the entities are clear, there are natural places for patterns (pricing, spot assignment), and there's a real concurrency problem.

Functional requirements

Non-functional requirements

From version 1 to the final design

  1. Version 1: one floor, one gate, one spot size, a flat fee. Classes: ParkingLot, Spot, Vehicle, Ticket.
  2. Version 2: several spot sizes and vehicle types, a rule for which vehicle fits which spot, and pricing as a strategy.
  3. Version 3: several floors and gates, with display boards observing the free counts.
  4. Version 4: concurrency — claiming a spot atomically — and storing state in a database so gates on different servers agree.

The design, step by step

  1. Entry: a vehicle arrives → the assignment strategy finds a free spot that fits → the spot is marked taken in one atomic step → a ticket is issued.
  2. Exit: scan the ticket → the pricing strategy works out the fee from the time parked → payment → the spot is freed.
  3. Display boards subscribe to spot changes (Observer) and update their counts.

Deep dives

Common mistakes

Not true: Pricing rules: kept inside the Ticket class.
In fact: Prices change often, and for many reasons. Keep them in a separate pricing strategy, so that a new tariff does not touch Ticket or Vehicle.

In the interview

Core classes: ParkingLot, Floor, Spot, the Vehicle types, Ticket and Payment. Spot assignment and pricing are strategies, so the rules can change without touching the rest. Parking is one atomic step — a lock or a compare-and-set — so two gates can't take the same spot. Display boards observe spot changes.

Part of Unit 7: Low-level design questions in the free System Design course.