System requirements


Functional:

  1. User can reserve a parking lot
  2. User can pay for a reservation
  3. User can park car in the park lot



Non-Functional:

  1. Scalability: the system operates for multiple countries
  2. Reliability: the system should be 99.9% available for user to make reservation
  3. Security: the system should protect cars to be broken or stolen
  4. Consistency: once user make the reservation, the parking lot is available to user and unavailable for others.



Capacity estimation

  1. the system has parking lots in 10 countries
  2. In each country, there are 100 parking lots
  3. On average, each parking lot can park 200 cars
  4. On average, 80% users park for 4 hours
  5. On average, 20% users park for 5 days
  6. Each parking lot receives 200 reservation request each day

Estimation

  1. total parking lots: 100 * 10 = 1000
  2. The system receive : 1000 * 200 = 200000 reservation each day
  3. Each reservation need roughly 128 bytes
    1. reservation ID: 8 byte
    2. user ID: 8 bytes
    3. car type: 1 byte
    4. start time: 8 bytes
    5. end time: 8 bytes
  4. Each day, new data is 128 * 200000 = 25.6M
  5. In two years, the data will add up to 25.6 * 365 * 200K * 1.5 =27.6P



API design

Define what APIs are expected from the system...


  1. List parking lots
    1. Input: city
    2. Output: park lots in the city
  2. List available parking spaces in a parking lot
    1. Input: park lot ID
    2. Output: parking spaces with status
  3. Reserve a parking space
    1. Input: parking lot ID and space ID
    2. Output: success or failure of the reservation
  4. Complete a reservation:
    1. Input: Parking lot ID and space ID
    2. Output: success of failure of the operation. Fee to be paid
  5. Cancel a reservation
    1. Input: Parking lot ID and space ID
    2. Output: success/failure of the operation. Fee involved
  6. Car checkin:
    1. Input: car ID, parking lot ID, space ID. time
    2. Output: success/failure of the operation.
  7. Car checkout:
    1. Input: car ID, parking lot ID, space ID, time
    2. Output: success/failure of the operation



Database design

  1. Reservation table
    1. Reservation_id
    2. user_id
    3. start_date
    4. end_date
  2. Slot table
    1. slot_id
    2. lot_id
    3. location
    4. vehicle_type
    5. status
  3. ParkLot table
    1. lot_id
    2. capacity
    3. city
    4. address
  4. Vehicle table
    1. vehicle_id
    2. vehicle_type
    3. contact_id
  5. Contact table
    1. user_id
    2. user_name
    3. user_email
  6. User table
    1. user_id
    2. user_name
    3. user_email
  7. Transaction table
    1. transaction_id
    2. user_id
    3. vehicle_id
    4. start_date
    5. end_date
    6. amount
    7. status



High-level design

  1. User
  2. Parking lot entrance system
  3. API gateway
  4. reservation service
  5. payment service
  6. transaction service
  7. database
  8. cache





Request flows

  1. User make reservation:
    1. User list parking lots in the city
    2. User view available of spaces in a parking lot
    3. User make reservation
    4. The system save the reservation information
    5. User is confirmed about reservation
  2. Char check-in
    1. Car arrives at parking lot
    2. The parking lot entrance system send information about user, car ID
    3. The system confirm the validity of reservation and allow the car to enter. Start counting fee.
    4. The parking lot entrance system allow the car to enter.
    5. The monitor of the slot detect car coming and send car ID
    6. The system confirm the car parked is the same as what is reserved and updating the resevation and trnasaction information





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?