System Design AI

Design a Proximity Service like Yelp: Junior, Senior, and Staff Answers

When you’re asked to design a proximity service like Yelp, the interviewer is looking for three things: your ability to translate vague product goals into concrete system requirements, your knowledge of geo-distributed data stores and latency-critical paths, and your sense of operational robustness. The question forces you to think about high-read, moderate-write workloads, geographic indexing, and how to keep the user experience snappy while the backend scales.

What the Interviewer Is Testing

  • Scalability – Can you handle millions of places and hundreds of millions of reads per day?
  • Latency – Users expect results in a few hundred milliseconds, especially on mobile.
  • Data Modeling – How you store and query location data matters for both performance and cost.
  • Operational Insight – Do you consider monitoring, failure handling, and cost trade-offs?

Core Requirements and Driving Numbers

RequirementTypical Value (hedged)
Number of places (restaurants, shops, etc.)~10 million (order of 10⁷)
Daily read requests (searches)~100 million (≈1 200 per second)
Write rate (new listings, updates)~1 million per day (≈12 per second)
Latency target for search<200 ms end-to-end
Availability99.9 % overall, with regional fail-over

These numbers drive the choice of storage, caching, and request routing. A read-heavy workload suggests a read-optimized store and a strong cache layer. The geographic query pattern pushes us toward a service that can efficiently filter by distance.

Core Design Overview (One Hop at a Time)

  1. Client → API Gateway – The mobile or web client sends a GET request like /search?lat=37.77&lon=-122.41&radius=5km&category=restaurant. API Gateway validates the query and forwards it to the Search Service.
  2. Search Service → Geo Index – The service first checks an ElastiCache (Redis) read-through cache keyed by the rounded latitude/longitude tile. If a cache miss occurs, it queries DynamoDB for the user's geohash tile and its eight neighbours, where the partition key is a geohash prefix and the sort key starts with the category.
  3. DynamoDB → Result Set – DynamoDB returns candidate place IDs. The service then fetches the full place records from Aurora MySQL (or Aurora PostgreSQL) where richer metadata lives (reviews, photos). A batch SELECT reduces round-trips.
  4. Result Enrichment → S3 – Photo URLs stored in S3 are attached to the response. A CloudFront distribution caches static assets, keeping bandwidth low.
  5. Response → Client – The assembled JSON is sent back through API Gateway.

Data Model Highlights

  • DynamoDB Table: PK = geohash_prefix, SK = category#place_id. Attributes: rating, price tier. A query on one tile with begins_with(SK, "restaurant#") returns only that category; a global secondary index keyed on category alone would return every restaurant everywhere, not the ones nearby.
  • Aurora Table: place_id primary key, columns for name, address and description; reviews live in their own table keyed by (place_id, review_id), because a popular place collects thousands of reviews that must be paged and edited independently.
  • Redis Cache: Keys like geo:{tile_id}:{category} store a list of top-N place IDs for fast lookup.

The key choice here is DynamoDB with a geohash partition key. Alternatives such as a pure relational index or a dedicated search engine (e.g., OpenSearch) were considered. DynamoDB offers predictable latency at scale and integrates well with the serverless stack, while a relational option (PostgreSQL with PostGIS on read replicas) would also hold 10 million places comfortably; either way, popular city tiles are hot and need the cache in front.

What a Complete Junior Answer Covers

  • High-level flow as described above, with each component named.
  • Basic schema for DynamoDB and Aurora.
  • Caching using ElastiCache to meet the <200 ms latency goal.
  • Simple scaling: increase read capacity units on DynamoDB and add more Redis nodes.
  • Assumptions: uniform distribution of places, no multi-region writes.
  • Missing pieces: no discussion of write-through cache invalidation, no handling of hot tiles, and no operational metrics.

What a Senior Answer Adds

  • Sharding strategy: split DynamoDB by geohash depth to avoid hot partitions; use adaptive capacity.
  • Read-through & write-behind cache: after a write, push updates to Redis via an SQS queue processed by a Lambda that refreshes the cached tile.
  • Async pipelines: a Kafka (MSK) stream captures place updates, feeding both Aurora (for rich data) and a materialized view in ElastiCache.
  • Rate limiting: API Gateway throttles per-IP to protect downstream services.
  • Monitoring: CloudWatch dashboards for latency, cache hit ratio, and DynamoDB throttling.
  • Cost awareness: estimate DynamoDB RCUs (e.g., 1,200 searches/sec, each querying a tile and its 8 neighbours, is about 11 k queries/sec; a strongly consistent read costs one RCU per 4 KB read, an eventually consistent one half that) and Redis node count.

What a Staff Answer Adds

  • Failure modes: discuss partial outages of Redis, DynamoDB throttling, and network partitions. Propose fallback to Aurora-only path with a higher latency budget.
  • Operational runbooks: automated alarms for cache miss rates, periodic cache warm-up jobs, and data-reconciliation scripts.
  • Cost-benefit trade-off: evaluate using a dedicated geo-search engine (e.g., OpenSearch) versus DynamoDB+Redis. Defend the chosen stack by showing that DynamoDB’s on-demand pricing plus a modest Redis cluster stays within a predictable budget while meeting latency.
  • Data consistency: explain eventual consistency of DynamoDB reads and how the cache may serve stale data for a few seconds; mitigate with short TTLs.
  • Multi-region replication: replicate DynamoDB tables using Global Tables for low-latency reads in distant regions; replicate S3 assets with S3 Cross-Region Replication, with CloudFront caching them at the edge.
  • Security: IAM roles scoped to least privilege, VPC endpoints for DynamoDB and S3, and TLS everywhere.

Common Mistakes That Sink This Question

MistakeWhy It Fails
Searching only the user's own geohash tilePlaces just across a tile edge are missed; a radius search must also read the neighbouring tiles.
Over-engineering with a full-text search engine without justificationAdds unnecessary complexity and cost when DynamoDB + geohash meets the read pattern.
Forgetting cache invalidation on writesStale results quickly erode user trust; the service appears broken.
Not accounting for read-write ratioScaling write capacity for a read-heavy workload wastes money and can cause throttling.
Skipping operational metricsWithout alarms you won’t know when latency spikes or cache hit rates drop, leading to silent degradation.

How to Practice This

  1. Study the worked design, Design a Local Business Review Site like Yelp, part of Pro ($10/month). It opens on a step-by-step walkthrough, and every component on the board can be clicked for its notes. Free readers can start with the free worked design Design a Proximity Search Service.
  2. Sketch your own design on paper or a whiteboard: the API flow, DynamoDB schema, and caching layer. Check completeness against the junior, senior, and staff expectations above.
  3. Run a mock interview: have a peer ask you the junior, senior, and staff prompts. Record where you miss the extra considerations and iterate.

Questions people ask

What is the best way to store geographic data for a proximity service?

A common pattern is to encode latitude/longitude into a geohash and use it as a partition key in DynamoDB. This lets you query a tile and its neighbors efficiently. Alternatives include a dedicated search engine or a relational spatial index, but they add complexity.

How do you keep search latency under 200 ms at scale?

Cache the most common tile-category combos in ElastiCache (Redis) with a short TTL. On a miss, query DynamoDB which offers single-digit millisecond latency. The hit ratio mainly protects DynamoDB capacity and cost; even the miss path fits well inside 200 ms.

What should you do when the cache layer fails?

Fall back to a DynamoDB-only path. The service should detect Redis timeouts, log the event, and continue serving results directly from DynamoDB, accepting a higher latency for that request.

Why not use a single relational database for both search and metadata?

You can: PostgreSQL with PostGIS answers radius queries from a spatial index, and read replicas carry a read-heavy load at this scale. This design moves the geo lookup to DynamoDB with geohash partitioning for predictable performance as traffic grows, while Aurora stores the richer data accessed less frequently.