Approximate Trending Hashtags in Fixed Memory With Space-Saving
Last updated: November 29, 2026
Quick Overview
Given an unbounded stream of hashtags from new Threads and Instagram posts, report the approximate top k using a fixed number of counters, with a guaranteed error bound on every reported count.
Meta
November 29, 20260
0
0 solved
Given an unbounded stream of hashtags from new Threads and Instagram posts, report the approximate top k using a fixed number of counters, with a guaranteed error bound on every reported count.
Trending surfaces at Meta consume streams too large to count exactly per shard, so heavy-hitter sketches are a natural memory and performance question. The interviewer checks whether you know a counter-based algorithm with provable bounds, can implement eviction efficiently, and can say when a reported item is guaranteed to be truly in the top k.
What the Interviewer Expects
- Chooses Space-Saving (or Misra-Gries) and states its error bound of N/capacity
- Tracks a per-item overestimate so a lower bound on the true count is available
- Implements efficient minimum eviction with a heap and lazy deletion, or a stream-summary list
- Distinguishes guaranteed top-k items from merely likely ones
- Explains how to merge summaries from many shards
- Compares with Count-Min Sketch plus a heap
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you turn this into a sliding one-hour window instead of all time?
- How do you merge Space-Saving summaries from 1,000 ingest shards?
- How would you stop a spam ring from pushing a hashtag into the top list?
- What capacity would you pick to report a reliable top 50?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
add(tag)for each hashtag in the stream;top(k)at any time.- Memory fixed at
capacitycounters regardless of how many distinct tags appear. - Each reported count must come with an error boun...
High-Level Design
Space-Saving keeps capacity (tag, count, error) entries. A tracked tag increments its count. An untracked tag, when the table is full, replaces the entry with the smallest count c, taking count ...