KatInterview

Nearby Venue Feed: Real-Time Top-K Ranking as You Explore a Map

Machine LearningModel answer
HardModel answerMachine Learningml-system-designgeospatialretrieval

Last updated

Design a low-latency system that surfaces the most relevant K venues within a moving map viewport, covering spatial indexing, candidate retrieval, personalized re-ranking, and caching.

Nearby Venue Feed: Real-Time Top-K Ranking as You Explore a Map

You're building the backend for a consumer map app. As a user pans and zooms, the map continuously shows pins for the most relevant venues (restaurants, attractions, shops, etc.) inside their current view. The experience needs to feel instantaneous and personal.

Design the end-to-end system. Your answer should cover:

  • Requirements and scale — functional behavior, latency targets (aim for p95 ≤ 150 ms end-to-end), availability, and rough throughput numbers
  • API contract — what the client calls, what it gets back, and why the response shape supports caching
  • Spatial indexing strategy — how you partition and index hundreds of millions of venues globally; compare the main options and justify your choice
  • Candidate generation — how you efficiently find ~1–2k candidates for a given viewport without scanning all venues
  • Retrieval vs. re-ranking — when you'd use approximate nearest neighbor (ANN) search versus a learned ranking model, and how you combine them; discuss decision criteria like latency budget, personalization depth, data sparsity, and recall requirements
  • Caching layers — client, edge/CDN, and backend; what you can cache, what you can't, and how you maintain freshness without stale results
  • Incremental updates — how edits to venues and trending signals propagate without invalidating everything
  • Operational concerns — deduplication across tile boundaries, smooth pagination while panning, load shedding under traffic spikes, cold-start for new users and new venues, offline and online evaluation, and cost

A strong answer reasons about trade-offs explicitly, gives concrete numbers where useful, and explains what breaks if you make the wrong architectural choice.

Hints

Hint 1

Start by converting the viewport into discrete map tiles rather than a raw bounding box. Tile-keyed responses are cacheable; bbox-keyed ones are not — think about why that matters before designing the cache layer.

Hint 2

Separate candidate generation from ranking. The spatial index job is to narrow hundreds of millions of venues down to a few thousand cheaply; the ranker's job is to order those few thousand by relevance. ANN and learned ranking solve different problems and work best in combination, not in competition.

Hint 3

Freshness and caching are in tension. Ask yourself which part of the result changes fast (personalized scores, trending signals) versus slowly (which venues exist in a tile). That split tells you exactly what to cache at the edge versus recompute per-request.