InterviewDB Experience

Order Monitor: Real-Time Monitoring System for E-Commerce Order State Transitions

Interview Experience

Problem

Design an OrderMonitor that tracks state transitions for e-commerce orders. Each order transitions through: PLACED -> CONFIRMED -> SHIPPED -> DELIVERED (or CANCELLED from any state). The monitor should (1) validate transitions, (2) record history with timestamps, (3) alert if an order has been in CONFIRMED state for more than 2 hours without shipping.

python
class OrderMonitor:
    def transition(self, order_id: str, new_state: str, timestamp: int) -> bool:
        """Return False if transition is invalid."""

    def get_history(self, order_id: str) -> list[dict]:
        """Return [{state, timestamp}] in order."""

    def get_stalled_orders(self, current_time: int) -> list[str]:
        """Return order_ids stuck in CONFIRMED > 7200 seconds."""

Example:

transition("O1", "PLACED", 0)      -> True
transition("O1", "SHIPPED", 10)   -> False  # skipped CONFIRMED
transition("O1", "CONFIRMED", 10) -> True
get_stalled_orders(7201)           -> ["O1"]

Follow-ups

  1. How do you represent the valid state machine? Adjacency set vs. enum transitions?
  2. How would you scale get_stalled_orders to millions of active orders without scanning all?
  3. What if the same order_id can be reused after cancellation? How does your history model change?
  4. How would you expose this as a REST API with webhook callbacks on state changes?

Full Details

Problem

Design an OrderMonitor that tracks state transitions for e-commerce orders. Each order transitions through: PLACED -> CONFIRMED -> SHIPPED -> DELIVERED (or CANCELLED from any state). The monitor should (1) validate transitions, (2) record history with timestamps, (3) alert if an order has been in CONFIRMED state for more than 2 hours without shipping.

python
class OrderMonitor:
    def transition(self, order_id: str, new_state: str, timestamp: int) -> bool:
        """Return False if transition is invalid."""

    def get_history(self, order_id: str) -> list[dict]:
        """Return [{state, timestamp}] in order."""

    def get_stalled_orders(self, current_time: int) -> list[str]:
        """Return order_ids stuck in CONFIRMED > 7200 seconds."""

Example:

transition("O1", "PLACED", 0)      -> True
transition("O1", "SHIPPED", 10)   -> False  # skipped CONFIRMED
transition("O1", "CONFIRMED", 10) -> True
get_stalled_orders(7201)           -> ["O1"]

Follow-ups

  1. How do you represent the valid state machine? Adjacency set vs. enum transitions?
  2. How would you scale get_stalled_orders to millions of active orders without scanning all?
  3. What if the same order_id can be reused after cancellation? How does your history model change?
  4. How would you expose this as a REST API with webhook callbacks on state changes?

About This Question

This is a candidate experience report from a voleon group interview during the onsite round.

It covers the following topics: Coding, Onsite .