AlgoViz

Design a podcast hosting platform

medium 45 min

Creators 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

Our systemCreatorPodcast APIPostgreSQLJob queueAudio workerRaw uploadsobject storageObject storageserved audio

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

SchedulerPostgreSQLand outboxFeed builderObject storagefeed versionsCDN edgePodcast app

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

    critical

    Apps 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

    critical

    An edit makes every app show the episode again.

    Wrong
    guid = slug(episode.title)
    Right
    guid = episode.guid   # set once
  • Requests taken for downloads

    major

    One app may send a dozen ranges; robots send more.

    Wrong
    downloads = count(lines)
    Right
    downloads = apply_rule(join_ranges(people(lines)))
  • New ads for each range

    critical

    The parts belong to different files.

    Wrong
    def get(range): return splice(choose_ads())[range]
    Right
    def get(plan_id, range): return segments(plans[plan_id])[range]
  • Trusting the job lock

    major

    A slow worker can outlive its lease and write later.

    Wrong
    lock(job); encode(); db.set(ready)
    Right
    put(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.