This question has a lot of surface area and I underestimated how much of it I'd need to cover.
Start by clarifying requirements and scale, then propose a high-level architecture that ingests events, computes trends in near real time, and serves results with low latency. Focus on the trade-offs between accuracy, latency, and cost, and justify your choices based on Figma's collaborative design platform context.
Pro tip: Emphasize that 'trending' is subjective and requires a clear definition (e.g., velocity of views/likes/comments in a sliding window). Also, discuss how to handle cold start and ensure fairness across content types, which shows product thinking beyond pure engineering.
Ask questions to understand what 'trending' means, the expected scale (DAU, articles, events per second), latency requirements (near real time = seconds?), and consistency needs. Define metrics like views, likes, comments, and time windows.
Propose a pipeline: ingestion (Kafka/Kinesis), stream processing (Flink/Spark Streaming) to compute trends, storage (Redis/DynamoDB) for serving, and an API layer. Include a batch layer for backfill or correction if needed (Lambda architecture).
Choose a trending algorithm (e.g., sliding window counts, decayed scores, or machine learning). Model data as events with article ID, user ID, timestamp, and type. Discuss how to handle duplicates, bots, and spam.
Discuss trade-offs: latency vs. accuracy (approximate algorithms like count-min sketch), cost vs. performance (pre-aggregation vs. on-the-fly), and consistency (eventual vs. strong). Mention scaling strategies (sharding, partitioning).
Explain how to handle failures (backpressure, dead-letter queues, idempotency) and monitor system health (latency, throughput, accuracy). Include fallback to batch results if stream fails.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.