parking
GET /parking/?query_param as
[{
parking_spot, status, vehicle_number, parking_allowed_till,
}]
POST /parking/:parking_id/reserve
Rquest payload
{
"registration_number":
"mobile_number": <>,
"username": <>
}
POST /parking/:parking_id/pay
Response
{
"msg": SUCESS/FAILED
}
POST /parking/:parking_id/park
Req payload
{
"vehicle_number": <>
}
POST /vehicle/
POST /vehicle/
Core Constraints
GET listing can be directly fetched from DB
parking table can be queried using status = AVAILABLE
POST /reserve
parking spot can be reserved from user
Concurrnecy handling
Its possible that more than 2 users try to reserve a spot, hence we can take a pessimistic locking on DB
This way no 2 users would be able to take action
checkin
checkout
These 2 APIs are straightforward just updating fields in the parking table
Validation can be whether these spots are in RESERVED state or not
1st deep dive-
Flaw with existing reserve
Taking lock on DB level can be cruelsome for DB . we would be blocking the status of the parking spot until payment is done, which can be dependent on Payment GW. Transaction and lock will be blocked till API receives the response
Introduce redis instead.
create a key
This way other req will first check if the key exists, and if yes that means parking_spot is already under some operation
2nd DD -
On reservation, 2 cases are possible