< 10 ms
scale
1000 spots
10000 users
Read vs reserve request 10:1
10 get requests per second
1 parking request per second
get /parkingspots?type={} -> [parkingspot]
post /parking/{parkingspotid}/reserve
-> ReservationId & statuscode
201 for created or 404 not found
// webhook
post /paymentdone/
{
reservationid
}
get /reservationstatus/{reservationId}
-> Succeeded | Failed| Cancelled
get /booking/{reservationId}-> reservation
patch /parkingspot/{id}
{
status - occupied | Available
} -> HttpStatusCode
Entities
User
ParkingSpot
Reservation
parking service will be used for managing vehicles that enter the parking spot.
Postgres will be used as database
Reservation cleanup janitor service will cleanup old reservations
Parking reservation service will handle reservations
Parking fetch service will handle fetch of the available parking spots
parking reservation service
parking reservation flow
Distributed lock will be taken on the node that is handliing all the requests. We dont' need a separate redis instance for this as the volume is low
parking service entry
parking service exit
Parking slot fetch service
If the reservation stastus is completed but the current Time is greater than the reservation time, that means no o ne has come for the erservation and we can give the resrvation of the parking slot to someone else.
Database design
User - userId(PK), name
ParkingSlot - id(PK), Type(secondary index)
Reservation- resevationId(Pk), userId,
parkingSlotId, startTime, endTime, Status
Query to see if there are overlapping reservations
select * from Reservation where parkingSlotId=id && !(startTime >= currentEndTime || endTime<= currentStartTime) & Status == Completed &&
( currentTime < startTime )-> Overlapping reservations
project count(*)
if count > 0 -> can't do reservation
query to get free parking slots
select * from Resevation where && !(startTime >= currentEndTime || endTime<= currentStartTime) & Status == Completed &&
( currentTime < startTime )
| project parkingSlot
| get all parking slots from parkingslot table which are not in parkingSlot table and of type specified
Reservation cleanup service
This service wil lcleanup old reservations