Design: Booking Conflict Resolution System
Design focuses on booking conflict detection and resolution logic, API design, and data model. User interface and payment integration are out of scope.
Functional Requirements
Non-Functional Requirements
Jump into concepts and practice - no test required
Client | v API Server (REST) | v Booking Service --- Cache (Redis) | v Database (PostgreSQL) Legend: - Client sends booking requests - API Server validates and forwards to Booking Service - Booking Service checks cache and database for conflicts - Uses transactions to ensure no overlapping bookings - Cache updated after successful booking
(start1, end1) and (start2, end2) overlap?start1 < end2 and start2 < end1 correctly detects overlap.[(10, 12), (14, 16), (18, 20)], what will be the result of checking a new booking (12, 14) for conflict using the overlap condition start1 < end2 and start2 < end1?def is_conflict(new_start, new_end, existing_bookings):
for start, end in existing_bookings:
if new_start <= end and new_end >= start:
return True
return Falsenew_start <= end and new_end >= start includes cases where bookings just touch at edges, causing false conflicts.new_start < end and new_end > start to detect true overlaps only.