AlgoViz

Design a Top K / Trending Topics System

hard 45 min

Count billions of mentions a day and show the ten topics that are rising right now, in each country and city.

What each level should show

The same question is judged differently for mid, senior and staff.

  • Mid

    Must show

    • Event rate from posts
    • A log and a counting worker
    • Minute buckets
    • Finished lists in a cache

    Will be probed on

    • Heap of K and its cost
    • What a sketch returns
    • Why not query on read

    Stands out

    Separates popular from trending without being asked.

  • Senior

    Must show

    • Correct merging with the right key
    • Sketch width from the error
    • Hot topic and late events
    • Recovery without double counting

    Will be probed on

    • World from regions
    • Baselines
    • Repeats by one account

    Stands out

    Shows when exact counting is cheaper than a sketch.

  • Staff

    Must show

    • Definition tied to the product and to abuse
    • Freshness budget and what it costs
    • Replay as a way to change rules
    • What to build first

    Will be probed on

    • Review policy
    • Measuring accuracy
    • Second region

    Stands out

    Treats the list as an adversarial product and plans for wrong decisions.

Same question, three answers

"How do you find the top ten?"

LevelA good answer sounds like
Mid"Count in memory by minute, keep a heap of ten, write the list every few seconds."
Senior"Partition by topic so each counter's top ten is enough. Sum by account first, so a hot topic is two records a second."
Staff"First, what counts: people, above their own baseline. Then partition for correct merging, gate the tail, and keep the log so that a bad rule can be replayed away."