What if your customers' voices could instantly shape your business reputation without extra work?
Why Rating and review system in LLD? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine running a small online store where customers send their feedback by email or phone. You try to keep track of their ratings and reviews using a simple spreadsheet.
As orders grow, you struggle to organize and display this feedback clearly on your website.
Manually collecting and updating reviews is slow and error-prone. You miss some feedback, mix up customer details, and can't easily show average ratings or filter reviews.
This leads to unhappy customers and lost sales because your site looks untrustworthy and outdated.
A rating and review system automates collecting, storing, and displaying customer feedback. It calculates average ratings, shows recent reviews, and lets users submit new ones easily.
This system keeps data organized, consistent, and instantly available to all visitors, building trust and improving sales.
Add review to spreadsheet Calculate average manually Update website HTML
Submit review via form
Store review in database
Display average rating dynamicallyIt enables real-time, reliable customer feedback that boosts trust and helps businesses grow.
Think of Amazon's product pages showing star ratings and customer reviews that update instantly as new feedback arrives.
Manual tracking of reviews is slow and error-prone.
Automated rating and review systems organize and display feedback clearly.
This builds customer trust and supports business growth.
Practice
Solution
Step 1: Understand the system's goal
A rating and review system is designed to gather user opinions and ratings about products.Step 2: Identify the main function
It calculates average ratings to help other users make decisions quickly.Final Answer:
To collect user feedback and calculate average product ratings -> Option BQuick Check:
Rating system = Collect feedback + average rating [OK]
- Confusing rating system with payment or inventory systems
- Thinking it manages user credentials
- Assuming it handles shipping or delivery
Solution
Step 1: Consider lookup efficiency
Quick lookup by product ID requires a data structure with fast key-based access.Step 2: Choose appropriate structure
A hash map (dictionary) allows O(1) average time to find reviews by product ID.Final Answer:
Hash map with product ID as key and list of reviews as value -> Option AQuick Check:
Fast lookup = Hash map [OK]
- Using arrays without indexing causes slow searches
- Linked lists have O(n) lookup time
- Stacks do not support direct lookup by key
current_avg = 4.0
num_reviews = 5
new_rating = 5
new_avg = (current_avg * num_reviews + new_rating) / (num_reviews + 1)
What is the value of
new_avg?Solution
Step 1: Calculate total rating sum before new review
Total sum = current_avg * num_reviews = 4.0 * 5 = 20Step 2: Add new rating and compute new average
New sum = 20 + 5 = 25
New average = 25 / (5 + 1) = 25 / 6 ≈ 4.1667Final Answer:
4.17 -> Option AQuick Check:
Average update formula ≈ 4.17 [OK]
- Forgetting to add new rating to total sum
- Dividing by old count instead of count+1
- Rounding too early causing wrong average
Solution
Step 1: Understand average calculation
Average = sum of ratings / count of reviews. Both must be accurate.Step 2: Identify deletion impact
If count is not decreased after deleting a review, average calculation divides by wrong count.Final Answer:
Not updating the count of reviews after deletion -> Option CQuick Check:
Count mismatch causes wrong average [OK]
- Ignoring count update after deletion
- Assuming recalculation always fixes average
- Confusing data structure choice with calculation error
Solution
Step 1: Consider query and update load
Millions of products and users mean many queries and updates.Step 2: Choose efficient strategy
Precomputing average and count and updating them incrementally avoids scanning all reviews each time.Step 3: Evaluate other options
Computing average on each query is slow; no indexes cause slow lookups; caching only latest review misses full rating info.Final Answer:
Maintain precomputed average and count, update incrementally on review changes -> Option DQuick Check:
Precompute + incremental update = scalable [OK]
- Recomputing averages on every query
- Ignoring indexing and caching strategies
- Caching incomplete data causing stale info
