Product Review Platform with Helpful Votes and Author Payouts
System DesignModel answerLast updated
Design a high-traffic product review service with idempotent helpful-votes, scalable counters, ranking, abuse defenses and an exact, auditable author reward flow.
You are asked to design the backend for a review feature on a large online marketplace. Shoppers write reviews for products they bought, and other shoppers mark those reviews as helpful or unhelpful. Review authors earn rewards once their reviews pass certain helpful-vote thresholds.
Your design should cover:
- APIs for creating a review, casting/changing/withdrawing a vote, fetching the top reviews of a product, and viewing and claiming rewards.
- Data model for reviews, individual votes, per-review aggregate counters, and rewards.
- Voting correctness: one vote per user per review, safe under client retries and duplicate messages, with support for changing or undoing a vote.
- Counter strategy: how you keep vote totals accurate enough and cheap enough when a single review can receive a burst of votes (for example sharded, batched or approximate counters), and which numbers must be exact.
- Ranking: how "top" reviews are chosen and served.
- Abuse resistance: fake accounts, coordinated brigading, self-voting, vote rings.
- Scale, caching and consistency: read/write path separation, failure handling (failover, retries, deduplication), and the consistency level you pick for each piece of data.
- Operations: monitoring and how you would repair or rebuild derived data.
State your own scale assumptions (users, products, reviews, votes per day, read QPS) and use them to justify choices such as sharding and caching.
Hints
Hint 1
Make the vote endpoint a PUT that sets an absolute value (+1, -1, 0) rather than a toggle or increment, so retries are naturally idempotent. Treat the votes table as the source of truth and everything else as derived.
Hint 2
Separate the paths: a small transactional write to the votes store plus an outbox event, then asynchronous aggregation into counters. Think about micro-batching and spreading a hot review's writes over several counter shards.
Hint 3
Display counts can lag by seconds, but reward eligibility cannot be approximate. Use unique constraints on (review, milestone) and on ledger entries, and compute rewards from exact, abuse-filtered counts.
Hint 4
Raw up minus down is a weak ranking signal. Consider a confidence-based score such as the Wilson lower bound, optionally weighted by voter trust, and cache the top N per product.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Requirements and assumptions
Functional
- One review per buyer per product, with rating, text and optional media.
- Helpful/unhelpful votes that can be changed or withdrawn.
- Product page shows top reviews with sorts: most helpful, newest, rating.
- Authors earn rewards at vote milestones and claim them.
Non-functional
- Read-heavy; product-page review fetch p99 under ~100 ms.
- Votes idempotent: no double counting on retries.
- Displayed counts may be eventually consistent (seconds). Rewards involve money, so they must be exact, audited and issued once.
- Resilient to sybil accounts, brigading and vote rings.
Scale (assumed): 50M DAU, 2B reviews, 100M votes/day (about 1.2K/s average, about 10K/s peak), about 100K review-read QPS at peak. Votes at about 40 B per row over about 20B rows is roughly 1 TB, so the votes table must be sharded. Viral reviews create hot keys.
2. APIs
POST /v1/products/{pid}/reviews (Idempotency-Key header)
PUT /v1/reviews/{rid}/vote body {value: +1 | -1 | 0}
GET /v1/products/{pid}/reviews?sort=&cursor=&limit=
GET /v1/users/me/rewards
POST /v1/rewards/{id}/claim (Idempotency-Key header)
The central choice is that voting is a PUT of an absolute state. Sending +1 twice equals sending it once, and undo or change is just another value. No toggle or increment semantics means retries cannot corrupt state. Reads use cursor pagination.
3. Data model
reviews(review_id, product_id, author_id, rating, body, status, ...), unique on(product_id, author_id), sharded by product.votes(review_id, voter_id, value, updated_at, trust_weight), primary key(review_id, voter_id), sharded by review. Source of truth.review_counters(review_id, up, down, weighted_up, weighted_down, score, version): derived.counter_shards(review_id, shard_no, up_delta, down_delta): only for hot reviews.rewards(reward_id, author_id, review_id, milestone, amount, status), unique on(review_id, milestone).reward_ledger(txn_id, reward_id UNIQUE, author_id, amount).outbox(event_id, aggregate_id, payload, published).
The composite primary key physically prevents double votes. Unique keys on rewards and ledger make issuance and payout idempotent.
4. Architecture
Clients go through a gateway (auth, rate limits) to review, vote and reward services. The vote service writes to the votes shard plus an outbox row in one transaction; CDC publishes to Kafka partitioned by review_id. Consumers: a counter aggregator, an abuse scorer, and a reward evaluator. The ranking service maintains Redis sorted sets per product. Reads hit Redis first, then the DB, with a CDN for anonymous traffic.
5. Deep dives
Idempotent vote with change and undo
In one transaction on the votes shard:
- Lock and read the existing vote (missing means 0).
- If it equals the new value, return (retry no-op).
- Upsert, compute the delta (for example +1 to -1 gives up -1, down +1).
- Insert an outbox event carrying
oldandnew.
Consumers dedupe by event_id, and because each event carries old and new values, application is order-safe within a review partition. Reject self-votes, votes on unpublished reviews, and apply per-user and per-device rate limits.
Counters
- Default: the aggregator micro-batches deltas per review (for example every second) and applies one increment. A thousand votes on a viral review become one write.
- Hot keys: above a write-rate threshold, spread deltas over N shard rows (
hash(voter_id) % N); readers sum shards and a job folds them back. - Display: Redis
HINCRBYfor near-real-time numbers, treated as a cache. - Approximate structures (HyperLogLog, Count-Min) are fine for analytics such as unique voters, never for rewards.
- Reconciliation: periodically recompute counts from
votesfor recently active reviews and repair drift.
Ranking
Up minus down favors old reviews and a 1/0 review beats 90/10. Use the Wilson lower bound of the helpful fraction at 95% confidence, optionally using trust-weighted votes, with mild time decay and quality signals (verified purchase, media). Keep the top ~100 IDs per product in a Redis ZSET; deep pages fall back to a DB index on (product_id, score DESC). Newest and rating sorts use plain indexes.
Abuse prevention
- Eligibility: verified, aged accounts with purchase history.
- Trust weight from 0 to 1 using account age, orders, device and payment uniqueness.
- Streaming detection: velocity spikes on one review, voter clusters sharing device/IP/payment, reciprocal rings via graph analysis.
- Cleanup: mark votes invalid rather than deleting; emit compensating events so counters, ranks and pending rewards adjust. Keep an audit trail.
Rewards
Milestones are evaluated from exact, abuse-filtered counts and made claimable only after a hold period so late fraud detection can revoke them. Issuance relies on UNIQUE(review_id, milestone). Claim runs in one transaction that flips status and writes a ledger row (unique on reward_id), with an idempotency key on the API. Revocations post negative ledger entries rather than editing history.
6. Reliability and consistency
| Data | Consistency | Reason |
|---|---|---|
| Votes | Strong per key | Correctness of one vote per user |
| Counters, ranks | Eventual (seconds) | Display only |
| Rewards and ledger | Strong, audited | Money |
- Outbox plus at-least-once delivery plus consumer dedupe gives effectively-once effects.
- Replicate shards with automatic failover; clients retry with the same idempotency key.
- Dead-letter queues for poison events; replay from Kafka retention or from the votes table.
7. Monitoring and backfill
- Metrics: vote latency, consumer lag, counter drift between votes and counters, cache hit rate, hot-key detection, abuse flag rate, reward issuance versus ledger totals.
- Alerts on lag and drift thresholds.
- Backfill: rebuild counters and scores from
votesby shard in batches, then swap; re-run the reward evaluator in dry-run mode to compare.
Common mistakes
- Toggle or increment vote APIs that break under retry.
- Treating Redis counters as the source of truth.
- Using approximate counts for payouts.
- Ranking by raw net votes.
- Paying rewards instantly with no hold or revocation path.
- Ignoring hot-key write contention.