Total no of parking lots: 1000
Capacity of each parking lot: 200
200K daily new reservations
Total data size for each reservation = ~200B
Data stored everyday = 200B * 200K = 40MB
Data store in 2 yrs = 40MB * 365 * 2 * 1.5(considering growth) = 43GB
Estimation leads us to relational database like SQL or PostgreSQL.
RDBMS provides strong consistency which is required for the system
checkAvailability(): Checks whether a given parking spot is available for reservation
Input: lotId, reservationStartTime, reservationEndTime, vehicleType
Output: status
reserveSpot(): Reserves a spot for the user
Input: userId, spotId, reservationStartTime, reservationEndTime, vehicleType
Output: reservationId
vehicleEntry(): Tracks entry of vehicles
Input: reservationId, timestamp of entry
vehicleExit(): Tracks exit of vehicles
Input: reservationId, timestamp of exit
payment(): Allows user to make payment. Integrated with 3rd party
manageReservation(): Allow user to manage/delete a reservation
ReservationDetails:
User:
Spot:
Lot:
VehicleType:
Client: Sends request for reservation
Reservation Service: Handles reservation requests
Payment Service: Handles payment for reservation
Stripe: 3rd party payment integration
MySQL: Relational database for consistency
Check availability:
Reserve spot:
Make payment:
Manage reservation:
API gateway: Handles API routing to different services
We can have multiple instances of servers across different zones to handle client requests from different regions.
We can also shard database based on lot ids. This helps handle increased load in case of events or high traffic
Consistency over availability: We want our system to be highly consistent to avoid double booking. A small delay in response for make reservation request is acceptable but we shouldn't let 2 users book the same spot.
Data estimation and choice of consistency, leads to use relational database over nosql database.
Relational database provides high consistency and is suitable for our data estimations and growth.
NoSQL databases are suitable for large amount of data, eventual consistency and high scalability