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
| Requirement | Typical 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 |
| Availability | 99.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)
- 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.
- 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 where the primary key is a geohash prefix and a secondary index on category.
- 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
SELECTreduces round-trips. - Result Enrichment → S3 – Photo URLs stored in S3 are attached to the response. A CloudFront distribution caches static assets, keeping bandwidth low.
- Response → Client – The assembled JSON is sent back through API Gateway.
Data Model Highlights
- DynamoDB Table:
PK = geohash_prefix,SK = place_id. Attributes: category, rating, price tier. A global secondary index oncategoryenables filtered scans. - Aurora Table:
place_idprimary key, columns for name, address, description, and a JSON column for reviews. - 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 approach would require complex sharding and could suffer from hotspotting on popular city tiles.
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., 10 k reads/sec ≈ 10 k RCUs) 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 via CloudFront edge locations.
- Security: IAM roles scoped to least privilege, VPC endpoints for DynamoDB and S3, and TLS everywhere.
Common Mistakes That Sink This Question
| Mistake | Why It Fails |
|---|---|
| Ignoring geo-distribution and using a single monolithic DB | Hot spots in popular cities overload a single partition, breaking latency guarantees. |
| Over-engineering with a full-text search engine without justification | Adds unnecessary complexity and cost when DynamoDB + geohash meets the read pattern. |
| Forgetting cache invalidation on writes | Stale results quickly erode user trust; the service appears broken. |
| Not accounting for read-write ratio | Scaling write capacity for a read-heavy workload wastes money and can cause throttling. |
| Skipping operational metrics | Without alarms you won’t know when latency spikes or cache hit rates drop, leading to silent degradation. |
How to Practice This
- Study the worked design in the System Design AI library. It opens on a step-by-step walkthrough, and every component on the board can be clicked for its notes.
- Create your own canvas: sketch the API flow, DynamoDB schema, and caching layer. Use the brief’s rubric to check completeness.
- 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. Keep the cache hit ratio above 80 % to stay within the latency budget.
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?
Relational databases can handle rich metadata but struggle with high-throughput geo queries and scaling reads. DynamoDB’s key-value pattern with geohash partitioning gives predictable performance, while Aurora stores the richer data accessed less frequently.