Design a meeting room scheduler 00:00:00 Make a prediction You will test an overlap rule at exact boundaries and move a booking without losing the original if a new room is unavailable. A room is booked from nine until ten. Another request is ten until eleven. Under half-open intervals, do the bookings overlap? No. The first excludes the instant ten and the second begins there. Treating both end points as occupied would incorrectly reject an adjacent meeting. 00:00:28 Blocks on a rail Two wooden blocks slide onto a rail. One ends exactly where the other begins. They touch but do not occupy the same stretch; sliding the second back even slightly makes them overlap. Define the interval convention before testing candidate rooms. A room and interval are the jointly allocated resource; a read-only availability screen cannot reserve them. A meeting room scheduler takes a wish (a time, a number of people, some equipment) and gives a room, or says that none is free. People can cancel, move, and ask for the next free time. It is asked because it can be answered at every level. A beginner can get a working overlap test. An experienced engineer finds the race, the failed move, the clock change, and the place where a database takes over. 00:01:22 Allow meetings that just touch Room one is booked from nine until ten. Another meeting requests ten until eleven. Treat bookings as half-open intervals so the second starts exactly when the first ends. Check the requested capacity and equipment, then test overlaps against bookings of candidate rooms. Claim the chosen room and interval atomically. If another request wins the slot first, choosing it from a stale availability screen must not create two confirmations. Represent each interval as including its start and excluding its end. The ten o'clock boundary belongs only to the second booking, so both fit. Move the second start to nine fifty-nine and the overlapping minute creates a conflict even though neither appointment has the same start time. 00:02:10 Change a meeting without losing the original A team wants to move a booking into an already occupied time. If the implementation deletes the old booking first, a failed move can lose it entirely. Validate and commit the move as one operation, or keep the original reservation until the replacement succeeds. Attempt a move into the occupied slot. The move must fail while the original booking remains available to its owner. If the implementation cancels first and books second in separate operations, a third customer can claim the old slot while the move is failing. A separate is-available call followed later by insert allows two clients to see the same free slot. Test the atomic reservation, not only the overlap predicate. A sorted list per room may be enough for modest scale; choose a more complex interval index only when search patterns justify it. PostgreSQL supports exclusion constraints that can prevent overlapping time ranges for the same room. Two customers may both see a free slot in an earlier search. The constraint still guards the actual commitment. A uniqueness rule on the start time alone would miss two bookings with different start times that overlap. 00:03:22 Try an interview follow-up How do you move a booking? I would validate and move the booking under one guard. Temporarily exclude the booking's own old interval while checking the new one. If the destination conflicts, restore the original slot before releasing the guard. Splitting the move into public cancel and book calls lets someone else take the original slot during the gap. A calendar now promises both an available room and an available host. The room is clear, but the host already has a meeting. Can a room reservation commit? If both are required, validate and claim both resources together or release any temporary claim when the second check fails. A room-only overlap test remains useful, but it cannot establish the new two-resource promise. 00:04:12 What to take with you Protect one promise: for each room, bookings never overlap. Give it to one class, RoomCalendar, sorted by start. Because the promise holds, the left and the right neighbour decide about a conflict. Scheduler is the only door. It asks rules and room choice outside the lock, and looks and places inside it. A move takes out, looks, and puts in or puts back.