KatInterview

Design a Scalable Food-Item Review and Voting Platform

System DesignModel answer
MediumModel answerSystem Designsystem-designdatabase-designcaching

Last updated

Design a scalable review, rating, and vote tracking service for a food ordering platform, focusing on data modeling, atomic vote mutations, and read/write path performance.

Design an end-to-end review and community feedback system for a food delivery platform. Verified buyers can leave a star rating (0–5) and a written review for items on a restaurant's menu. Platform users can upvote or downvote existing reviews to flag helpful feedback.

Key Requirements

1. Business & Functional Scope

  • Verified Reviews: Only users who have purchased an item can review it. Each user is restricted to at most one review per item.
  • Ratings vs. Votes: Ratings (0 to 5 stars) belong to an item review. Upvotes and downvotes (+1 / -1) belong to other users evaluating the review's quality.
  • Mutable Voting: A user can toggle their vote on a review (e.g., change an upvote to a downvote, or revoke a vote completely).
  • Item Summary & Pagination: Item detail pages require the item's average star rating, total review count, and a paginated list of reviews (sorted by helpfulness or date).

2. Scale & Workload Profile

  • Reviews: ~10,000 new reviews daily (~0.12 RPS baseline, low write rate).
  • Votes & Ratings: ~1,000,000 requests per day for votes and rating updates (average ~12 RPS, peak ~100 RPS).
  • Read/Write Mix: Review listing is read-heavy (99:1 read/write ratio). Rating and vote requests have an approximate 50:50 read/write balance.

Technical Deliverables

  1. Data Model & Schema: Define core tables/entities, primary and secondary keys, unique constraints, and eligibility checks.
  2. API Specification: Define endpoints for creating a review, voting on a review, and fetching an item detail page with reviews.
  3. Consistency & Concurrency: Detail how vote counters and item rating aggregates are updated accurately under concurrent requests (handling retries, vote flips, and cache evictions).
  4. Caching & Storage Strategy: Propose a storage architecture that maintains high read throughput without introducing write bottlenecks on hot menu items.

Hints

Hint 1

Use database unique constraints (e.g., composite primary keys or unique index on (user_id, item_id)) to enforce single-review and single-vote invariants natively.

Hint 2

Avoid recalculating average ratings on every request; maintain running totals (sum of stars and count of ratings) or use asynchronous stream processing to update aggregates.

Hint 3

For vote count changes (upvote -> downvote), handle delta updates explicitly (+2/-2 for vote flips) to prevent race conditions during concurrent requests.