Skip to content

Hotel Booking System

Design a hotel booking system that allows customers to search for available rooms, make reservations, manage bookings, and handle payments. The system should support multiple hotels, room types, booking cancellations, and pricing strategies.

  1. Search hotels by location, dates, and room type
  2. Check room availability for given dates
  3. Create, modify, and cancel bookings
  4. Support multiple room types (Single, Double, Suite)
  5. Handle payment processing
  6. Generate booking confirmations
  7. Manage customer profiles
  8. Support different pricing strategies (seasonal, weekend, holiday)
  9. Handle overbooking scenarios
  10. Send booking notifications
  1. Handle concurrent bookings without double-booking
  2. High availability for search operations
  3. ACID properties for booking transactions
  4. Scalable to handle multiple hotels
  5. Fast search response time
PlantUML Diagram
PlantUML Diagram
PlantUML Diagram
  1. Strategy Pattern: Different pricing strategies
  2. Factory Pattern: Create bookings and rooms
  3. Observer Pattern: Notify users about booking status
  4. Singleton Pattern: BookingService as central coordinator
  5. Repository Pattern: Data access for hotels and bookings
PlantUML Diagram

2. Observer Pattern - Booking Notifications

Section titled “2. Observer Pattern - Booking Notifications”
PlantUML Diagram

3. Factory Pattern - Room & Booking Creation

Section titled “3. Factory Pattern - Room & Booking Creation”
PlantUML Diagram
PlantUML Diagram
BookingService.java
public class BookingService {
public Booking createBooking(Guest guest, Room room, Date checkIn, Date checkOut)
throws BookingException {
synchronized(this) {
// Check availability
RoomInventory inventory = inventoryMap.get(room.getHotel().getHotelId());
if (!inventory.checkAvailability(room, checkIn, checkOut)) {
throw new BookingException("Room not available for selected dates");
}
// Create booking
Booking booking = new Booking(guest, room, checkIn, checkOut);
// Calculate price
double totalAmount = pricingStrategy.calculatePrice(room, checkIn, checkOut);
booking.setTotalAmount(totalAmount);
// Block room
if (!inventory.blockRoom(room, checkIn, checkOut)) {
throw new BookingException("Failed to block room");
}
// Save booking
booking.setStatus(BookingStatus.PENDING);
bookings.put(booking.getBookingId(), booking);
// Send notification
notificationService.sendBookingConfirmation(booking);
return booking;
}
}
}
RoomInventory.java
public class RoomInventory {
public boolean checkAvailability(Room room, Date checkIn, Date checkOut) {
for (Booking booking : bookings) {
if (!booking.getRoom().equals(room)) {
continue;
}
if (booking.getStatus() == BookingStatus.CANCELLED) {
continue;
}
// Check for overlap
if (datesOverlap(booking.getCheckInDate(), booking.getCheckOutDate(),
checkIn, checkOut)) {
return false;
}
}
return true;
}
private boolean datesOverlap(Date start1, Date end1, Date start2, Date end2) {
return !(end1.before(start2) || end2.before(start1));
}
}
public class SeasonalPricing implements PricingStrategy {
private Map<Season, Double> seasonRates;
@Override
public double calculatePrice(Room room, Date checkIn, Date checkOut) {
double basePrice = room.getPrice();
long nights = calculateNights(checkIn, checkOut);
double totalPrice = 0;
Calendar cal = Calendar.getInstance();
cal.setTime(checkIn);
for (int i = 0; i < nights; i++) {
Season season = getSeason(cal.getTime());
double multiplier = seasonRates.getOrDefault(season, 1.0);
totalPrice += basePrice * multiplier;
cal.add(Calendar.DAY_OF_MONTH, 1);
}
return totalPrice;
}
private Season getSeason(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int month = cal.get(Calendar.MONTH);
if (month >= 11 || month <= 1) return Season.WINTER;
if (month >= 2 && month <= 4) return Season.SPRING;
if (month >= 5 && month <= 7) return Season.SUMMER;
return Season.FALL;
}
}
public class BookingService {
public List<Hotel> searchHotels(SearchCriteria criteria) {
List<Hotel> results = new ArrayList<>();
for (Hotel hotel : hotels.values()) {
if (!matchesLocation(hotel, criteria.getLocation())) {
continue;
}
List<Room> availableRooms = hotel.getAvailableRooms(
criteria.getCheckInDate(),
criteria.getCheckOutDate(),
criteria.getRoomType()
);
if (!availableRooms.isEmpty()) {
results.add(hotel);
}
}
return results;
}
}
  1. Add loyalty programs and rewards
  2. Implement dynamic pricing based on demand
  3. Add room upgrade options
  4. Support group bookings
  5. Implement waitlist for fully booked hotels
  6. Add review and rating system
  7. Support multi-room bookings
  8. Implement booking modifications with price adjustments
  9. Add integration with payment gateways
  10. Support corporate accounts and bulk bookings