POST /reservations
Request
{
"licensePlate": "30A12345",
"vehicleType": "CAR"
}
Response
{
"reservationId": "R123",
"slotId": "A-101",
"expiresAt": "2026-06-04T10:15:00Z"
}
GET /reservations/{reservationId}
Response
{
"reservationId": "R123",
"status": "ACTIVE"
}
DELETE /reservations/{reservationId}
POST /reservations/{reservationId}/check-in
Converts a reservation into an active parking session.
POST /entries
Request
{
"licensePlate": "30A12345",
"vehicleType": "CAR"
}
Response
{
"ticketId": "T123",
"slotId": "A-101"
}
POST /exits
Request
{
"ticketId": "T123"
}
Response
{
"amount": 50000,
"status": "PENDING"
}
POST /payments
GET /parking-slots/available?vehicleType=CAR
| Mobile App |
+------+------+
|
v
+-------------+
| API Gateway |
+------+------+
|
+-----------------+------------------+
| | |
v v v
+---------------+ +---------------+ +---------------+
| Reservation | | Allocation | | Payment |
| Service | | Service | | Service |
+-------+-------+ +-------+-------+ +-------+-------+
| | |
+-----------------+-----------------+
|
+-----------+
| Database |
+-----------+
Entry Gate --> Reservation/Ticket Service
Exit Gate --> Payment Service
Responsible for:
ACTIVE
|
+--> COMPLETED
|
+--> CANCELLED
|
+--> EXPIRED
Each reservation has a TTL (e.g., 15 minutes).
Reservation Created
|
15 min
|
Vehicle Not Arrived
|
Reservation Expired
|
Slot Released
A scheduled background job periodically scans and expires reservations.
Maintains available parking slots by vehicle type.
CAR Slots (Min Heap)
A1
A2
A5
A8
The heap is ordered by distance from the entrance.
Allocate: O(log n)
Release : O(log n)
Stores active parking sessions.
Ticket
ticket_id
reservation_id
slot_id
license_plate
entry_time
exit_time
status
Responsibilities:
Responsibilities:
Example pricing:
First hour : 2 Additional hour : 1 Daily cap : $20
ParkingSlot
slot_id
vehicle_type
status
version
Status:
AVAILABLE
RESERVED
OCCUPIED
OUT_OF_SERVICE
The main risk is multiple users reserving the same slot simultaneously.
Use a version column to prevent race conditions.
UPDATE ParkingSlot
SET status='RESERVED',
version=version+1
WHERE slot_id='A1'
AND version=5;
If no row is updated:
Another request reserved the slot first.
Retry allocation.
Benefits:
For large-scale deployments with multiple allocation service instances:
Allocation Service
|
Redis Lock
|
Reserve Slot
|
Release Lock
Example lock key:
lock:slot:A1
This guarantees only one instance can reserve a slot at a time.
ParkingSlot
slot_id
vehicle_type
status
version
Reservation
reservation_id
slot_id
license_plate
status
created_at
expires_at
Ticket
ticket_id
reservation_id
slot_id
license_plate
entry_time
exit_time
status
Payment
payment_id
ticket_id
amount
status
ReservationCreated
ReservationCancelled
ReservationExpired
ReservationCompleted
VehicleEntered
VehicleExited
PaymentCompleted
These events can be published to Kafka/RabbitMQ for analytics, monitoring, auditing, and future integrations.
Monolith
+
PostgreSQL
API Gateway
|
Microservices
|
Redis (Cache + Locking)
|
Kafka
|
PostgreSQL
Additional optimizations: