Overview
S-Parking’s reservation system allows users to reserve available spots for a specific duration (15-120 minutes). Reservations automatically expire without manual intervention, and the system prevents double-booking through Firestore transactions.Reservation Workflow
Status Codes
| Status | Name | Color | Description |
|---|---|---|---|
1 | Available | Green | Spot is free and ready to use |
0 | Occupied | Red | Vehicle physically present |
2 | Reserved | Yellow | Reserved for specific duration |
Making a Reservation
Reservations are created via a Cloud Function with transaction-based conflict prevention:License Plate Format: The system validates Chilean license plates (e.g.,
AB-1234, ABCD-12)Server-Side Transaction Logic
The Cloud Function uses Firestore transactions to prevent race conditions:Why Firestore Transactions?
Why Firestore Transactions?
Firestore transactions provide atomic read-modify-write operations that:
- Prevent double-booking: Two users can’t reserve the same spot simultaneously
- Ensure consistency: Status checks and updates happen atomically
- Handle retries: Firestore automatically retries transactions on conflicts
- Guarantee isolation: Changes aren’t visible until transaction commits
Reservation Data Structure
Each reserved spot stores reservation metadata:license_plate
Vehicle identifier (validated format)
expires_at
Timestamp when reservation auto-expires
duration
Original duration in minutes
Automatic Expiration
Reservations automatically expire without cron jobs or scheduled tasks. The expiration logic runs every time parking status is fetched:Lazy Expiration: Reservations are cleaned up on-demand when status is requested, not on a schedule. This reduces costs and complexity.
Duration Presets
The dashboard offers predefined duration options:- Quick Options
- Custom Duration
| Duration | Use Case |
|---|---|
| 15 min | Quick errands |
| 30 min | Short visits |
| 60 min | Standard parking |
| 90 min | Extended stay |
| 120 min | Maximum allowed |
Canceling Reservations
Users can release their reservation before it expires:Conflict Handling
The system handles various conflict scenarios:Simultaneous Reservations
Simultaneous Reservations
Scenario: Two users try to reserve the same spot at exactly the same time.Solution: Firestore transactions ensure only one succeeds:The second user receives a
409 Conflict response with the error message.Occupied Spot Reservation
Occupied Spot Reservation
Scenario: User tries to reserve a spot that’s currently occupied.Solution: Transaction checks current status before updating:
Expired but Not Released
Expired but Not Released
Scenario: A reservation expires but the status hasn’t been refreshed yet.Solution: The next status fetch automatically cleans up expired reservations:
UI Indicators
Reservations are visually distinct in the dashboard:Amber Badge
Reserved spots display with amber/yellow styling
Countdown Timer
Shows remaining time until expiration
Analytics Impact
Reservations are tracked separately in occupancy analytics:Occupancy Calculation: Reserved spots count toward total occupancy percentage:
occupancyPct = (occupied + reserved) / total * 100Best Practices
Choosing Duration Limits
Choosing Duration Limits
The 120-minute maximum is based on typical parking patterns:
- University parking: 90-120 min covers most classes
- Shopping centers: 60-90 min for typical visits
- Quick stops: 15-30 min prevents abuse
MAX_DURATION in your Cloud Function based on your use case.Preventing Abuse
Preventing Abuse
To prevent users from monopolizing spots with repeated reservations:
- Rate limiting: Limit reservations per user per day
- Cooldown period: Require 5-minute gap between reservations
- Penalty system: Temporary bans for repeated no-shows
- Reservation fees: Small charge to discourage frivolous bookings
Handling No-Shows
Handling No-Shows
If a user reserves but never arrives:
- The spot automatically becomes available after expiration
- No manual intervention needed
- Consider tracking no-show rate per user for reputation scoring
Related Topics
Real-Time Monitoring
How reservation status syncs across all clients
Analytics Dashboard
Reservation metrics in occupancy reports