Calculating accurate average ratings across millions of customer reviews seems trivial on paper: run an aggregation pipeline with $match and $group: { _id: '$companyId', avgRating: { $avg: '$rating' } }. In high-traffic directories like Trusts Advisor, however, calculating this on the fly during search queries produced severe performance degradation.
As the review database grew beyond 2,000,000 documents, every company profile visit triggered full index index scans and memory-intensive aggregation stages, causing database CPU utilization to spike to 95%. Here is how we redesigned the scoring pipeline using the Bucket Pattern and Bayesian Weighted Averages to achieve sub-5ms response times.
The Scaling Trap of Real-Time Aggregation
In standard relational and document models, calculating a company's rating involves scanning every individual review ever written for that business. For popular firms with tens of thousands of reviews, MongoDB had to fetch and compute arithmetic sums across megabytes of raw documents on every page load.
