Design a podcast hosting platform
medium 45 minCreators upload episodes; thousands of apps we do not control find and download them through one public file, the feed.
See it run
An episode from a creator's laptop to somebody's pocket, and from log lines to a number that a sponsor believes.
Operations
Upload an episode
Text goes to the API, bytes go straight to storage, work goes to a queue.
Step 1 of 9
Describe
title
Episode 42
Title, time, season. The key makes a repeated request return the same draft.
Step 1: Describe
def create(show, meta, key): ep = db.insert_once(key, show, meta, state="draft") return ep, storage.start_multipart(ep.id)def complete(ep, sha, size): storage.join(ep.upload) check(ep.upload, sha, size) with db.transaction(): db.move(ep, "draft", "processing") outbox.add("process", ep.id)- Time
- minutes, resumable
- Load
- 3,000 a day
- Part
- 8 MB
- Limit
- 500 MB
The draft exists before the first byte, so an unfinished upload can be found and cleaned.
In the real world
The same podcast platform doing real jobs. Pick one and step through it.
A title contains a character that XML does not allow.
Step 1 of 4
Edit
version
9
The creator pastes a title from another program.
Step 1: Edit
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Expiring URLs in a public feed
criticalApps keep the URL and use it weeks later. They get 403.
Wrong<enclosure url="https://audio/ep_7.mp3?expires=3600"/>Right<enclosure url="https://audio/e/ep_7.mp3"/>Title or number as GUID
criticalAn edit makes every app show the episode again.
Wrongguid = slug(episode.title)Rightguid = episode.guid # set onceRequests taken for downloads
majorOne app may send a dozen ranges; robots send more.
Wrongdownloads = count(lines)Rightdownloads = apply_rule(join_ranges(people(lines)))New ads for each range
criticalThe parts belong to different files.
Wrongdef get(range): return splice(choose_ads())[range]Rightdef get(plan_id, range): return segments(plans[plan_id])[range]Trusting the job lock
majorA slow worker can outlive its lease and write later.
Wronglock(job); encode(); db.set(ready)Rightput(content_name, encode())db.move(ep, "processing", "ready")
Interview tips
Begin with the feed
- It is the interface to strangers.
- GUID, enclosure, date.
- Checked, versioned, swapped.
Then the bytes
- 57.6 MB, 28.8 PB a month, 267 Gb/s.
- One file for each episode.
- Straight to storage, straight from the edge.
Define the number
- One minute, 24 hours.
- Address, agent, episode.
- Keep the reason for each removal.
Stay small
- One service, workers, counting.
- PostgreSQL first.
- Split for load or crashes, not for fashion.