Design a Parking Lot system

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2022-05-18

Problem Statement

Design and implement a Parking Lot System to manage parking spaces, vehicle entry/exit, and payments. Focus on efficient space allocation, vehicle tracking, and extensibility for multiple floors or types of vehicles.


Functional Requirements (FR)


Parking Lot Management


•Support multiple floors/levels.
•Different types of slots: compact, regular, large, handicapped, EV charging.
•Track available and occupied slots in real-time.


Vehicle Management


•Vehicle entry/exit with automatic slot assignment.
•Support different vehicle types: car, bike, truck, electric.
•Record entry/exit time for billing.


Payment Management


•Calculate parking fees based on duration and vehicle type.
•Support multiple payment modes: cash, card, mobile wallet.
•Optionally, integrate with prepaid or subscription plans.


User Management (Optional)


•Allow registered users with faster entry/exit.
•Maintain history of parked vehicles.


Notifications (Optional)


•Notify when slots are full or reserved.
•Alerts for exceeded parking time.


Non-Functional Requirements (NFR)


•Performance → Real-time slot assignment and availability updates.
•Scalability → Support multiple parking lots or large multi-floor lots.
•Availability → Ensure system works 24/7.
•Reliability → Prevent double allocation of slots.


Core Entities & Attributes


ParkingLot


•lotId, name, location, floors[]


Floor


•floorId, level, slots[]


ParkingSlot


•slotId, type (compact/large/EV), isOccupied, vehicleId


Vehicle


•vehicleId, type (car/bike/truck), licensePlate


Ticket / ParkingSession


•ticketId, vehicleId, slotId, entryTime, exitTime, amount, status


Core Components


ParkingLotService


•Manage floors and slots.
•Track overall availability.


SlotAssignmentService


•Assign nearest available slot based on vehicle type.
•Free slot when vehicle exits.


PaymentService


•Calculate fees and handle transactions.


VehicleService


•Track vehicles entering/exiting and issue parking tickets.


NotificationService (Optional)


•Alert users for slot availability or exceeded time.


APIs / Operations


ParkingLot APIs


•addParkingLot(lotDetails)
•getAvailableSlots(lotId, type)
•getParkingLotStatus(lotId)


Vehicle & Slot APIs


•parkVehicle(vehicle) → Assign slot, generate ticket
•exitVehicle(ticketId, paymentDetails) → Release slot and process payment
•getVehicleTicket(vehicleId)


Payment APIs


•calculateFee(ticketId)
•processPayment(ticketId, paymentMode)


LLD Design Goals


•Class Diagram → ParkingLot, Floor, ParkingSlot, Vehicle, Ticket, Services.
•Design Patterns:
•Singleton → For central ParkingLot instance.
•Factory → For creating vehicles and tickets.
•Observer → Notify users about slot availability.
•Concurrency Handling → Thread-safe slot assignment to prevent double allocation.
•Trade-offs →1. Real-time slot assignment vs. pre-reservation system. 2.Memory vs. performance for tracking slots in large parking lots.


Solution

Comments