Why this work, at that time
Yelp's consumer marketplace ran on fast, reliable business listings and review consumption. In 2014 the platform was a Python service-oriented architecture on MySQL with Elasticsearch and a growing cache layer.
The problem
Popular business pages loaded review summaries through expensive joins, and offset pagination got slower the deeper a reader went. The job was to cut response time without changing review ordering or trust rules.
The team and my part
Five engineers: two Python and API, one web, one search and index, one senior tech lead, with PM and QA shared part-time. I was one of the API engineers and owned the reviews pagination change.
Data and index design
business(id, status, updated_at); review(id, business_id, created_at, status, stars); business_review_counter(business_id, count, sum_stars, version). Composite index on review(business_id, status, created_at DESC, id DESC).
API and event contract
GET /v1/businesses/{id}?include=rating and GET /v1/businesses/{id}/reviews?after=<cursor>&limit=20. The cursor encodes created_at and id rather than an offset; responses carry an etag and next_cursor.
Core logic
Serve the summary from cache and fall back to the pre-aggregated counter on a miss. List reviews by keyset seek with a deterministic sort and id tie-breaker, exclude removed or spam content, and cap the limit at 50. Invalidate the cached counter through a versioned key whenever an approved review changes.
Implementation sequence
- Start with p50 and p95 by route and database EXPLAIN plans on high-review businesses.
- Add a composite index in an online migration, then implement cursor pagination behind a feature flag.
- Introduce cached summary records with a bounded TTL and single-flight refresh; make deleted reviews invalidate the right keys.
- Add unit tests for sorting, review visibility, cursor edge cases and SQL compatibility.
- Canary at 1, 10 and 50 percent while watching query CPU, p95 latency, page error rate and review-count agreement.
Environments and release
Local Python and MySQL fixtures; staging with synthetic review distributions; production through the CI pipeline behind progressive flags, preserving the old response shape during migration.
Failure drill
Hot-key expiry triggers a cache stampede. Serve bounded stale summaries, allow one refresh per key, cap database read concurrency, and roll the flag back if review counters diverge.
Scale and targets
Modeled scale
- 680K listing and review reads per day, 7.9 RPS average, 190 RPS peak
- About 180K businesses and 3.6M review associations in the cohort
- About 3K content changes per day
Acceptance targets
- Read p95 from 650 ms to under 350 ms
- Summary accuracy at or above 99.95%
- Zero hidden reviews leaked
The trade-off I would defend
A composite index plus cursor pagination beat rebuilding the search stack. The review-filtering contract stayed explicit so trust rules could not drift.
