List the key functional requirements for the system (Ask the AI for hints if stuck)...
1) there would be different charges for different vehicles (motorcycle, car, bus, EV )
2) when a vehicle enters they are assigned a spot and a ticket is generated
3) User should be able to reserve a spot in advance
4) We should know if there are enough space available else need to display full, digital display boards at entrance/per-floor
5) payment would on timely basis
6) on vehicle exit the bill is calculated and the spot is freed.
7) if a ticket is lost full max fee is charged
8) special spots EV charging spots or handicapped spots
List the key non-functional requirements (performance, scalability, reliability, etc.)...
1) Spot allocation should be instant (under 1000ms) when the vehicle is scanned at the gate.
2) No same spot can be shared between two cars so concurrency is important
3) New vehicle types should be added easily and prices can be altered
System should be highly available and consistent, should be able to support across 1000s of lots across various regions.
display available spot count" across a dashboard, eventual consistency might be fine.
Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
How many parking lots?
-> 5000
Average spots per lot?
-> 500
Average stay time of vehicle
-> 2 hours
Open time
-> 16 hours a day
So basically each spot has been used twice a day
So Turnover rate = 8 times a day
Total spots = 5000 × 500
so we are talking around 2.5M spots
Daily vehicle entries = total spots × turnover/day
Assuming we use 50% capacity on an average all the time
which means 1-1.25M spots are used
Daily throughput then would be x8 around 10M
Entry QPS
1,0000,000 ÷ 86,400 seconds
120 QPS
Double the qps for peak which sits at 240 QPS
Storage estimation
A ticket/record: vehicle plate, entry time, exit time, spot ID, fee, payment status — maybe ~200 bytes - 1KB per record.
Around 10M daily entries a day
About 365 GB per year (10M × 365 × 1 KB).
~10-15 TB/year including replication overhead
Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...
A Client / Edge device (a driver's app, or the gate's ANPR camera and controller) sends a request to a Load Balancer, which spreads traffic across instances of the API Gateway. The gateway routes each request into the MicroServices boundary, which holds five services: Reservation, Ticket, Parking, Payments, and User.
SELECT ... FOR UPDATE SKIP LOCKED on a free spot of the right type (EV, handicapped, and so on). It marks the spot HELD, inserts a reservation with status PENDING_PAYMENT, and commits. The database is the source of truth here, so this step prevents double-booking.CONFIRMED, and an event goes onto the Queue so Notification sends the confirmation.OCCUPIED.Ownership summary: Parking owns reads, Reservation owns the hold and its state, Payments owns money, Ticket owns entry and exit, and Notification owns messaging.
The outbound call alone leaves the reservation stuck in PENDING_PAYMENT if the response is lost. Close the loop three ways:
PaymentSucceeded or PaymentFailed to the Queue. Reservation consumes the event and updates its status.Define the data model. Identify the main entities, their attributes, and relationships. Consider the choice of database type (SQL vs NoSQL) and justify your decision based on access patterns...
q. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
1. Spot allocation
lot_id so allocation is a single-shard transaction.SELECT ... FOR UPDATE SKIP LOCKED on a free spot, so concurrent gates lock different rows and never double-book.2. Availability (Redis)
3. Reservation lifecycle
PENDING_PAYMENT → CONFIRMED → CHECKED_IN → COMPLETED, plus EXPIRED and CANCELLED.