Design a Train Ticket Booking Service
Model journeys, segment-based seat reuse, timed holds, payment, cancellation, and safe concurrent booking for a train ticket service.
Design a train ticket booking service.
For this exercise, assume one railway operator runs scheduled train journeys. A journey is one train on one travel date, and it stops at an ordered list of stations. Each journey has coaches, and every seat belongs to one seat class, such as sleeper or AC chair car.
For this exercise, assume a passenger searches journeys between a boarding station and a destination station on a date, sees how many seats are free in each class for that part of the route, and books seats for one to six travellers in one class.
A seat can be sold again for a part of the route that does not overlap: a traveller riding from the first to the third station and another riding from the third to the fifth station may use the same seat.
A booking is all or nothing: if the class cannot seat every traveller for the whole requested part of the route, no seat is taken.
For this exercise, assume a new booking holds its seats for ten minutes while payment is handled by an external payment provider. A successful payment confirms the booking and issues a ticket with a unique booking reference. A failed payment or an expired hold releases the seats.
A confirmed booking can be cancelled as a whole, which releases its seats for that part of the route. Repeating a payment confirmation or a cancellation must not charge, issue a ticket, or release seats twice.
The fare depends on the seat class and the number of stations travelled, and the fare rules are expected to change. Many passengers use the service at the same time, so two requests can compete for the last seat on overlapping parts of the route; at most one may win.
Design the object model, focused contracts, and interactions for this booking service. Code is not required. Train scheduling and administration, special quotas, seat or berth preferences, partial cancellation, refund amounts, notifications, authentication, and distributed storage are outside scope.
Waitlists are not part of the foundation; a follow-up may add one.