NelworksNelworks
Season 1

EP03 - Spotify Streaming

How Spotify's 'streaming' actually works. Learn about LRU cache, prefetching, encrypted chunks, Storage Manager architecture, and Spotify's P2P roots from uTorrent.

Tweet coming soon
No! I forgot to download my 'Pink Season' playlist!
I can't survive a 6-hour flight with just my thoughts!
It works? But I didn't click download!
It's a miracle. God is watching over me.
God had nothing to do with it. It was the **LRU Cache**.
Kurumi? Are you following me?
Anyway, put your headphones on. Let's talk about why your phone is a digital hoarder.
You think Spotify is a radio. You tune in, it plays.
Wrong. Spotify is a **Downloader** that's just quicker than your ears.
There is no 'Stream'. There are only chunks.
A 3-minute song: dozens of small encrypted bricks.
Saving it? But I didn't pay for premium downloads on this album.
Doesn't matter. The app keeps a secret stash — the **Cache**.
Up to a gigabyte (or more) of 'junk' on your phone. Songs from yesterday. Ones you *might* play next.
That song you just played? You listened to it last Tuesday. It never left your phone.
Fine, that's old songs. But what if I skip to the next one?
See? Instant. How did it know?
Because it **Prefetches**.
While you're on Song A, it snags the first 15 seconds of B, C, D.
It reads your queue. It checks your history.
Bandwidth bets on what you'll need next.
So it's guessing?
Basically! Playlist mode? Odds you want the next track? 99%.
So it grabs the start of the track before you even finish this one.
But what if I choose a totally random song? I'm offline!
Aha! It failed.
The magic has limits. It can only predict so much.
Still, kind of genius how Spotify handled this.
Maybe because Spotify was built by **Ludvig Strigeus**.
Who?
The guy who made **uTorrent**.
Wait. The pirate guy?
Spotify's roots: pure peer-to-peer piracy tech.
In the beginning, music didn't come from servers. *Other users* shared it.
Neighbor has your song? Your phone nabs the chunks. Saved Spotify millions in server costs.
They disabled that in 2014. Switched to Google Cloud. But the architecture's bones stayed.
File structure? Basically a torrent.
The what?
Here's the **Storage Manager**.
Spotify UI—the nice buttons—don't care where music lives.
It just tells the Manager, 'I need Track 5.'
Manager checks his filing cabinet (Cache). If there, he hands it over.
If not, he rings the Warehouse (CDN).
That's why it works offline. UI asks for a song — Manager says 'Got it.' UI never knows you're cutoff. The disk just looks like ultra-fast WiFi.
So it's all fragments? Little encrypted bricks?
AES-128 encrypted chunks. You got it.
Can't just copy or play. Without the key, they're just bricks.
So... my phone's a digital hoarder, lies about streaming, organized by piracy code?
Pretty much.