šŸŽ¬ 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).

šŸ„ 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

Node.js TypeScript PostgreSQL Redis Cloudflare Workers D1 Database Docker

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 protection
  • GET /api/bookings - List all bookings
  • GET /api/bookings/:id - Get booking by ID
  • DELETE /api/bookings/:id - Cancel a booking
  • POST /api/concurrency-test - Run concurrent booking simulation
  • GET /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

Tech Stack

Node.js TypeScript PostgreSQL Redis Cloudflare Workers D1 Database Docker Upstash