KatInterview

Building a Global Music Chart Aggregation System

System DesignModel answer
MediumModel answerSystem Designstreamingdata-pipelineaggregation

Last updated

Design a scalable streaming pipeline that computes country-level song popularity rankings from millions of play events with 10-minute refresh cycles.

Problem

You're building a music analytics platform that displays popularity rankings. Design a system that processes streaming play events and generates country-specific song rankings, refreshing the results every 10 minutes.

The platform receives a continuous stream of play events containing fields like user identifier, song identifier, country code, and timestamp. Your system should maintain current rankings for each country and serve them through a read API.

Core Requirements

Functional:

  • Accept a high-volume stream of play events
  • Calculate the top 10 most-played songs for each country every 10 minutes
  • Expose an API endpoint that returns the current rankings for any country
  • Support reprocessing historical data when corrections or recalculations are needed

Non-Functional:

  • Handle duplicate events gracefully without inflating counts
  • Scale to millions of simultaneous users across 200+ countries
  • Tolerate eventual consistency given the periodic refresh model
  • Support traffic bursts during peak listening hours

Your Task

Present a complete architecture that addresses:

  1. End-to-end flow: How data moves from event generation to queryable rankings
  2. Data storage: Where and how you store both raw events and computed results
  3. Horizontal scaling: How the system handles load increases and avoids bottlenecks
  4. Correctness guarantees: How you ensure duplicate events don't corrupt rankings and how you enable safe reprocessing

Hints

Hint 1

Consider the write-to-read ratio: you'll process millions of events but serve relatively tiny result sets

Hint 2

Partitioning by country alone creates imbalanced load; think about composite keys

Hint 3

Event deduplication needs a strategy that works both in streaming and batch replay scenarios