Katkat

Design a Rotating Workplace Food-Ordering Service

eBaySoftware Engineer · Onsite

Last updated

Tests the ability to design an enterprise food-ordering platform featuring scheduled vendor rotations, optimistic concurrency control for live inventory, and reliable checkout with corporate subsidy splitting.

Scenario

Design an internal food-ordering platform for corporate campuses (similar to services like Fooda or Cater2.me). Each corporate office features a rotating lineup of external partner restaurants every business day. Employees can browse menus, customize dishes (e.g., dressings, protein choices), and place orders before a daily cutoff window. Orders must handle company meal subsidies alongside personal payment methods, while preventing race conditions when limited inventory items sell out during checkout.

Requirements

Functional Requirements

  • Daily Vendor Rotation: Admins schedule partner restaurants to office locations days or weeks in advance. Employees can only view and order from vendors active at their assigned office for a selected date.
  • Customizable Menus: Items support modifier groups (e.g., choice of protein, extra toppings, dressing on the side), where each modifier can alter the base price and item availability.
  • Inventory & Safe Checkout: Certain items or modifiers have strict quantity caps per day. The system must prevent overselling when multiple employees check out simultaneously.
  • Split Payment & Subsidies: The system applies an employer-provided daily stipend (e.g., $15/day). If the order total exceeds the stipend, the user's secondary payment method covers the remainder.
  • Order Aggregation & Cutoff: Orders lock at a defined cutoff time (e.g., 10:30 AM), after which consolidated batch orders are dispatched to the restaurants.

Non-Functional Requirements

  • Consistency over Availability at Checkout: Inventory reservation and payment processing must be strongly consistent to avoid overselling.
  • High Read Availability: Menu browsing should have low latency (< 100ms p95) and survive temporary backend spikes right before cutoff.
  • Fault Tolerance: Third-party payment failures or timeouts must leave order states clean and release reserved inventory.

Scale & Assumptions

  • 50 corporate office locations; 50,000 daily active users (DAUs).
  • Peak traffic: 70% of orders occur in the 60 minutes prior to the 10:30 AM cutoff (~10 orders/sec average, peaking at 50-100 orders/sec).
  • Each office hosts 3 to 5 rotating restaurants per day, with each restaurant offering 20 to 40 items.

Key Deliverables

  1. Data Model: Entities for offices, rotating schedules, menus, modifiers, inventory stock, and orders.
  2. API Design: Key endpoints for fetching daily menus, reserving cart items, and completing checkout.
  3. Concurrency & Inventory Management: Strategy to prevent double-allocation of limited meals during checkout surges.
  4. Payment Flow: Handling two-phase payment (subsidy deduction + credit card charge) with proper rollback mechanics.

Hints

Hint 1

Consider decoupling read-heavy menu views from transactional inventory checks by caching published daily menus in Redis or a CDN.

Hint 2

Use short-lived inventory reservations (TTL leases) in a fast in-memory store like Redis or database row-level versioning (optimistic locking) to prevent overselling without blocking browsing users.

Hint 3

For the two-tier payment process, model checkout as a state machine or saga pattern so that failure to charge an employee's personal card immediately releases corporate subsidies and held inventory.

Follow-up questions

  • How would you handle a scenario where a restaurant suddenly marks an ingredient as unavailable 15 minutes before the daily cutoff?
  • How does your database schema handle menu item pricing history when a restaurant changes modifier costs across different scheduled days?
  • If an office grows to 100,000 employees and checkout spikes to thousands of orders per second, how would you evolve the inventory reservation engine?