Skip to content

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
Practice this question

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

AskWhy it mattersA 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.

The requirements menu

RequirementScopeWhy

Scroll a feed of photos from followed accounts, more loading as the reader goes

Core

The main screen, and where nearly all the image bytes go.

Open one photo on its own page with its caption, likes and comments

Core

A second screen that draws the same photo the feed drew, which is what makes a single client store worth having.

Upload a photo with a caption, seeing progress and then the post

Core

The one write path that moves a large file, and the one that must survive a dropped connection.

Like a photo and comment on it

Core

Small writes with a tight response budget; they show how the client handles a slow or refusing server.

Upload many photos at once

Optional

Take it if the interviewer raises it: it turns the single upload into a queue with a bound on how many files are in flight and progress per file. Leave it out of the core, since one photo already fills the round.

Crop or rotate the photo before posting

Optional

Take it if the product needs a square or cropped result, since then shrinking on the device also saves upload bytes. Leave it otherwise: the server can fix rotation and make the sizes.

Remove location data from the uploaded photo

Optional

Take it: a phone photo can carry where it was taken, and the server can drop that when it re-encodes the file. It costs a sentence and shows you thought about the reader's privacy.

Show other people's new likes and comments as they happen

Optional

Leave it unless asked. Refreshing the photo when it is opened covers the product, and a connection held open for each reader is more than a feed of photos needs.

Read the feed with no connection

Optional

Leave it unless asked. Keeping posts and images on the device raises storage and staleness questions that would crowd out uploads.

Messages between people

Out of scope

A messaging client is its own design, with a real-time transport the feed doesn't need.

How the server ranks the feed

Out of scope

The client receives a ranked page and a cursor; ranking is a backend question.

Stories and video

Out of scope

Video brings playback, buffering and data-saver rules that would double the round.

Photo filters

Out of scope

Pixel work on the device is a separate problem; the upload path doesn't change whether a filter ran first.

Non-functional requirements

RequirementWhat 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

EntityWhat 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

EndpointNotes

GET /feed?cursor&limit=10 → { posts, next_cursor }

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.

POST /uploads { size, type } → { upload_id, upload_url }

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.

HEAD {upload_url} → { offset }; PATCH {upload_url} at that offset with the next piece → { offset }

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.

POST /posts { upload_id, caption } → post

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.

POST /posts/{id}/like { liked } → { like_count }; POST /posts/{id}/comments { text } → comment

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

GETpostsimgServer APIClient storeFeed listPost cardImage host

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.

addressPATCHpendingGETpoststapsrcsetimglikeFile pickerUpload queueServer APIUpload storeServer makessizesImage hostClient storeFeed listPhoto pagePost card
The whole design

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?

A concept that helps here: Loading imagesA concept that helps here: Core Web VitalsA concept that helps here: List virtualization

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.

A concept that helps here: Chunked and resumable uploadsA concept that helps here: Blob storage and presigned uploadsA concept that helps here: Reconnect and resume

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: Loading images

Liking 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?

A concept that helps here: Optimistic updates and rollbackA concept that helps here: Client caching and normalized storesA concept that helps here: Debounce and request cancellation

Concepts this guide uses

Sources

  1. web.dev: Browser-level image lazy loading for the web
  2. web.dev: Serve responsive images
  3. web.dev: Optimize Largest Contentful Paint
  4. web.dev: Optimize resource loading with the Fetch Priority API
  5. web.dev: Optimize Cumulative Layout Shift
  6. web.dev: Web Vitals
  7. techinterview.org: Design Instagram Mobile: Feed, Stories, and the Photo Pipeline
  8. techinterview.org: Build a Profile / Avatar Upload with Cropping
  9. tus.io: Resumable uploads FAQ
  10. MDN: image-orientation CSS property
  11. Redux docs: Normalizing State Shape
Sign in to report a mistake