AlgoMaster Logo

Design Parking Lot

Ashish

Ashish Pratap Singh

easy

A parking lot is a designated area where vehicles can be parked temporarily, either in public or private spaces.

Parking Lot

It may consist of multiple floors, and each floor contains a fixed number of parking spots. These spots are often categorized by vehicle size such as small, compact, or large.

When a vehicle enters the parking lot, a parking ticket is issued to record the entry time. Upon exiting, the vehicle owner pays the parking fee.

In this chapter, we will explore the low-level design of a parking lot system in detail.

Let's start by clarifying the requirements:

1. Clarifying Requirements

Before starting the design, it's important to ask thoughtful questions to uncover hidden assumptions, clarify ambiguities, and define the system's scope more precisely.

Here is an example of how a discussion between the candidate and the interviewer might unfold:

After gathering the details, we can summarize the key system requirements.

1.1 Functional Requirements

  • Support multiple parking floors, each with a configurable number of parking spots.
  • Support multiple vehicle types, including bikes, cars, and trucks
  • Classify parking spots by size (e.g., Small, Medium, Large) and match them with appropriate vehicle types
  • Automatically assign parking spots based on availability
  • Issue a parking ticket upon vehicle entry and track entry and exit times
  • Calculate parking fees based on duration of stay and support different pricing strategies, such as flat-rate or vehicle-type-based pricing.
  • Support querying and displaying real-time availability of parking spots, grouped by floor and spot size.
  • Parking requests can be hardcoded in a driver/demo class for simulation purpose.

1.2 Non-Functional Requirements

  • Concurrency: System should handle concurrent entry/exit events without causing race conditions or data inconsistencies.
  • Scalability: System should be scalable to support large parking facilities with hundreds or thousands of parking spots.
  • Extensibility: The design should be flexible enough to support future enhancements, such as adding new floors, introducing additional vehicle or slot types, or supporting new pricing strategies.

After the requirements are clear, the next step is to identify the core entities and objects we will have in our system.

2. Identifying Core Entities

Premium Content

This content is for premium members only.