Distributed Hotel Booking Platform

The Engineering Challenge

Building a reliable booking engine is fundamentally a problem of distributed state and concurrency. When hundreds of users compete for the same limited room inventory, the system must guarantee ACID compliance, prevent double bookings, and maintain low latency.

For this platform, I architected a polyglot microservices ecosystem from scratch. Rather than relying on a monolithic framework, I designed five isolated domain services (Auth, Booking, Hotel, Review, and Notification) using Node.js (TypeScript) and Go, communicating via synchronous REST for strict validation and asynchronous Redis queues for non-blocking operations.

Architectural Philosophy: "Share-Nothing"

Each service operates in a completely independent directory with its own dependencies, its own environmental configuration, and its own isolated MySQL database.

While this approach requires duplicating lightweight assets (like custom error classes and DTOs), it prevents the "distributed monolith" anti-pattern. A change in the Booking Service's database schema or error handling has zero risk of accidentally breaking the Hotel Service.

Microservices architecture diagram of a hotel booking backend showing Auth, Hotel, Booking, Review, and Notification services with MySQL databases and Redis for distributed locking and asynchronous processing.
Microservices architecture with isolated databases, Redis, and asynchronous processing.

Solving Core Technical Problems

Concurrency Control & Idempotent Booking Confirmation

A booking system has to handle two different concurrency problems. Multiple users may try to book rooms in the same hotel at nearly the same time, while the same client may also retry a confirmation request because of repeated clicks, network failures, or timeouts.

I addressed these cases using distributed locking and idempotency controls.

Handling concurrent booking requests with Redis Redlock

When a booking request arrives, the Booking Service first queries the Hotel Service for available rooms. Once the available inventory is identified, the Booking Service acquires a distributed Redis Redlock scoped to the hotel:

hotelId:${hotelId}

The lock coordinates booking operations targeting the same hotel across application instances, ensuring that the critical booking operation is not executed concurrently by multiple workers.

Once the lock is acquired, the service creates the booking in a PENDING state and assigns the selected rooms to that booking before releasing the lock.

This provides an application-level mechanism for coordinating competing booking requests and controlling concurrent access to hotel inventory.

Hotel booking sequence showing availability checks, Redlock locking, idempotency handling, and transactional booking confirmation.
Booking flow with distributed locking and idempotent confirmation.

Making booking confirmation idempotent

A separate problem occurs when the same booking confirmation request is submitted multiple times. A user might click the confirmation button more than once, retry after a network timeout, or resend the same request from another client.

To handle this, each booking is associated with a unique idempotency key. The Booking Service generates the key when the booking is created and stores it in a dedicated IdempotencyKey table with a unique constraint.

The client receives the key along with the booking information and uses it when confirming the booking:

POST /confirm/:idempotencyKey

During confirmation, the Booking Service starts a Prisma transaction and locks the corresponding idempotency-key record using MySQL's:

SELECT ... FOR UPDATE

The service then checks whether the key has already been finalized. If it has, the request is rejected instead of executing the confirmation again. Otherwise, the booking is confirmed and the idempotency key is marked as finalized within the same transaction.

This prevents the same confirmation operation from being processed multiple times, even when the client sends the request repeatedly.

The two mechanisms therefore solve different problems: Redlock coordinates competing booking operations, while idempotency keys protect the confirmation workflow from duplicate requests.

Engineering Retrospective & Next Steps

Building this project provided valuable hands-on experience in managing microservice boundaries and balancing complexity with developer velocity. Practical next steps for the codebase include:

  • Containerization: Wrapping all services into a unified docker-compose setup to simplify local setup and service orchestration.
  • Observability & Health Checks: Adding centralized log monitoring and standard /health endpoints to streamline debugging and monitoring.

🔗 Check out the hotel booking backend project on my GitHub