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.

Explain your choices

Answer first. Then compare your reasoning.

12 questions 0 got it 0 to review12 not marked

Decisions

Choice, reason, cost, trigger

ChoiceBecauseCostChange it when
Two stages, two keysCorrect merging, no hot keyTen more secondsOne machine is enough
Gate, then exact1% of the memoryEstimates under 20Distinct topics fit anyway
Minute ringSmooth hour240 bytesOnly daily lists
People, not postsHarder to fakeMemory for repeatsInputs are trusted
Whole lists in RedisNo half updateRewrite 3 MBLists become personal
30 s at the edgeBudget of 60Less cacheTarget is five minutes

When they push back

They sayAnswer with
"Just use a Redis sorted set.""For one place and known items, yes. Here it is 417,000 increments a second, 100 million members and a window that slides."
"Approximate? Our lists must be right.""The listed counts are exact after 20 mentions. The estimate only decides who gets a counter, and it cannot miss anyone."
"Why Flink?""I need keyed state, event time and checkpoints. A plain consumer with a local store does it too, with more of our own code."
"Is a minute too slow?""55 of 58 seconds are timers. I can halve each, for more work and more edge traffic."
"Who decides what is suppressed?""A written policy and people, with a log. The system holds and shows evidence."