Estimate the scale of the system you are going to design...
DAU : 5000
each Spot Query Size : 100B
There is 5000 of spots
Storage Expectation : 100B * 5000
Define what APIs are expected from the system...
/api/allocate
ReqBody :
{
Vehicle Type
Time Duration
}
ResBody :
{
Ticket ID
Expiration Date
Expected Fee
}
//if invalid or no free spot -> response with failed to allocate
//Success : 200
//Failed By Client : 400
/api/release
ReqBody :
{
ticket ID
}
ResBody :
{
Fee Charged
}
//if ticket not found -> response with failed to process
// Success : 200
// Failed By Client : 400
Ticket
Spot
Device (User)
Client goes to App server for request and there should be database processing the request and return the response
We will use DB as RDBMS because it is good to use if there is relations between the data.
There can be multiple server as horizontal scaling with load balancer.
Allocate Spot
Release Spot
Notification Service
Application server will handle internally to find free spots for specific vehicle type
Also Application Server takes all the tickets which have 30 min left from expiration dates and send it to messaging queue to send notification to device (user)
After release the spot, process the purchase the charged fee through external API (we can use stripe or Square for it)
I used RDBMS for storing ticket and spot and device metadata because they have relations between them. I use messaging queue which is able to handle large set of request to services asynchronously.
If we use load balancer to handle request to multiple servers, it can be single point of failure. Because Database and server continuously handles the expiration dates to send notification, it can be bottleneck.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?
We can use multiple LB to prevent single point of failure. Database can be sharding using consistent hashing. We can implement feature of user to make over durated parking lot charge. To improve security, it is also good to implement authentication and authorization system.