A car will be given a ticket upon entry.
A car will be assigned a lot upon entry.
Car be denied if no space exist.
Cars fall into certain category will be prioritized to certain sections.
System should have high availability and consistency.
Suppose truck space is 3 times of a standard car, and a handicap occupies 2 car sizes.
Suppose we are making 1000 spaces. Assuming ~10000 daily car visits. QPS < 1. A single server should be sufficient to handle this low QPS.
enter_garage(car_category, license) -> NoAvailable Space exception or space number
exit_garage(license)
No SQL Database
lot_id: licence_plate
car_type: enum
entry_time: epoch
exit_time: epoch
lot_id: id
No SQL Database
lot_id: id
metadata: {
type: enum
condition: ...
location: ...
}
Database: store the car entry information and lot information. Lot information will most likely be ReadOnly as the lot information will not change unless the the parking structure changed.
Cache: cache will be the primary storage for parking space info. It will contain a few dictionaries. For instance: Car -> [ available_lot ids ], it can be using things like Redit.
A car visits the garage,
Let's talk about car lot assignment.
Once the car reaches the gate, the system will capture the car type (Car, Truck, Handicap) and licence plate. The front end will send a assign request to the PL system. The PL System will read the cache to find available parking lots according to the given category. If the space does not exist, it will through exception back to the requester. If there is a space exists, it will create an assignment entry in the licence plate database. Next, it will remove the item from cache.
If a car exists the PL, PL will read the entry using licence plate. It will void the parking lot assignment and gives the parking lot back to the cache before releasing the vehicle.
The design is supposed to handle concurrency issues because we are using a Redit. We should use a thread-safe hashset to avoid the samelot being assigned twice.
Explain any trade offs you have made and why you made certain tech choices...
If two cars use the same licence plate, this will be an error. The second car should be denied. All our assumptions are being made upon that no car will have the same licence plate.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?