Size of parking lot: 500
Average duration of parking per vehicle: 4 hours
Turnover rate of parking spot: 3 times per day
Daily active users = (500 * 3) / 4 = 375 DAU
User:
Vehicle:
ParkingSession:
You should identify enough components that are needed to solve the actual problem from end to end. Also remember to draw a block diagram using the diagramming tool to augment your design. If you are unfamiliar with the tool, you can simply describe your design to the chat bot and ask it to generate a starter diagram for you to modify...
Components:
Booking a parking spot:
Enter garage:
Exit garage:
Extend parking spot:
Cancel parking spot:
Parking Spot Checker:
Database:
Consistency would be key especially when payment is involved. For this reason, we want to have a good replication strategy in place for the databases. We can have 1 write database that would synchronously write to the read database as well as a replica in case one of them fails. In this case, the replica could take over. We can utilize primary-secondary replication.
Cache:
We could use an LRU cache for this application so that we are not needing to fetch data from the database when it comes to upcoming parking sessions. We can also evict when a parking session is completed.
Parking Spot Checker:
This service would be a scheduled task runner where it would run every 15 minutes and check for whether a parking spot is coming to an end or if the user is over their allotted time for parking. Each of these situations would send a push notification to the user. When a user is over their allotted time, we can also enforce fines or overtime fees.
The replication strategy we use for our database has a performance trade-off that i believe is necessary for us to have strict consistency when it comes to user parking. This is because there is money involved and using an asynchronous replication strategy can lead to lost data, where we have already taken money from the user.
I see Parking spot checker being an issue where it can put a lot of stress on the on the database.
In such a case, it may be a good idea to put a cache in the middle where we populate the cache based on active parking sessions.