KatInterview

Design Full-Text and Proximity Search for a Social Feed

System DesignModel answer
HardModel answerSystem Designsearchgeolocationdistributed-systems

Last updated

Design a system that indexes hundreds of millions of short posts for keyword search and geolocation queries, meeting tight freshness and latency targets at scale.

Problem

Build a backend service with two complementary capabilities:

  1. Post search: Users publish short text updates (up to ~280 characters), optionally tagged with a location. Any user can search the full corpus — including years of history — by keyword. Results should be ranked by relevance and recency, respect privacy settings (public vs. friends-only), and reflect deletions and edits within seconds.

  2. Proximity search: Given a coordinate and a radius, return nearby posts, places, or users currently sharing their live location. Geo queries may be combined with keyword filters.

What is expected

Walk through the full design lifecycle:

  • Requirements and scale: State your assumptions explicitly. Derive write rates, index sizes, and query rates from first principles.
  • API design: Define the key endpoints, pagination strategy, and any rate-limiting concerns.
  • Data model: Separate the source of truth from the derived indexes.
  • Architecture: Show the write path, the async indexing pipeline, and the read path including fan-out and merge.
  • Deep dives: Cover at least (a) how the inverted index is partitioned and tiered by time, (b) how deletes and privacy are handled efficiently, and (c) which spatial indexing scheme you would use for geo and why.
  • Trade-offs and failure modes: What degrades gracefully? What breaks hard?

Spend roughly 60% of your time on full-text search and 40% on geo — say so up front.

Hints

Hint 1

Think about the age distribution of queries: the vast majority ask about recent posts. How does that asymmetry let you split the index into a small hot tier and a large cold tier, and what does each tier optimize for?

Hint 2

For full-text, should you partition the inverted index by term or by document? Consider what happens to a shard that owns the term '#worldcup' during a major event, and how multi-term queries behave under each scheme.

Hint 3

For geo, a single bounding cell misses entities sitting just across a cell boundary. What is the minimal set of cells you must query to guarantee no false negatives within radius R, and how does that interact with result ranking?