My Solution for Design an Efficient Parking Lot System with Score: 8/10

by celshya

System requirements


Functional

  1. User parks a vehicle
  2. User unparks the vehicle
  3. Admin need to monitor the available spots
  4. payment ssystem based on timing
  5. ticket generation with vehicle detail
  6. supporting different vehicle types(car,bike,truck)
  7. real time spot availability




Non-Functional:

  1. scalability : In case if further floor increases. we should able to update the lots and spots
  2. accessibilty : It should be easily accesible by the customer
  3. reliability : Fault tolerance and payment should be error free
  4. avilability: Hightly available for the customers



Capacity estimation


let's assume as of now

  1. 1000 spots per floor
  2. we have 3 floors for cars
  3. which should be 3000 spots
  4. 1 floor designated for bike where it is 2000 bikes can part.



API design

  1. POST <domain>/park

request : {

vehicleType:"Car",

VehicleNumber:"TN 07 AG 4567",

owner:{

name:"John",phone:12376t77

}

}


response : {

parkingStatus: Parked

InTime:02:45pm

ticketId:4567

}



2.POST /unpark


request: {

ticketId:4567}


response:{

outTime:4:56pm,

charge:"100rs",status:"success"}


3.GET /availability

response:{

totalavailability:3000,typebased:{

car:500,bike:200,truck:300

}}


4.GET/{lotid}/monitor


response : {


totalaspots:3000,

available:2000,

occupancyrate:30%


}



Database design

  1. customer/owner: id, name,ohone,vehicletype,number
  2. parking lot : id,location, floor, spotnumber,vehicletypeallowed, status(available/occupied)
  3. vehicle: id,type,number, owner
  4. parkingTicket: id,vehiclenumber, intime,outtime,charge




High-level design

Parking Lot Service: Responsible for managing parking spots, floors, and lots.

Vehicle Service: Manages vehicles and parking.

Payment Service: Calculates and processes payment.

Admin Service: For monitoring parking lots and viewing reports.

Notification Service: Sends real-time notifications for alerts.

Reservation Service: Manages spot reservations in advance.


Request flows

  1. parking a vehicle: user sends a request to park a vehicle. parking service accepts vehicle type and check the parking service if place available. once it checks the avialbilty it gives the spot number along with the ticket. and make the spot occupied
  2. unpark a vehicle: User requests for unpaking a vehicle. parking service locate the vehicle based on the ticket id where it contains the spot.It calculates the outtime - intime and provide the payment service for calculating this provide price. after succesful payment spot is available now customer can unaprk now





Detailed component design

  1. parking spot allocation:

to efficiently allocate availability location also nearest. DSA = we can go for minheap wehere we can check neares available spots also we no need to over allocate in one lot.

handling spot reservation : it is like special place for VIP we can use priority queue and can allocate some space for them it can be occupied only if all the normal occupied and no vip reservation so far. for large lots system can divide into zones like north spot, south spot.

  1. payment processing: This is mainly to determine partking fares based on timing , dynamic fare, discounts, for hourly rate. (exit time - entrytime )* hourly rate. also based on the customer type vip or premium we can provide discounts on fare.They can subscribe to mopnthly pass if they visit often this acts as discounts. we can have third party payment gateway like paypal to do this payment activity. Late payment fees can be added. Also add a flag for vehicle if not paid fare for future entry.





Trade offs/Tech choices

sql -since the data are structural

redis - for caching spot availability

concurrency to handle the different floors in spearte pipes





Failure scenarios/bottlenecks

  1. there could be possible of payment failure. we can have multiple option for payment cas, upi or card also rollback if paymet issue
  2. availability should be error free.





Future improvements

  1. dynamic pricing
  2. indicate from ground floor which floor and which spot available in a monitor
  3. integrate with gps.
  4. real time spot tracing using license plate