How to design a photo sharing app (frontend)
The first sections are free. The deep dives, level expectations and quiz are part of Pro.
On this page
- The problem
- Clarifying questions
- The requirements menu
- Non-functional requirements
- Core entities
- The API
- The high-level design
- What breaks first
- The deep dives
- Entity fields
- A feed of images that stays fast
- Uploading on a slow connection
- Images for every screen size
- Liking and commenting
- Variants
- What each level is expected to show
- The 30-second answer
- Quiz
The problem
The web client of a photo sharing app: a feed of photos from the accounts you follow, a page for a single photo with its caption, likes and comments, and an upload flow that shows progress and then the finished post. Photos are nearly all of what the page downloads, so the design turns on image bytes: each screen asks for a file sized for it, the photo in view starts at once while the rest wait until they're near, and a large upload goes up in pieces that can continue after the connection drops. Taps are answered from a client store that holds each post once, before the server has replied.
Clarifying questions
| Ask | Why it matters | A typical answer |
|---|---|---|
Who is the reader we design for first: a phone on a weak connection, or a laptop on office wifi? | It decides the hard case. A laptop hides most image problems; a phone on a slow connection shows them in the first second, and it sets the budget for the first photo. | A phone on a slow connection. The first photo should be on screen within 2.5 seconds, and a phone shouldn't download an image sized for a desktop. |
How large are the photos people upload, and where do they come from? | A camera photo from a phone is big, stores its rotation as a flag rather than in the pixels, and may carry the location it was taken. Each of those changes the upload path. | Phone camera photos, up to 50 megabytes in the hard case, on a connection that can drop. One photo at a time is the core; many at once is a follow-up. |
Who makes the smaller sizes of each photo: the server after upload, or the browser before it? | It decides whether the client ships image processing, whether the new photo can show the moment the file lands, and how much goes over the wire. | The server produces the sizes once the upload lands and tells the client when they're ready. The client may shrink or crop before sending when the product wants a cropped result anyway. |
Is the feed already ranked and paged by the server? | If the client had to rank, the data model and the paging change completely. A cursor from the server keeps the client to drawing what it is given. | Yes. The server returns pages of about 10 posts with a cursor for the next page. How it ranks them is out of scope. |
Do likes and comments from other people need to appear live while the reader looks at a photo? | Live updates from others mean a held-open connection or polling, which is a different design from showing your own tap at once. | No. Your own like or comment shows at once; counts from other people refresh when the post is fetched again. |
Which browsers and image formats do we support? Phones often produce HEIC files. | A format that not all browsers display changes where conversion happens and what the preview shows right after the pick. | Current browsers on phones and desktops. The server converts what it receives into formats the supported browsers can show, so the client doesn't carry a converter. |
Non-functional requirements
| Requirement | What it forces |
|---|---|
The first photo shows within 2.5 seconds on a phone | The first photo's file is named in the markup with high priority and is not lazy-loaded, nothing else heavy starts before it, and the file it gets is sized for a phone. Measured as Largest Contentful Paint on real visits, at the 75th percentile. |
Images never push the page around as they load: layout shift of 0.1 or less | Each post carries its image width and height, and each img gets them as attributes, so the browser reserves the box before a byte of the image arrives. The placeholder and the error state live inside that same box. The score of 0.1 is the test, not a literal zero: it allows a little measured shift, so the aim is that images themselves cause none of it. |
A phone never downloads a desktop-size image | The image host holds a few widths per photo, each post lists them with their widths, and the img says how wide it will display, so the browser can pick a file suited to the screen and its pixel density. Read it as the aim, not a literal rule: the browser makes the final choice, and a dense phone screen may fairly pick a file a laptop would also use. |
An upload survives a dropped connection without starting over | The file travels piece by piece to a server-issued address, the server keeps what it received and reports the offset, and the client continues from there instead of from the first byte. |
A tap answers within 200 milliseconds | A like or comment changes the client store and the screen before any request is sent; the server's reply then confirms it or rolls it back. Measured as Interaction to Next Paint. |
Core entities
| Entity | What it holds |
|---|---|
Photo post | The client's record of one photo, kept once by id and drawn by the feed card and by the photo page alike. |
Image size | One file of a photo at one width, as the server made it. |
Comment | One comment under a photo, drawn in a sending state until the server's confirmation arrives. |
Upload | One file on its way up, with enough recorded to continue after a drop. |
Feed state | What the feed screen knows beyond the posts themselves. |
The API
| Endpoint | Notes |
|---|---|
| Each post comes with its image width and height and the list of sizes with their widths, so the client can reserve the box and write the srcset without another call. The client asks for the next page before the reader reaches the end; techinterview.org's mobile feed guide suggests around the 60% mark. |
| Creates the upload and returns the address the bytes go to. The address can point at file storage rather than the API server, so the large body doesn't pass through it. |
| The resume pair, modeled on the tus protocol. PATCH carries the offset it writes at and the server returns the new one; after a drop, HEAD asks how much the server kept, and the next PATCH starts there. |
| Creates the post from a finished upload. The returned post may still be pending while the server makes its sizes; the client swaps the temporary id for the real one. |
| The like sends a state, not a toggle, so a repeated request is harmless and a burst of taps can send the last state alone. The comment returns the server's id, which replaces the temporary one. |
The high-level design
Step 1 of 4
A feed, end to end
Start with the plain data flow: the page calls GET /feed, keeps the posts in a client store, and draws a card for each one with an img pointing at the image host. It works, and it already shows the first problem: each card asks for the original file, all at once, with no dimensions, so the page jumps as each one lands and the photo on screen shares the connection with the photos below it.
What breaks first
The deep dives
A feed of images that stays fast. A reader on a phone with a slow connection opens the feed and scrolls through dozens of photos. When does each image start downloading, what holds its place until it arrives, and what does the reader see if one fails?
Uploading on a slow connection. Someone on a phone with a weak connection posts a large photo, and the connection drops when most of the file has gone up. Walk through the upload from the pick to the post in the feed, including what happens after the drop.
Images for every screen size. One photo shows on a small phone, a laptop, and a large screen with a dense display. Which file does each browser download, how does it decide, and how many files do you keep for each photo?
A concept that helps here: Responsive images: srcset and sizes
A concept that helps here: Loading imagesLiking and commenting. A reader double taps a photo to like it and then writes a comment, on a slow connection where the server takes a while to answer. What does the screen show at each moment, and what happens if the server says no?
Concepts this guide uses
Sources
- web.dev: Browser-level image lazy loading for the web
- web.dev: Serve responsive images
- web.dev: Optimize Largest Contentful Paint
- web.dev: Optimize resource loading with the Fetch Priority API
- web.dev: Optimize Cumulative Layout Shift
- web.dev: Web Vitals
- techinterview.org: Design Instagram Mobile: Feed, Stories, and the Photo Pipeline
- techinterview.org: Build a Profile / Avatar Upload with Cropping
- tus.io: Resumable uploads FAQ
- MDN: image-orientation CSS property
- Redux docs: Normalizing State Shape