Problem statement
Design the object model and core APIs for a content rating system that collects per-user star ratings on media items and exposes a live aggregate, guaranteeing each user counts exactly once.
Operating context. Single in-process service. A user rates a media item from one to five stars; a user may later change or withdraw their rating. Each item exposes an aggregate: a count, an average, and a per-star histogram. Double-voting is impossible because at most one active rating exists per user per item. The aggregate may be computed by a pluggable strategy, from a plain mean to a time-decayed or confidence-weighted mean. Concurrent ratings on the same popular item must keep the aggregate consistent.
Out of scope. Written reviews and their moderation text, abuse or fraud detection, recommendation, any database or persistence layer, and the HTTP layer.
What to produce. The class hierarchy (rating value, rated item, per-user rating index, aggregation strategy), the rating lifecycle (submit, change, withdraw), and the aggregate-maintenance model. Be explicit about: how one-vote-per-user is enforced, how the running aggregate updates incrementally on submit, change, and withdraw, how the aggregation formula is made pluggable, and how concurrent updates on one item stay consistent.
Functional requirements
- Submit a one-to-five star rating from a user for a media item.
- Change a user's existing rating and update the aggregate accordingly.
- Withdraw a user's rating so it no longer counts.
- Expose an item's rating count, average, and per-star histogram.
- Read a specific user's current rating for an item.
Non-functional requirements
- Each user has at most one active rating per item; a resubmission replaces it, never duplicates it.
- Submit, change, and withdraw update the aggregate incrementally in O(1), not by rescanning all ratings.
- The aggregation formula is a pluggable strategy swappable without touching the rating lifecycle.
- Concurrent ratings on one item keep the count, sum, and histogram mutually consistent.
- The object model is unit-testable without a database or a real clock; the clock is injected for decay.
Topics
- System Design LLD
- Media Ratings
- Patterns Strategy
- Concurrency Locks
- Oop Solid