Design a Sliding-Hour Top-Restaurants Service
DoorDashSoftware Engineer · OnsiteLast updated
This problem tests the ability to design a high-throughput, real-time analytics system that maintains a top-k leaderboard over a sliding time window.
Problem Statement
Design a service that maintains a list of the top 10 most-ordered restaurants globally over a trailing 60-minute window.
Functional Requirements
- Provide a real-time
getTopRestaurants()API that returns the top 10 restaurants. - The system must process incoming order events and update the leaderboard continuously.
- Support handling late-arriving events (events where the timestamp is slightly behind the current wall clock).
Non-Functional Requirements
- Scale to handle 100,000 orders per second globally.
- The top 10 list must reflect the state of the trailing hour with a latency of no more than 5 seconds.
- The system should be fault-tolerant.
Your Task
Provide a high-level design that covers:
- The data ingestion pipeline.
- Storage and aggregation strategy (consider trade-offs between precision and latency).
- How you handle time-window sliding (e.g., event-time vs. processing-time).
- How to scale this service to support per-city leaderboards.
Hints
Hint 1
Consider using a stream processing framework that supports windowing operations, such as Apache Flink or Spark Streaming.
Hint 2
For massive event throughput, using an approximate counting algorithm (like Count-Min Sketch) can significantly reduce memory overhead at the cost of slight accuracy loss.
Hint 3
To handle per-city leaderboards, think about partitioning the data stream by city ID before applying the windowing logic.
Follow-up questions
- How would your design change if the top 10 list needed to be 100% accurate without using probabilistic data structures?
- What would you do if a specific, high-volume restaurant causes a 'hot partition' issue in your distributed system?
- How would you ensure that the top-ten calculation handles system restarts or process failures without losing data?
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.