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.
Video lesson · Chapter 1 of 5
The share link arrives before every picture size is ready
Theory
Read or listen first. About 1 min.
What it is
An image hosting service stores a picture and gives back a short link. Anyone with the link can see the picture, in a page, a forum or a chat.
Inside it is three systems: a careful one that accepts and checks uploads, a patient one that prints each picture in several sizes, and a very fast one that hands out finished copies. They meet only in storage.
Why it exists
A picture from a phone is large, may contain the place where it was taken, and may be in a format some browsers cannot show. Sending it as it is wastes traffic and can hurt the person who took it.
A link also has to survive success. One picture in a million becomes famous within an hour. If each view cost the origin anything, the famous picture would take all the others down.
A short history
1987
GIF appears, a small image format that later also carries animations.
1992
The JPEG standard makes photographs small enough to share.
2006
Amazon S3 opens on 14 March: storage for files as a service.
2009
Imgur starts in February, announced in a post on Reddit.
2017
RFC 8246 adds
immutableto HTTP caching, for files that never change.
Words to know
- Original
- The file exactly as uploaded. Kept private.
- Variant
- A finished copy in one size and format.
- Exif
- Data inside a photo file: camera, time and often the place.
- Edge
- A cache close to the viewer.
- Origin shield
- One more cache between all edges and the store.
- Content hash
- A fingerprint of the bytes. Equal bytes give equal hashes.
- Delete token
- A long secret that lets an anonymous uploader remove a picture.
- Purge
- Telling caches to drop a copy now.
Solve it like an interview
New to it? Start with Approach. Revising? Go straight to the mock.
- 1ApproachWhat this question tests, where it gets hard, and how to spend the time.
- 2ScopeAsk what changes the design, then commit to a short list.
- 3NumbersWork out a number when the answer changes what you build.
- 4API and dataThe contract first, then the data that serves it.
- 5DesignStart with the smallest system that works. Change it only when something breaks.
- 6Deep divesCompare the options before you open them, then say which you would pick.
- 7Explain your choicesAnswer first. Then compare your reasoning.
- 8By levelThe same question is judged differently for mid, senior and staff.
- 9MockAnswer against the clock, then score yourself.
How it works
Step through the idea, or press Play.
Hand in. The original goes to a private store, the link comes back
Understand it
Scope
What are we building?
A service like Imgur: anonymous or signed-in uploads of images up to 20 MB, short links, several sizes, albums, deletion and fast delivery worldwide. Social feeds and video have pages of their own: Instagram stories, Reddit, YouTube.
Upload
Straight to a private store, safe to retry, link in about a second.
Process
A queue and workers: check, clean, resize.
Serve
Edge, shield, store. 99 of 100 never reach the store.
Protect
Nothing public before checks; takedown everywhere.
Similar services
| Kind | Examples | Main idea |
|---|---|---|
| Quick image links | Imgur, ImgBB, Postimages, Catbox | Upload and share |
| Photographers | Flickr, Photobucket, Unsplash | Collections, large files, licences |
| Animations | Giphy | Search and short loops |
| Screenshots | Gyazo | Capture and link |
| Media API | Cloudinary | Transform by address |
The finished system
Where the design ends up
The whole system
Summary
The whole topic in one minute.
An image service accepts the original into a private place, answers with a link, and publishes only finished copies after checking and cleaning them in the background. Users wait a second for the link, and the picture follows.
Reads are 500 times more common than writes, and finished copies never change. So the edge keeps them, a shield collapses misses, and storage sees about one request in a hundred. Views are counted from edge logs, old files move to cheaper storage, and takedowns purge every layer.
- Answer the upload when the original is safe, not when every size is ready.
- Publish nothing until it is checked, cleaned and re-encoded.
- A finished copy never changes, so caches may keep it long.
- 95% at the edge and 80% of the rest at the shield leaves 1% for the store.
- Make the common sizes ahead and the rare ones on demand.
- Deletion is part of the design: record, files, shield, edge.