AlgoViz

Design an image hosting service (like Imgur)

medium 50 min

Upload a picture, get a link at once, and let the whole world look at it.

How to approach it

What this question tests, where it gets hard, and how to spend the time.

Read the question

What this problem tests

  • Can you split the work?

    Accepting, processing and serving have different speeds and different machines.

  • Can you serve reads?

    57,870 views a second, 17 GB a second, files that never change.

  • Can you order steps safely?

    A picture must be checked and cleaned before it can be cached anywhere.

  • Can you count money?

    12.6 TB more each day. Storage and traffic decide the design.

Think

Five questions before you draw

Ask yourselfHere
Who does what?Some people upload, strangers view, uploaders delete, reviewers decide
What must never go wrong?A picture is lost after the link was given, or a private place is published
What is the hardest thing?Fast links, safe publication and long caching at the same time
What breaks first as it grows?View traffic, then storage, then the records
What am I giving up?Seconds before sizes exist; minutes before counts are right

The path to keep in your head

Time

Spend the 45 minutes

MinutesDoLeave withSkip
0 to 5Images only, anonymous yes or no, size limitScope and targetsComments, filters
5 to 10Views, bytes a second, storage a dayCDN and storage decisionsCost per country
10 to 15Upload, get, delete, address of a sizeEndpoints and recordsEvery album call
15 to 25One server, then split itWorking upload and viewProduct names
25 to 40Pipeline, then caching and takedownTwo defended choicesCodec details
40 to 45Failures, cost, recapOne clear last sentenceNew features

Lines you can open with

  1. 1

    Start

    "I will treat upload, processing and viewing as three systems. Reads are the large one."

  2. 2

    Park something

    "Safety checks are one step for now. I will come back to the order."

  3. 3

    When stuck

    "Who waits for this, the uploader or the viewer?"

  4. 4

    Close

    "Originals are private, copies are immutable, 1% of views reach storage, and a takedown reaches every layer. Next I would test a purge under load."

Do

  • Say 500 to 1
  • Give the link before processing
  • Keep originals private
  • Say how a delete reaches caches

Traps

  • Files in the database
  • All sizes of everything
  • A year in the browser and a takedown promise
  • Counting each view in a row

Patterns inside this problem

PatternThe signalWhere it lands
Large filesMegabytes in each uploadDirect to storage, resumable
Background jobsSlow work the user need not awaitQueue and workers
Read-heavy500 views to one uploadEdge, shield, immutable copies
CountingMany small eventsLogs, sharded counters