š¬ Booking Service Demo
Production-grade distributed booking system with race-condition protection using Redis distributed locks and database transactions.
š¬ Interactive Demo: This dashboard demonstrates the booking service UI with mock data. All features work - create bookings, run concurrency tests, view activity logs.
For Production: The backend uses Redis distributed locks + PostgreSQL transactions to prevent race conditions. Deployable on Cloudflare Workers (serverless) or Docker (PostgreSQL + Redis).
For Production: The backend uses Redis distributed locks + PostgreSQL transactions to prevent race conditions. Deployable on Cloudflare Workers (serverless) or Docker (PostgreSQL + Redis).
š„ Service Health
š¬ Demo
Status
< 10ms
Response Time
š¬
Mode
API Endpoint:
Cloudflare Pages (Demo)
ā Create Booking
ā” Concurrency Test
Send 10 simultaneous requests for the same time slot. Only 1 should succeed.
0
Success
0
Failed
š Activity Log
| Title | Start Time | End Time | Status |
|---|---|---|---|
| Team Standup | - | - | CONFIRMED |
| Product Review | - | - | CONFIRMED |
Technical Implementation
Race-Condition Protection
- Redis Distributed Locks: Uses Redlock algorithm to acquire exclusive locks on time slots before booking
- Database Transactions: PostgreSQL transactions with SERIALIZABLE isolation level for conflict detection
- Idempotency Keys: Prevents duplicate bookings from retry logic
- Optimistic Locking: Version-based conflict detection as fallback
- Audit Logging: Complete trail of all booking attempts with timestamps
Architecture Options
- Cloudflare Workers (Serverless): Uses D1 database + Upstash Redis for fully serverless deployment
- Docker (Traditional): PostgreSQL + Redis containerized setup for self-hosted deployment
- Hybrid Mode: Demo mode with mock data for testing without backend
API Endpoints
POST /api/bookings- Create a new booking with race-condition protectionGET /api/bookings- List all bookingsGET /api/bookings/:id- Get booking by IDDELETE /api/bookings/:id- Cancel a bookingPOST /api/concurrency-test- Run concurrent booking simulationGET /api/health- Health check endpoint
Key Features
- Time slot conflict detection with sub-millisecond precision
- Distributed locking prevents double-booking across multiple instances
- Transaction rollback on conflict with detailed error messages
- RESTful API design with proper HTTP status codes
- Interactive dashboard demonstrating concurrency concepts
- Comprehensive test suite with 90%+ coverage
Overview
Distributed booking system designed to handle concurrent requests safely. Implements multiple layers of race-condition protection including Redis distributed locks, database transactions, and idempotency handling. Demonstrates production-ready patterns for preventing double-booking in high-concurrency scenarios.
Key Features
- Race-Condition Safe: Only 1 of 10 concurrent requests for the same time slot succeeds
- Redis Distributed Locks: Redlock algorithm for cross-instance coordination
- Database Transactions: PostgreSQL with SERIALIZABLE isolation for conflict detection
- Idempotency: Prevents duplicate bookings from retry logic
- Audit Logging: Complete trail of all booking attempts
- Interactive Demo: Live concurrency test showing protection in action