Design real-time kitchen order fulfillment system
CloudKitchensSoftware Engineer · OnsiteLast updated
This question evaluates a candidate's competency in designing real-time backend systems, emphasizing concurrency control, stateful resource allocation, time-sensitive freshness constraints, efficient eviction policies, and action logging.
Backend Engineering Challenge: Real-time order fulfillment
Design and implement (conceptually) a single-process, real-time backend system for fulfilling food orders in a delivery-only kitchen. Orders can be placed and picked up concurrently.
Order model
Each order has:
- id: short identifier (e.g.,
e6bc2) used at pickup time - name: food name
- temp: ideal storage temperature:
hot,cold, orroom - price: dollars
- freshness: duration (seconds) the food remains fresh at its ideal temperature
Freshness degradation rule
- If an order is not stored at its ideal temperature, it degrades 2× as quickly as it would at ideal temperature.
Storage devices
- Heater: capacity 6, stores at
hot - Cooler: capacity 6, stores at
cold - Shelf: capacity 12, stores at
room
Placement logic (on order received)
When a new order arrives:
- The system “instantly cooks” it and must store it until pickup.
- Try to store it at its ideal temperature (heater/cooler/shelf if room).
- If the ideal option is full, place it on the shelf.
- If the shelf is also full:
- First, try to move an existing
hot/coldorder currently on the shelf into the heater/cooler respectively, if there is room. - If no such move is possible, discard one order currently on the shelf (choose a thoughtful discard criterion) to make room, then place the new order.
Pickup logic
- When an order is picked up, it must be removed quickly without moving other orders around.
- If a pickup occurs and the order is not present, the kitchen takes no action.
- If at pickup time the order’s age has exceeded its freshness duration (accounting for 2× degradation when not at ideal temperature), the order must be discarded instead of picked up.
Action ledger
Capture a time-ordered action ledger. Every action record includes at least:
- timestamp
- order id
- action:
place,move,pickup,discard - target:
heater,cooler, orshelf
Constraints:
- For each order: first action is always place; last is pickup or discard.
- Output actions to console in human-readable form as they occur.
Execution harness (load test / simulator)
Build a CLI harness that:
- Fetches a list of orders from a challenge server.
- Places orders at a configurable rate (default: 500 ms between orders).
- Schedules each order’s pickup at a random time after placement within a closed interval (default: 4–8 seconds).
- After all orders are processed (picked up or discarded), submits the action ledger to the server and exits.
Non-functional requirements
- Concurrency: placements and removals may happen concurrently; design should be safe for use beyond the harness.
- Efficiency: discard selection when the shelf is full must be better than O(n) worst-case in the shelf size.
- Single process (may be multi-threaded).
Explain:
- Your system architecture and concurrency approach.
- Data structures enabling fast placement, lookup-by-id removal, and efficient shelf discard.
- How you compute freshness under temperature changes.
- Your discard criterion and why it’s reasonable.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.