Design a Railway Search and Booking Platform
Design railway search, safe ticket booking and payment, journey reminders, and live next-station distance and arrival estimates.
Problem statement
For this exercise, assume authenticated customers search scheduled train runs by origin, destination, and travel date, inspect fare and class-level availability, place a short inventory hold, confirm one booking after payment, and cancel a confirmed booking.
Capacity is tracked for each travel segment within a train-run class, so a multi-segment itinerary is available only when every covered segment has room. A hold expires after a bounded interval.
Confirmation is idempotent and consumes the held capacity exactly once; hold expiry or a valid cancellation restores capacity. Concurrent requests must never oversell any segment.
Assume the platform handles about 10 million searches and 1 million booking attempts per day, with traffic peaking at roughly ten times the daily average rate.
Search is read-heavy and may use slightly stale schedule, fare, and availability projections, but the booking path must validate against authoritative inventory.
The service runs across multiple zones and must recover safely from worker restarts, duplicate client requests, delayed expiry work, and uncertain payment-provider responses. Train schedules and fares arrive from an upstream catalog.
Dynamic pricing, quota-policy authoring, waitlists, loyalty programs, and operator administration are outside scope.
Also cover the rest of the booked journey: notify users 24 hours before departure, and show live train tracking with distance to the next station and an estimated arrival time. For this exercise, the reminder time is based on the booked boarding station's scheduled departure.
A confirmed booking made inside that 24-hour window is eligible immediately if departure is still in the future. Use the current booking and departure revision when delivery is authorized: earlier cancellation or rescheduling invalidates pending work, while an already authorized delivery cannot be recalled.
For this exercise, the notification provider accepts a stable idempotency key and supports acceptance lookup for seven days. After an uncertain response, the original recipient, payload and key must remain fixed while its outcome is resolved.
Train observations arrive with a train-run ID, source sequence, observation time and a position already aligned to the planned route; raw GPS map matching is outside scope. Calculate remaining track distance to the next planned station and produce an ETA estimate with its observation time.
Prefer input no older than 30 seconds; after 60 seconds without a valid update, clearly mark live distance and ETA stale or unavailable. Position-feed and reminder failures must not block a booking already committed by the original inventory/payment path.
What to build
- Customers can search train runs by origin, destination, and travel date and see schedules, fares, and class-level availability.
- Customers can place a bounded hold on capacity for one train run, class, itinerary, and passenger count.
- Customers can confirm an active hold exactly once after payment, with safe retries after an uncertain response.
- Customers can cancel an eligible confirmed booking and return its capacity exactly once.
- Notify the user24hours before the booked boarding departure, using the current confirmed booking and departure revision at delivery authorization; handle late bookings and obsolete pending reminders.
- Show the train's next planned station, remaining track distance and estimated arrival time, including as-of information and an explicit stale or unavailable state.
At scale
- About 10 million searches per day with a peak rate near ten times the daily average; search favors low latency and horizontal read scaling.
- About 1 million booking attempts per day with a peak rate near ten times the daily average; inventory correctness takes priority over accepting every write during a partition.
- The service spans multiple zones; a zone or worker failure must not duplicate confirmations, lose durable holds, or oversell capacity.
- Schedule and fare updates come from an upstream catalog and may propagate asynchronously to search, while authoritative inventory is checked during hold and confirmation.
- For this exercise, assume 5,000 active train runs with one route-aligned observation every ten seconds, and up to 100,000 concurrent status viewers refreshing every ten seconds.
- For this exercise, reminder work is durable and may catch up after worker failure; a late booking is eligible immediately before departure. Provider acceptance lookup and duplicate keys are retained for seven days.