Design an image hosting service (like Imgur)
medium 50 minUpload 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 yourself | Here |
|---|---|
| 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
| Minutes | Do | Leave with | Skip |
|---|---|---|---|
| 0 to 5 | Images only, anonymous yes or no, size limit | Scope and targets | Comments, filters |
| 5 to 10 | Views, bytes a second, storage a day | CDN and storage decisions | Cost per country |
| 10 to 15 | Upload, get, delete, address of a size | Endpoints and records | Every album call |
| 15 to 25 | One server, then split it | Working upload and view | Product names |
| 25 to 40 | Pipeline, then caching and takedown | Two defended choices | Codec details |
| 40 to 45 | Failures, cost, recap | One clear last sentence | New features |
Lines you can open with
- 1
Start
"I will treat upload, processing and viewing as three systems. Reads are the large one."
- 2
Park something
"Safety checks are one step for now. I will come back to the order."
- 3
When stuck
"Who waits for this, the uploader or the viewer?"
- 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
| Pattern | The signal | Where it lands |
|---|---|---|
| Large files | Megabytes in each upload | Direct to storage, resumable |
| Background jobs | Slow work the user need not await | Queue and workers |
| Read-heavy | 500 views to one upload | Edge, shield, immutable copies |
| Counting | Many small events | Logs, sharded counters |