System requirements


Functional:

It has to support:

  • vehicle enters
  • vehicle exists
  • parking allocation
    • supports different types of vehicles
    • prioritize convenience for users



Non-Functional:

It's a city center parking lot that should support 500 to 1000 vehicles daily. It's medium size so has 200 spaces. Cars will stay 3-5 hours on average.





Capacity estimation


Assuming 80 vehicles per hour entering

we would get a TPS of 1/100 for cars entering and leaving.








API design


VehicleType{

COMPACT, REGULAR

}


QueueTicket{

String ticketId

}


ParkingTicket{

String ticketId

}


QueueTicket enterParkingLot(String vehicleId, VehicleType vehicleType)


ParkingTicket pollIfSpaceIsReady(QueueTicket ticket)


void leaveParkingLot(String vehicleId, ParkingTicket ticket)



Database design

We need a separate persistent fifo queue (like Kafka) for each type of vehicle. Let's call this queue incomingVehicles. We also need a separate persistent fifo queue for each type of vehicle with available spaces for this type of vehicle. Let's call this one availableSpaces. We need a table TakenSpaces that would have a primary key ticketId.




High-level design








Request flows

Cars enter by calling enterParkingLot() that would give them a QueueTicket , and then they should call pollIfSpaceIsReady every 5 seconds until a parking space becomes ready. Then when the car





Detailed component design

Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...






Trade offs/Tech choices

Explain any trade offs you have made and why you made certain tech choices...






Failure scenarios/bottlenecks

Try to discuss as many failure scenarios/bottlenecks as possible.






Future improvements

What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?