Here is how to address each specific requirement from the image:
Allow reservation of a parking spot
Action: User searches for a lot and reserves a spot for a specific timeframe.
Implementation: The Reservation Service checks the Availability Cache (Redis). If a spot is free, it creates a record in the Reservations Table with a PENDING status until payment is confirmed.
Key Detail: Use a Distributed Lock on the LotID to prevent two users from booking the last available spot at the same microsecond.
Process payment for the reservation
Action: Securely handle transactions.
Implementation: The Payment Service interacts with an external Gateway (Stripe/PayPal).
Workflow: Once the webhook from the payment provider returns Success, the reservation status is updated to CONFIRMED, and the spot is officially "locked" for that user.
Enable parking of a car in the reserved spot
Action: Mapping the digital reservation to a physical space.
Implementation: Upon Gate Check-in, the system assigns a specific Spot_ID (if spots are assigned) or simply decrements the Available_Count for that lot.
Hardware Sync: The IoT sensor at the stall detects the vehicle's presence and updates the Parking_Spot_Status to OCCUPIED.
Support early departure before reservation time expires
Action: User leaves before the scheduled end time.
Implementation: When the Gate Check-out is triggered, the system calculates the actual duration.
Business Logic: If the policy allows, the Payment Service can issue a partial refund or simply release the spot back to the "Available" pool immediately to maximize lot occupancy.
Gate check-in/out
Action: Physical entry and exit.
Implementation: * Check-in: User scans a QR code or License Plate Recognition (LPR) identifies the car. System validates the Reservation_ID.
Check-out: System verifies that the balance is zero (paid). If yes, the Gate Controller receives a signal to open.
Handle no show
Action: User reserves but never arrives.
Implementation: A Cron Job or TTL (Time-To-Live) index monitors reservations. If a user hasn't checked in within X minutes of the Start_Time, the status changes to EXPIRED/NO_SHOW.
Define the system constraints to ensure stability and performance.
| Method | Endpoint | Description |
GET | /v1/parking-lots | Search for nearby parking lots based on GPS. |
POST | /v1/reservations | Reserve a spot (userId, lotId, vehicleType, startTime). |
POST | /v1/entry | Triggered by gate sensor to record check-in time. |
POST | /v1/exit | Triggered by gate sensor to calculate fee and check-in payment. |
POST | /v1/payments | Process transaction via external providers (e.g., Stripe). |
A microservices architecture is preferred for independent scaling.
When two users try to book the last spot simultaneously, we must ensure only one succeeds.
SELECT ... FOR UPDATE) in the RDBMS or a Distributed Lock (Redis) on the lot_id. This ensures the decrement of available spots is atomic.As the number of parking lots grows, a single DB instance becomes a bottleneck.
Location_ID or City_ID. This keeps related data close together and allows the system to scale horizontally.