SuryanandHome

Music Streaming (e.g. Spotify-class)

Problem statement

Stream millions of tracks globally with DRM, personalized playlists, offline downloads, and royalty reporting to labels.

How it works

  • Catalog stored as encrypted segments (AAC) in object storage + CDN.
  • Playback: client obtains widevine / FairPlay license after entitlement check.
  • Personalization: batch + online feature pipelines to ranking models.

Analogy: A gym membership card (entitlement token) unlocks specific machines (tracks) for a session; the floor layout (CDN) brings equipment close to you.

High-level design

Rendering diagram…

Components explained — this design

ComponentWhat it isWhy we use it here
Encoding pipelineTranscodes masters to streaming formats.CPU-heavy; isolated workers autoscaled on queue depth.
S3 masters + segmentsStorage for source + packaged media.Durable, cheap bytes; lifecycle to Glacier for old masters if allowed.
CloudFrontCDN delivery of segments.Users worldwide pull from edge; reduces origin bandwidth cost.
Entitlement APIChecks subscription / purchase rights.Authorization separate from bytes delivery; short-lived JWT playback tokens.
License server (DRM)Issues keys for Widevine/FairPlay.Contractual requirement from labels; protects premium content.
Kafka + warehousePlay events → analytics/royalties.Decouple billing-grade logging from real-time playback path.

Shared definitions: 00-glossary-common-services.md

Low-level design

DRM

  • Google Widevine, Apple FairPlay, Microsoft PlayReady — multi-DRM packaging (Shaka Packager / AWS MediaPackage).

Entitlement

  • JWT short-lived playback token embedding user_id, track_ids, exp.
  • Stripe Billing for subscription state webhooks → update entitlements cache in Redis.

Personalization

  • Offline: Spark jobs compute Matrix Factorization / two-tower embeddings nightly to Feature Store (Feast on DynamoDB / Redis).
  • Online: candidate generation (similar artists) + lightweight ranker in Sagemaker endpoint.

Audio quality

  • ABR ladders 96–320 kbps; normalization (ReplayGain) in transcoding.

E2E: play a song

Rendering diagram…

Tricky parts

ProblemSolution
Caching DRM segmentsShort TTL signed URLs; per-user URL optional
Seek latencyIndependent segment alignment (2s segments)
Royalties accuracyIdempotent play logs; 30s rule industry standard

Caveats

  • Licensing is legal bottleneck — engineering cannot “solve” regional blackout.
  • HiFi lossless increases CDN egress cost linearly.

Azure mapping

  • Azure Media Services (retiring — plan migration to 3rd party or ffmpeg on AKS); PlayReady.