I went straight for a min-heap of size K and felt pretty good about it until they pushed on the streaming angle.
Start by clarifying requirements: define K, data characteristics (streaming vs batch), update frequency, query latency, and consistency needs. Then propose a hybrid architecture: a fast in-memory layer (e.g., min-heap or count-min sketch) for approximate top-K with periodic exact recomputation from a scalable store (e.g., distributed cache + partitioned data). Discuss trade-offs between accuracy, latency, and resource usage, and how to scale horizontally.
Pro tip: Emphasize that exact top-K on unbounded streams is often impractical; propose an approximate solution with error bounds and a mechanism to periodically refresh exact results, showing you understand real-world constraints at LinkedIn's scale.
Ask about K's typical size, data volume/velocity, acceptable latency for updates and queries, consistency requirements, and whether approximate results are acceptable.
For exact top-K on bounded data, use a min-heap of size K; for unbounded streams, consider count-min sketch with a heap, or space-saving algorithm. Discuss trade-offs.
Describe how new elements are ingested, processed (e.g., via stream processor), and used to update the top-K structure. Explain how queries are served with low latency.
Partition the stream by key, use distributed processing (e.g., Kafka + Flink), replicate state, and handle failures with checkpointing. Discuss horizontal scaling and load balancing.
Cache top-K results, use read replicas, or precompute materialized views. Consider push-based updates to clients if needed.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.