Design the Swiggy Review System

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2022-08-18

Problem Statement

Design a scalable and performant review system for Swiggy, enabling users to submit, update, and view reviews for restaurants, delivery experiences, and food items. Focus on data modeling, moderation, scalability, and real-time availability.


Functional Requirements (FR)


Review Management


•Users can submit reviews for:
•Restaurants
•Orders / Delivery experience
•Specific food items (optional)
•Reviews include: rating (1–5), text comment, images, timestamp.
•Users can edit or delete their own reviews.


Aggregation & Display


•Compute average ratings per restaurant, per item, and per delivery partner.
•Display top reviews based on recency, helpfulness, or rating.
•Support sorting and filtering: most recent, highest rating, most helpful.


Moderation & Spam Detection


•Detect and flag inappropriate content (profanity, spam).
•Optional admin approval or automated filtering.


Feedback & Interactions


•Users can upvote/downvote helpful reviews.
•Optionally, reply to reviews or mark as “verified order”.


Notifications


•Notify restaurants of new reviews.
•Notify users if their review is flagged or responded to.


Non-Functional Requirements (NFR)


•Scalability → Handle millions of reviews across thousands of restaurants and users.
•Low Latency → Reviews should appear almost instantly.
•Availability → Reviews should be highly available even under load.
•Consistency → Average ratings and review counts must be accurate.
•Extensibility → Future support for media uploads, sentiment analysis, and advanced analytics.


Core Entities & Attributes


User


•userId, name, email, profilePic


Restaurant


•restaurantId, name, location, averageRating, totalReviews


Review


•reviewId, userId, restaurantId, orderId (optional), rating, comment, images[], timestamp, status (ACTIVE, FLAGGED, DELETED)


Feedback / Interaction


•feedbackId, reviewId, userId, type (UPVOTE/DOWNVOTE), timestamp


High-Level Components


ReviewService


•Handles CRUD operations for reviews.
•Validates user permissions (edit/delete).


AggregationService


•Computes average ratings and review counts.
•Maintains denormalized statistics for fast retrieval.


ModerationService


•Filters inappropriate content.
•Flags suspicious reviews for manual review.


NotificationService


•Sends alerts to restaurants or users for new reviews or flagged content.


API & Query Layer


•Provides endpoints to fetch reviews, average ratings, top reviews, and feedback counts.


APIs / Operations


User APIs


•submitReview(userId, restaurantId, rating, comment, images)
•updateReview(reviewId, newRating, newComment)
•deleteReview(reviewId)
•getUserReviews(userId)


Restaurant APIs


•getRestaurantReviews(restaurantId, filters)
•getAverageRating(restaurantId)


Feedback APIs


•addFeedback(reviewId, userId, type)
•getReviewFeedback(reviewId)


Design Considerations


•Data Storage → NoSQL (e.g., MongoDB, DynamoDB) for fast read/write of reviews; RDBMS for aggregation if needed.
•Caching → Cache top reviews and average ratings in Redis for low-latency retrieval.
•Sharding → Partition data by restaurantId or region for scalability.
•Concurrency Handling → Handle simultaneous reviews for the same restaurant without inconsistencies.
•Moderation → Use ML models for spam/inappropriate content detection.
•Extensibility → Support media uploads (images/videos) and sentiment analytics.


Solution

Comments