Post search
0-day streakReview

Your progress

Level 1

0 XP100 XP to level 2
0day streak
0best streak
0topics started
0cards reviewed
    Review cards

    Progress is stored only in this browser. No account is required.

    Design post search (Twitter / Facebook): the 60-second story

    Design post search

    “ind vs aus” in the last over: posts from seconds ago, not last week.

    Thousands of posts a second, likes that move every second, and results that differ per viewer.

    1 TB

    the last 7 days, in RAM, per copy

    7 × 500M posts = 3.5B, at ≈ 300 B each, in 20 partitions of ≈ 52 GB. More than ten years, 600 billion posts, sit on SSD.

    Tweets once took ≈ 15 s to be searchable, stuck behind slow fields and a sort buffer.

    The 1-second fix

    Index now, patch slow fields later. Derive doc IDs from creation time, so late posts slot in.

    “#diwali” matches 3.5M posts per partition. Latest reads a handful.

    Postings are read newest-first, so Latest stops after 20 hits. Top scores the newest 2,000 matches plus a small index of popular posts.

    Likes change every second. Where do counts live?

    Bad: Re-index on every like

    200,000 deletes and re-inserts a second, into segments meant to freeze.

    Good: Counters, updated in place

    Sum 5-second windows; overwrite fixed-width columns. Postings never move.

    Nobody sees a post they shouldn’t. Three layers, cheap to exact:

    1. Partition: audience terms, Bloom filters, tombstones
    2. Root: an exact check on about 60 finalists
    3. Hydration: drop any post deleted a moment ago

    Assume 40,000 fans a second search “ind vs aus”

    The postings cope; 800,000 identical partition calls a second don’t. Normalise to ≈ 10 keys, cache public results for 1 s, coalesce misses, personalise after.

    Five new posts arrive while you scroll. Page 2 repeats five.

    A max_id cursor marks a position in time, not in a list: “the 20 newest below this ID”. New posts wait above.

    Remember

    Stream posts into time-ordered partitions, searchable in a second. Latest stops early; Top scores a recent window with in-place counts. Filter cheaply, check exactly, collapse hot queries.