Implement concurrent order-accept/pickup simulator

Quick Overview

This question evaluates concurrency and synchronization skills, including thread-safe design, inter-thread communication, state tracking, and correctness properties such as race-condition avoidance and deadlock freedom.

Implement concurrent order-accept/pickup simulator

Company: CloudKitchens

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Concurrent restaurant order + pickup simulator Design and implement a **thread-safe** simulation for a restaurant that: - Receives incoming orders concurrently (multiple producer threads). - Prepares orders concurrently (one or more worker/chef threads). - Allows customers to pick up orders concurrently (multiple consumer threads). ### Requirements 1. Each order has: - `order_id` (unique integer) - `item_name` (string) - `cook_time_ms` (positive integer) 2. API / operations to support (names can vary): - `placeOrder(order_id, item_name, cook_time_ms)` - `startKitchen(num_chefs)` (starts background processing) - `pickupOrder(order_id)` blocks until the specified order is ready, then returns it - `shutdown()` stops background threads gracefully 3. Correctness constraints: - No order can be picked up before it is cooked. - Each order is cooked **exactly once** and picked up **at most once**. - No deadlocks; avoid busy-waiting. - The system should handle `N` orders with concurrent placement and pickup. ### What to discuss/implement - Your choice of synchronization primitives (mutex/lock, condition variable, semaphore, blocking queue, etc.). - Data structures used to track order state. - How you ensure fairness and avoid race conditions. (You may assume a single process and shared memory; no networking required.)

Overview: This question evaluates concurrency and synchronization skills, including thread-safe design, inter-thread communication, state tracking, and correctness properties such as race-condition avoidance and deadlock freedom.

|Home/Coding & Algorithms/CloudKitchens
CloudKitchens logo
CloudKitchens
Aug 20, 2025
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
13
0

Concurrent restaurant order + pickup simulator

Design and implement a thread-safe simulation for a restaurant that:

  • Receives incoming orders concurrently (multiple producer threads).
  • Prepares orders concurrently (one or more worker/chef threads).
  • Allows customers to pick up orders concurrently (multiple consumer threads).

Requirements

  1. Each order has:
    • order_id (unique integer)
    • item_name (string)
    • cook_time_ms (positive integer)
  2. API / operations to support (names can vary):
    • placeOrder(order_id, item_name, cook_time_ms)
    • startKitchen(num_chefs) (starts background processing)
    • pickupOrder(order_id) blocks until the specified order is ready, then returns it
    • shutdown() stops background threads gracefully
  3. Correctness constraints:
    • No order can be picked up before it is cooked.
    • Each order is cooked exactly once and picked up at most once .
    • No deadlocks; avoid busy-waiting.
    • The system should handle N orders with concurrent placement and pickup.

What to discuss/implement

  • Your choice of synchronization primitives (mutex/lock, condition variable, semaphore, blocking queue, etc.).
  • Data structures used to track order state.
  • How you ensure fairness and avoid race conditions.

(You may assume a single process and shared memory; no networking required.)

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...