System requirements
Functional:
- User to login
- Looking for consistency & availability
- User can make a reservation / booking a parking slot
- User can have vehicle types
- User can select Parking lot
- space type => ( Regular, Handicap )
- Payment is integrated with third party - like stripe
Non-Functional:
- We want to have a high availability -> meaning everytime the users wants the system to be highly available -> with low latency
Capacity estimation
- Daily active usages of a user wanting to have a space => 2
- Maximum spaces in Parking Lot => 15000 Spaces
- 30000 reservations per day
- 2000 requests / hr -> throughput
API design
Base Url: api/v1
End points:
- POST -> /reservation -> { user_id, space_id, vehicle_type, is_paid, start_time, entry_id, exit_id }
- GET -> /availability -> { no_of_available_spaces, spaces_type )
- POST -> /user -> { name, email, phone_number }
- GET -> /invoices -> { reservation_id, amount_paid, reference }
Database design
MySQL - Relational Database
- users
- id -> primary key, auto-increment, indexed, Not Nullable
- name -> varchar
- email -> varchar(255)
- parking_lots
- id -> primary key, auto-increment, indexed, Not Nullable
- name -> varchar
- postcode -> varchar
- address -> varchar
- entries
- id - primary key, auto-increment, indexed, Not Nullable
- parking_lot_id: foreign key
- entry_reference -> varchar
- entry_name -> Entry - 1, 2, 3, etc
- exits
- id - primary key, auto-increment, indexed, Not Nullable
- parking_lot_id: foreign key
- entry_reference -> varchar
- entry_name -> Entry - 1, 2, 3, etc
- reservations
- id - primary key, auto-increment, indexed, Not Nullable
- user_id
- vehicle_type: enum ( regular, compact, XUV, Truck )
- paid: boolean
- start_time: Datetime stamp
- end_time: Date time Stamp
- spaces
- id - primary key, auto-increment, indexed, Not Nullable
- parking_lot_id: foreign key
- space_type: enum(( Regular, Handicap )
- cost_per_hour: double
- invoices
- id - primary key, auto-increment, indexed, Not Nullable
- reservation_id
- amount
- paid
High-level design
Client App -> Load Balancer -> Booking Service
-> Invoice Service
-> Payment Engine Service
-> Notification Service
-> Redis Cache for Parking & Entries and exists -> can be fetched also from read replica
-> available spaces are pushed into elastic search ->
-> if a space is released or booked, it can be re indexed in real time too
-> Use Scheduler to generate invoices or notification services
-
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?