Zomato is launching a new feature to allow users to schedule future food orders. How would a backend developer design the system to handle scheduled orders, considering reliability, scalability, and timely execution?

ZomatoBackend Developer3–5 YearsSystem Design

6 min readUpdated

Designing a system for scheduled orders requires robust mechanisms for persistence, timely triggering, and fault tolerance. The core components would include a database for storing order details, a message queue for decoupling and asynchronous processing, and a dedicated scheduler service responsible for triggering orders at their appointed time. This architecture ensures that order placement is fast, and order fulfillment is reliable even under high load or intermittent failures.

Core Components and Flow

When a user places a scheduled order, the request first hits the Order API. This API validates the order, persists its details (including the scheduled delivery time) in a transactional database, and then publishes an “OrderScheduled” event to a message queue. This event is lightweight, containing only essential identifiers and the scheduled time. A separate Scheduler Service continuously monitors this message queue, or a dedicated “scheduled tasks” queue. Upon receiving an event, the Scheduler Service calculates the delay until the scheduled time and then either enqueues the order into a delay queue (like AWS SQS Delay Queues or Kafka with a delayed topic strategy) or stores it in a separate persistent job store, ready to be picked up by a job executor. At the specified time, the Scheduler Service (or a Job Executor pool) picks up the order and forwards it to the downstream fulfillment systems (e.g., restaurant management, delivery assignment) via another message queue for processing.

Best practice

Employ idempotent operations for order fulfillment. Since messages might be delivered more than once in a distributed system (at-least-once delivery), the downstream systems processing the scheduled order must be able to handle duplicate requests without creating duplicate orders or side effects. This can be achieved by including a unique request ID (e.g., the scheduled order ID) in all fulfillment messages and having the receiving system check for prior processing using this ID. Also, use dead-letter queues (DLQs) for failed scheduled order events to ensure no order is silently dropped, allowing for manual inspection and reprocessing.

Edge case interviewers probe for

A common edge case is handling time zone differences for scheduled orders. Users might schedule an order for “8 PM local time” which needs to be correctly translated and stored in UTC for consistency across the system. The Scheduler Service must then convert the UTC time back to the relevant local time for triggering, especially if downstream systems operate in specific time zones. Another edge case is handling changes or cancellations to scheduled orders very close to the execution time. This requires a mechanism to quickly retrieve and update or remove the order from the pending execution queue or job store, potentially involving locking mechanisms or optimistic concurrency control.

Common mistake

A frequent mistake is relying solely on simple cron jobs or in-memory timers for triggering scheduled orders. While suitable for low-volume, non-critical tasks, this approach lacks reliability, scalability, and fault tolerance for a high-traffic, critical system like Zomato. If the server running the cron job crashes, all scheduled tasks are lost or delayed. Similarly, scaling horizontally with cron jobs can lead to duplicate executions or complex coordination. A dedicated, distributed scheduler service with a persistent job store and message queue integration is essential for robustness.

What the interviewer is checking

The interviewer is assessing your ability to design a reliable, scalable, and fault-tolerant distributed system. They want to see your understanding of asynchronous processing, message queues, persistence strategies for time-based events, idempotency, error handling (retries, DLQs), and how to manage concurrency and state in a distributed environment. Your ability to reason about edge cases like time zones and late cancellations also demonstrates a thorough design approach.

Imagine a very busy restaurant where you can order food to be delivered at a specific time later. When you place a “scheduled order,” the waiter doesn’t shout it to the chef immediately. Instead, they write it down in a special “Future Orders Book” with your desired delivery time and then also tie a little string to a specific “Reminder Bell” for that exact time.

There’s a dedicated “Bell Ringer” person who does nothing but watch all the Reminder Bells. When a bell tied for your order’s time finally rings, the Bell Ringer goes to the Future Orders Book, pulls out your order slip, and hands it to the kitchen and delivery team. This way, the initial order placement is quick, the kitchen isn’t overwhelmed with orders too early, and even if one Bell Ringer takes a break, another one can take over, ensuring your food arrives on time.

Why interviewers ask this

This question evaluates your understanding of distributed systems, asynchronous processing, data persistence, and fault-tolerant design. It tests your ability to think about time-sensitive operations, scalability challenges, and error handling in a real-world, high-stakes scenario like food delivery.

What a strong answer signals

A strong answer demonstrates a structured approach, identifying key components (database, message queues, scheduler), discussing their interactions, and addressing reliability, scalability, and idempotency. It shows an awareness of trade-offs and practical considerations for time-based tasks.

Common follow-ups

  • How would you handle time zone differences for scheduled orders from global users?
  • What mechanisms would you implement to ensure an order is delivered exactly once to the fulfillment system?
  • How would the system react to a sudden, massive spike in scheduled orders for a specific future time?

Advanced variation

Design a system that allows users to modify or cancel a scheduled order up to 60 seconds before its execution time, ensuring data consistency and real-time updates across all components, including handling potential race conditions.

A small online bakery initially used a single `cron` job running on their web server to check for and trigger scheduled cake deliveries every 15 minutes. As their business grew and scheduled orders increased, especially around holidays, the `cron` job started missing execution windows or overlapping, leading to delayed deliveries and customer complaints. To resolve this, they redesigned the system: scheduled orders were now stored in a database, and upon placement, a message was sent to a managed message queue (like RabbitMQ) with a delayed delivery plugin. A pool of dedicated “Order Processing Workers” constantly consumed from this queue. Each worker was responsible for a small subset of orders, ensuring that even if one worker failed, others could pick up the slack, and messages were only processed when their delay expired, guaranteeing timely and reliable execution.

User Order API Database (Scheduled Orders) Message Queue (Scheduled Events) Scheduler Service Fulfillment System
  1. 1Scheduled order systems require reliable time-based triggering mechanisms.
  2. 2A combination of a transactional database and a message queue is foundational for storing orders and coordinating tasks.
  3. 3A dedicated, distributed scheduler service is crucial for accurately triggering orders at their appointed times and handling high load.
  4. 4Implementing idempotency in downstream systems and utilizing dead-letter queues is essential for fault tolerance and reliability.
  5. 5Horizontal scaling of the Order API, Scheduler Service, and worker pools ensures the system can handle increasing volumes of scheduled orders.