System requirements


Functional:

  1. Enable users to reserve a parking spot for themselves and park in the spot.
  2. Once user reserves a spot they will get a parking ticket.
  3. Users will have to pay for the parking spot, the payment will be dependent on the amount of time and the type of vehicle of the user.
  4. Users will be able to see the total number of available and occupied parking spots.
  5. If none of the spots are free user will get a validation when trying to reserve a spot.
  6. If multiple users are coming in for a parking spot we will use FCFS algorithm.
  7. Users can pay via the application or by cash at checkout.



Non-Functional:

  1. The system will need to be consistent and it cannot be eventually consistent as if a parking spot has been assigned to a user it cannot be assigned to any other user.
  2. Some amount of latency will be involved in the system as we will need to ensure that the write operation completes for a parking spot.
  3. The system should be fault tolerant.




Capacity estimation

  1. we can consider each building to have 10 floors and each floor has 100 parking spots.
  2. we can consider daily active users as 1 million across the globe with multiple buildings across the world using our application.
  3. If we consider registration data such as building number, floor number, spot number to be 2 KB for each registration and each user registers 2 times in a day we will have 2 KB * 2 million requests per day for parking registration.
  4. This seems to be a write heavy system as mainly users will be registering for parking spots.





API design

  1. /register - This API will help the user register in the system and add his details such as user metadata and vehicle details.
  2. /login - This API will validate user credentials and help the user login to the system.
  3. /book-spot - This api will help the user book a parking spot, this will take the details of the user such as vehicle type and return the floor and the parking spot which has been booked for the user.
  4. /cancel-booking - This API will help user to cancel his booking for parking in case it is not needed.
  5. /parking-board - This API will get the data for a parking buidling regarding the number of total spots which are remaining for parking.
  6. /payment - This API will help processing of payments from the user accounts, this is an internal API which will then call the payment vendors for processing.
  7. /parking/add-spot This API is for the ADMIN user of the application for adding a parking spot on a particular floor.
  8. /parking/delete-spot - This API will remove a spot on a particular floor to be booked for parking.





Database design

  1. We can go for a postgres database as we need to store mappings between the user and the parking booked by the user.
  2. We can have a registration table which will store details for every booking, the columns will include, building_id, floor_id, booking_id, user_id.
  3. We will have a user table which will store the user metadata with user_id being the primary key to be used for joins.
  4. We will have a ticket table which will store the details of every ticket generated for the user, these details will include vehicle_license_number, vehicle_type, parking_spot_number.
  5. There will also be tables for building, floors and spots.
  6. Building table can be a partitioned table on the basis of zip_code this will help us to send requests for a particular area to the respective partition.





High-level design

You should identify enough components that are needed to solve the actual problem from end to end. Also remember to draw a block diagram using the diagramming tool to augment your design. If you are unfamiliar with the tool, you can simply describe your design to the chat bot and ask it to generate a starter diagram for you to modify...






Request flows

Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...






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?