Design a Ticket Resale Marketplace
Model ticket listings, seller withdrawal, buyer purchase, and a live cheapest-listing query.
For this exercise, assume sellers list transferable tickets for an event, buyers purchase a specific active listing, sellers may withdraw their own active listings, and clients may query the cheapest active listing for an event.
Each listing has a unique ID, event ID, seller ID, positive integer price, and one state: Active, Sold, or Withdrawn. A listing may make at most one terminal transition; sold or withdrawn listings never become active again. Ties in the cheapest query are resolved by smaller listing ID.
An exact retry with the same command ID and payload returns the prior result, while reuse with a different payload returns Conflict. Command replay, the listing transition, and recording its result must behave atomically; a failed purchase or withdrawal leaves state unchanged.
Payment processing, refunds, ticket authenticity, seat maps, auctions, recommendations, user accounts, persistence, and distributed messaging are outside scope.
Design the objects, responsibilities, APIs, interaction flows, and an in-memory indexing strategy that keeps the cheapest result correct after listings are sold or withdrawn.