Production-grade hotel booking backend - built to handle the problems real booking platforms actually face: concurrency, dynamic pricing, inventory consistency, and payment workflows.
Not another CRUD project. StayGrid is designed around production engineering concerns from the ground up.
StayGrid simulates the backend of a real hotel booking platform — the kind where two users can attempt to book the same room at the same time, pricing changes by the hour, and a failed payment still needs to leave inventory clean.
Core problem domains this project addresses:
- Race conditions in concurrent booking requests
- Multi-layered dynamic pricing logic
- Atomic inventory updates across multi-day stays
- Reliable payment processing with Stripe webhooks
- JWT-based auth with a short-lived access token + refresh token flow
- Refresh tokens stored in
HttpOnlycookies to prevent XSS exposure - Role-based access control:
HOTEL_MANAGERandGUESTroles with endpoint-level authorization
The most critical layer — two users booking the same room simultaneously must never both succeed.
- Pessimistic locking (
SELECT FOR UPDATE) to serialize concurrent writes - Reserved vs. Booked state separation to handle the window between intent and payment
- Multi-day availability validation across the full stay duration
- Atomic inventory updates within transactions to ensure consistency
- Stripe Checkout session creation per booking
- Webhook-driven confirmation — payment status is never polled, always pushed
- Automatic refund on cancellation
- Idempotent booking confirmation to handle duplicate webhook delivery safely
Pricing is not a single formula — it's a composable pipeline of strategies applied in sequence:
| Layer | Description |
|---|---|
| Base Price | Room's configured nightly rate |
| Surge Multiplier | Demand-based scaling |
| Occupancy Pricing | Adjusts with current fill rate |
| Urgency Pricing | Increases for near-date bookings |
| Holiday Adjustment | Applies calendar-based modifiers |
Each strategy is independently pluggable — new pricing rules can be added without touching existing logic.
- Hourly background job (
@Scheduled) recalculates room prices - Updates minimum price aggregates per hotel
- Designed for batch-scale operation
RESERVED → GUESTS_ADDED → PAYMENTS_PENDING → CONFIRMED
↘ CANCELLED
↘ EXPIRED
- 10-minute expiry window on reserved bookings — automatically released if payment doesn't complete
- Ownership validation on every state transition
- Transactional consistency enforced end-to-end
- Custom JPQL queries for availability filtering, pricing aggregation, and revenue reporting
- Avoids N+1 with fetch strategies and projection-based queries
| Layer | Technology |
|---|---|
| Language | Java 21 |
| Framework | Spring Boot 4 |
| Security | Spring Security + JWT |
| Database | PostgreSQL (Neon Serverless) |
| ORM | Hibernate / JPA |
| Payments | Stripe API |
| API Docs | Swagger / OpenAPI |
| Mapping | ModelMapper |
Interactive API documentation available at:
http://localhost:8080/api/v1/swagger-ui/index.html
All flows tested end-to-end via Postman collections:
- Auth flow (register, login, token refresh)
- Booking lifecycle (reserve → confirm → cancel)
- Payment simulation (Stripe test mode + webhook replay)
- Admin and Hotel Manager operations
Coming soon — Swagger UI, booking flow, and inventory locking demonstration
Free-tier cloud deployment in progress
Smit Roy github.com/smitroy4
⭐ If this project was useful or interesting, feel free to star the repo.