Skip to content
Preptima
mediumDesignCodingMidSenior

Design a food-ordering system: customers place orders with restaurants, and the system assigns a delivery partner. Walk me through the classes.

A food ordering design has two lifecycles: the order moves from placed to delivered, while delivery partner assignment runs alongside and can fail and restart. Keep them separate, claim a partner atomically, rank candidates behind a strategy, and write cancellation windows as rules keyed on order state.

5 min readUpdated 2026-10-10Target archetype: Product Startup

Answer

Short answer

A food ordering system has two lifecycles that run side by side. The order goes from placed to accepted by the restaurant, preparing, ready, picked up and delivered. Finding a delivery partner is a separate process that may start while the kitchen is cooking, and it can fail and restart without the order moving at all. Model them as two state machines, claim a partner with an atomic check-and-set, hide the ranking rule behind an AssignmentStrategy, and express cancellation windows as rules keyed on order state.

Was this answer helpful?

Likely follow-ups

  • The assigned partner goes offline after the food is ready. Which state changes, and which stays put?
  • How would you batch two orders from the same restaurant onto one partner without rewriting the dispatcher?
  • A restaurant edits a dish price while an order containing it is being placed. What does the customer pay?
  • Nobody accepts an offer for ten minutes. What does the system do, and what does the customer see?

Related questions