With 500 maximum vehicles parking at any time, the capacity isn't very large. If a car is parked for 1 hour on average, then there can be at most 24 * 500 = 12000 entries and exits per day. There are 86400 seconds in a day, which means the entry and exit QPS is roughly 0.14 QPS.
In terms of storage, we can for now assume that at the very basic level, we will need to store the plate number of each car, and we will at most store 500 plate numbers.
GET /parking/spaces
POST /parking/ticket
body {
timeWindow: number,
carPlate: String
}
PUT /parking/exit
body {
ticketId: id
}
The main components will be:
I can store all of this information in a SQL database. The schema and data that we need is predictable, hence Relational DB is a good option.
Currently the system is prone to data loss since it's a single server and a single DB component
We can scale horizontally the parking system to have multiple servers running for redundancy in case a server goes down. In order for the client to know which server to make a call to, we can introduce load balancer layer which will keep track of running servers and will spin up a new instance if a server goes down.
Additionally, the database is also a single point of failure, so I want to have the database replicated multiple times, say 5 times, to ensure fault tolerance of data.
The system cannot tolerate loss of car plates at any point, so we will want to have each request be a transaction and abort on failure and ask the user to retry. Each request write request will write to all 5 replicas within the same transaction to ensure full consistency.