Bird
Raised Fist0

Spotify - Audio Streaming, Playlist, Offline Download Architecture

HLDhardInterview freq: high
Choose your preparation mode4 modes available
▶
Request Trace
Step 1/8
User Device

Sends playlist fetch request

User requests playlist data to display tracks

Protocol:WebSocket
BeforeUser has no playlist data loaded
AfterPlaylist request sent to Playlist Service
Playlist Service

Queries Metadata Store for playlist tracks

Fetches track IDs and metadata for requested playlist from Cassandra

Protocol:gRPC
BeforePlaylist Service has no cached playlist data
AfterPlaylist Service has track metadata retrieved from Metadata Store
Metadata Store

Returns playlist track metadata

Responds with track info including audio file locations from Cassandra

Protocol:CQL Query
BeforeMetadata Store holds latest playlist data in Cassandra
AfterMetadata Store returns requested playlist metadata to Playlist Service
Streaming Service

Streams audio data for selected track

Receives track request and fetches audio from CDN

Protocol:HTTP Range Request
BeforeStreaming Service has track metadata but no audio data
AfterStreaming Service streams audio chunks fetched from CDN
Content Delivery Network (Akamai)

Delivers cached audio content

Serves audio chunks to Streaming Service for user playback

Protocol:HTTPS
BeforeCDN caches audio files from Object Store
AfterAudio chunks delivered to Streaming Service
User Device

Plays streamed audio

Receives and plays audio chunks from Streaming Service

Protocol:WebSocket
BeforeUser Device has playlist metadata but no audio
AfterUser hears audio playback of selected track
Offline Service

Handles offline download request

Fetches audio files from Object Store for offline caching

Protocol:S3 GET
BeforeOffline Service has user offline download request
AfterOffline Service downloads audio files from Object Store
Object Store

Serves audio files for offline download

Provides raw audio blobs to Offline Service

Protocol:S3 GET
BeforeObject Store stores raw audio files
AfterAudio files delivered to Offline Service for caching
🏗️
Architecture Diagram
Architecture Diagram
┌───────────────┐
│  User Device  │
└───────┬───────┘
        │ WebSocket
        ▼
┌───────────────────────┐
│   Playlist Service    │
│    (gRPC microservice)│
└───────┬───────────────┘
        │ gRPC
        ▼
┌───────────────────────┐
│   Metadata Store      │
│   (Apache Cassandra)  │
└───────┬───────────────┘
        │ CQL Query
        ▼
┌───────────────────────┐
│  Streaming Service    │
│  (Custom microservice)│
└───────┬───────────────┘
        │ HTTP Range Req
        ▼
┌───────────────────────────────┐
│ Content Delivery Network (CDN)│
│          (Akamai)             │
└───────┬───────────────────────┘
        │ HTTPS
        ▼
┌───────────────────────┐
│   User Device         │
│  (Audio Playback)     │
└───────────────────────┘
        ▲
        │ Offline Download Req
┌───────┴───────────────┐
│    Offline Service    │
│  (Custom microservice)│
└───────┬───────────────┘
        │ S3 GET
        ▼
┌───────────────────────┐
│    Object Store       │
│ (Amazon S3 or equiv.) │
└───────────────────────┘

This architecture illustrates Spotify's audio streaming and offline download flow. The user device initiates a playlist fetch via WebSocket to the Playlist Service, which queries the Metadata Store (Apache Cassandra) for track metadata. When a track is selected, the Streaming Service streams audio data using HTTP range requests from the Akamai CDN, which caches audio files from the Object Store (Amazon S3). The user device plays the streamed audio in real time. For offline downloads, the Offline Service fetches audio files directly from the Object Store to cache locally on the device. This design separates concerns: Playlist Service handles metadata management, Streaming Service manages live audio delivery, Offline Service manages downloads, and the CDN ensures efficient global content delivery, ensuring scalability and reliability.

Primary Focus

✓

Practice

(1/5)
1. You need to store billions of high-dimensional vectors with fast approximate nearest neighbor (ANN) search. Which component is best suited to efficiently index and query these vectors?
easy
A. A distributed key-value store like Cassandra
B. A relational database with B-tree indexes
C. An HNSW (Hierarchical Navigable Small World) graph index
D. A full-text search engine like Elasticsearch

Solution

  1. Step 1: Identify indexing method for high-dimensional vectors

    Relational DBs with B-tree indexes (A relational database with B-tree indexes) are inefficient for high-dimensional ANN queries due to curse of dimensionality.
  2. Step 2: Evaluate ANN-specific indexes

    HNSW (An HNSW (Hierarchical Navigable Small World) graph index) is designed for fast approximate nearest neighbor search with logarithmic query time and high recall.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    HNSW graph index enables efficient ANN search in high dimensions [check]
Hint: HNSW excels at fast ANN search in high dimensions [check]
Common Mistakes:
2. In a storage tiering system, at Step 4 the Data Migration Worker checks the access frequency metadata for a data block. What action does it take if the access frequency falls below the warm tier threshold?
easy
A. Immediately deletes the data block to free space
B. Promotes the data block to hot storage for faster access
C. Moves the data block from warm storage to cold storage tier
D. Archives the data block to tape storage without metadata update

Solution

  1. Step 1: Understand migration triggers

    Data Migration Worker uses access frequency to decide tier movement; low frequency triggers move to colder tier.
  2. Step 2: Identify correct tier movement

    Data with low access frequency moves from warm to cold storage, not deletion or promotion.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Low access frequency -> warm to cold migration [check]
Hint: Low access frequency -> move down tiers, not delete [check]
Common Mistakes:
3. For billing in a multi-tenant SaaS platform, which architecture best supports accurate usage tracking with minimal latency impact on tenant requests?
medium
A. Asynchronous event-driven usage aggregation via a message queue and batch processing
B. Embedding billing logic directly in the tenant service to update counters in-memory
C. Periodic polling of tenant usage logs by the billing service every hour
D. Synchronous billing updates on every tenant API call to the billing database

Solution

  1. Step 1: Analyze latency and accuracy trade-offs

    Synchronous updates (Synchronous billing updates on every tenant API call to the billing database) add latency; polling (Periodic polling of tenant usage logs by the billing service every hour) delays billing data; in-memory counters (Embedding billing logic directly in the tenant service to update counters in-memory) risk data loss.
  2. Step 2: Evaluate asynchronous event-driven approach

    Asynchronous event-driven usage aggregation via a message queue and batch processing decouples billing from tenant requests, ensuring accurate aggregation with minimal latency impact.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Event-driven async billing -> accurate, low-latency tenant requests [check]
Hint: Async event-driven billing decouples latency [check]
Common Mistakes:
4. At 10x scale, which component in a Raft cluster is most likely to become the bottleneck first, and why?
hard
A. The client load balancer, because it cannot distribute requests evenly at large scale
B. Followers, because they must store all log entries locally, increasing disk I/O linearly
C. The network, because Raft requires all nodes to broadcast heartbeats simultaneously, saturating bandwidth
D. The leader, because it handles all client requests and replicates logs to every follower, creating CPU and network bottlenecks

Solution

  1. Step 1: Identify Raft leader responsibilities

    The leader serializes all client writes and replicates logs to followers, causing CPU and network load concentration.
  2. Step 2: Analyze scaling impact

    At 10x scale, leader's CPU and network become bottlenecks before followers or network saturate.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Leader handles all writes and replication -> first bottleneck at scale [check]
Hint: Raft leader handles all writes and replication -> bottleneck at scale [check]
Common Mistakes:
5. At 10x scale, which component in the hotel booking system is most likely to fail first and why?
hard
A. The distributed lock service because it becomes a bottleneck coordinating locks across many nodes
B. The API Gateway because it cannot route the increased number of client requests efficiently
C. The Inventory Service because it maintains stateful caches that cannot be sharded easily
D. The relational database because it cannot handle the increased write throughput for reservations

Solution

  1. Step 1: Identify bottlenecks at 10x scale

    Distributed lock service coordinates exclusive access and must handle many concurrent lock requests.
  2. Step 2: Evaluate component scalability

    Relational DB (The relational database because it cannot handle the increased write throughput for reservations) can be scaled with sharding and read replicas. Inventory Service caches (The Inventory Service because it maintains stateful caches that cannot be sharded easily) can be sharded or invalidated. API Gateway (The API Gateway because it cannot route the increased number of client requests efficiently) can be horizontally scaled with load balancers. The lock service (The distributed lock service because it becomes a bottleneck coordinating locks across many nodes) is a centralized coordination point and becomes a bottleneck due to synchronization overhead and network latency.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Distributed lock service bottlenecks first due to coordination overhead [check]
Hint: Distributed locks bottleneck first at scale due to coordination overhead [check]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard