Design a Food Rating System
DoorDashSoftware Engineer · OnsiteLast updated
This problem tests your ability to design a distributed, read-heavy rating and review system that handles high concurrency and ensures data integrity.
System Design: Food Rating Service
Design a food rating and review service for a platform like DoorDash. Users should be able to submit a rating (1-5 stars) and a written review for a specific restaurant. Other users should be able to view these ratings, see an aggregate score, and upvote/downvote reviews.
Requirements
Functional Requirements:
- Users can post a rating and review for a restaurant.
- Users can view a list of reviews for a restaurant, sorted by recent or helpfulness.
- Users can upvote or downvote existing reviews.
- The system must display an accurate aggregate rating (average star value) for each restaurant.
Non-Functional Requirements:
- The system is read-heavy; reviews are viewed much more frequently than they are written.
- High availability is critical for the review feed.
- The aggregate rating must be eventually consistent, but low latency for reads is prioritized.
- Support a scale of 100,000 requests per second across the platform.
Your Task
Provide a high-level architecture that includes:
- API Design: Define key endpoints (e.g.,
POST /reviews,GET /restaurants/{id}/reviews). - Data Model: Schema design for storing reviews, ratings, and aggregate scores. Choose between SQL and NoSQL.
- Storage & Caching: Describe how you handle the write load and how you ensure fast reads for the review feed.
- Consistency: Explain how you handle the update process for aggregate ratings when a new review is added.
- Scalability: How would you handle hot partitions (e.g., a very popular restaurant receiving thousands of reviews at once)?
Hints
Hint 1
Consider using a materialized view or a dedicated aggregation service to compute average ratings asynchronously rather than recalculating on every read.
Hint 2
For write-heavy scenarios like review submissions, consider using a message queue to decouple the request from the database update.
Hint 3
Caching strategies like Redis can store pre-computed review lists for popular restaurants to reduce database pressure.
Follow-up questions
- How would you handle spam protection or ensure that only users who ordered from a restaurant can leave a review?
- If we need to support 'helpful' tags, how would you design a system that prevents a single user from inflating a review's score?
- How would you migrate the database schema if we decide to introduce multimedia attachments (photos) to reviews later?
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.