Design a Ratings and Reviews System
viaLeetCode
Problem Design a ratings and reviews system for a marketplace: submit star ratings and text reviews, show aggregate scores, paginate reviews, and moderate content.
Functional requirements
- Submit/edit/delete a rating (1–5) and optional text review per user per product (one review per purchase, typically).
- Display average rating + count (and histogram) on product pages; list reviews sorted by recency/helpfulness with pagination.
- Moderation: profanity/spam filtering, report-and-review workflow.
Non-functional requirements
- Read-heavy: aggregates render on every product page — assume 50K product-page views/sec vs tens of review writes/sec.
- Aggregate freshness within seconds is fine (eventual consistency acceptable).
Key components
- Review write service + store (review keyed by (product, user)), aggregate store (per-product avg/count/histogram), cache/CDN for aggregates, moderation pipeline (async queue: ML/keyword filters → human queue), helpfulness voting service.
Deep dives / trade-offs
- Keeping aggregates: recompute-on-read (never) vs incremental counters updated transactionally or via events; fixing drift with periodic reconciliation.
- Preventing abuse: verified-purchase gating, rate limits, dedupe, review-bombing detection.
- Pagination that doesn't break as new reviews arrive (cursor over (sortKey, id), not OFFSET); sorting by "most helpful" with decayed scores.
asked …