POST /parking/:location/submit -> reservation_id {
user_id: string
car_type: int
car_size: int
start_time: ISO 8601
end_time: ISO 8601
}
POST /parking/modify -> confirmation {
reservation_id: string
end_time: ISO 8601
}
GET /parking/view_reservation -> reservation_details {
reservation_id: string
}
This design is ammenable to a relational database. As mentioned previously a basic SQL database like postgreSQL is probably sufficient.
We can multi index based on reservation start time, user_id, and reservation_id since queries will most likely target a range of dates or a particular user or reservation ID.
The throughput of the system is not that high but if we can add some redundancy via replication that is natively supported by postgreSQL
Simple client talking through an API gateway to the server should be sufficient. There's no real need for too many multiple servers but it would be useful to have a replication of servers for robustness. Server receives RESTful commands and translates them to database updates or lookups and queries the postgreSQL database.
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...
The most likely to be scaled part of this design is the parking request and update. This can easily be scaled horizontally by sharding the database by geographical location and having a server handling each of the geographical locations.
Similarly, we can speedup reservation lookup requests by using something like redis to cache currently valid parking requests up to the furthest out in the future we allow reservations in a circular buffer and update every hour by removing the reservation reqeusts that have expired and adding new ones that were requested.
At the same time as updating the most recent valid requests, we can prevent parking conflicts by keeping a count of open parking spots for each car size in each car lot when updating the circular buffer. We reject reservation requests when the count for that car size in that parking location is 0.
Large scale events like solar eclipses or some other event may cause heavier traffic than normal. Since we cannot physically increase the size of available parking lots we will just have to reject requests if a parking location is full. Also throughput increases should not have too large of an impact if we have implemented geographical sharding since even a 10000% increase in a particular location of about 200 parking spots will only incur about a few MB of data flow.
We should eventually add a way to recommend close parking spots in the case a desired location is full.
We can also add analytics to understand where best to add new parking lots.