← Bytedance Interview Insights
The question sounds straightforward until you realize Q1 and Q2/Q3 have fundamentally different consistency requirements and you probably shouldn't serve them from the same pipeline.
Start by clarifying requirements and scale, then design a streaming aggregation pipeline using a time-series store or in-memory counters with sliding windows. Propose a two-tier architecture: per-post counters for point queries and a global/regional leaderboard using a sorted set or heap, with periodic rollups to handle the last-minute window. Discuss trade-offs between accuracy, latency, and cost, and how to handle late data and hot posts.
Pro tip: Emphasize that the 'last minute' is a sliding window, not a fixed tumbling window, and propose approximate algorithms (e.g., count-min sketch or sampled counters) for scalability while maintaining acceptable accuracy. Also, mention the need for idempotent like events to avoid double-counting.
Ask about expected QPS, number of posts, regions, and accuracy requirements. Determine if exact counts are needed or if approximations are acceptable, and whether the system must handle late-arriving events.
Propose a stream processing pipeline (e.g., Kafka + Flink) to ingest like events. Store per-post counts in a time-series database or in-memory store with sliding window support, and maintain global/regional aggregates.
For per-post count, query the time-series store or compute from a sliding window counter. For global/regional top posts, use a sorted set (e.g., Redis ZSET) or a heap that is updated as counts change, with periodic refresh.
Discuss sharding by post ID or region, using approximate counting for hot posts, and caching. Address trade-offs between exactness, latency, and resource usage, and propose a hybrid approach.
Cover late data handling (watermarks), idempotency, failure recovery, and consistency across regions. Mention monitoring and alerting for anomalies.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.