Design the web client of a photo sharing application like Instagram.
Core screens:
Constraints from the interviewer:
Focus on the client: image delivery and loading strategy, upload pipeline, data model, API and UX details.
A photo app shares a lot with a generic news feed (pagination, reactions, optimistic updates). Don't repeat that whole design; say so and spend the time where this product differs: image delivery, the upload and editing pipeline, public SEO-friendly profiles, and modal routing between grid and detail.
/p/:id); direct visits render a full page.| Concern | Target |
|---|---|
| LCP | < 2.5 s p75 on mobile 4G; the LCP element is the first photo |
| CLS | < 0.05 — images must never shift the layout |
| Image bytes | first viewport ≤ ~300 KB of images on mobile |
| Upload | survives a network drop; 10 photos upload in parallel with per-file progress |
| Editing | crop/filter preview at 60 fps on mid-range phones |
| SEO | profile and post pages server-rendered with Open Graph tags |
| Scale | profile grids with 10k+ posts |
Stories, Reels/video editing, DMs, explore ranking, server-side image processing internals (we specify what we need).
OffscreenCanvas availability.)| Route | Strategy | Why |
|---|---|---|
/:username (profile) | SSR + CDN caching with short TTL, hydrate | SEO, link previews, fast LCP for shared links |
/p/:id (post page) | SSR | SEO and OG tags (og:image) |
/ (home feed, logged in) | SSR shell + first posts streamed, CSR after | personalised, no SEO; fast first image |
/create | CSR, code-split | heavy editor code only for creators |
The editor (canvas code, filters, crop gestures) can easily be 100+ KB; lazy-load it on "Create" intent (hover or tap on the + button) so viewers never pay for it.
<AppShell> // nav, bottom tab bar on mobile
<Routes>
<HomeFeed>
<PostCard>
<PostHeader />
<MediaCarousel /> // scroll-snap, dots, lazy neighbours
<ActionBar /> // like, comment, share, save
<LikesSummary /> <Caption /> <CommentPreview />
<ProfilePage>
<ProfileHeader />
<ProfileTabs /> // posts, saved, tagged
<PhotoGrid> // virtualized rows of 3 thumbnails
<GridTile />
<PostModal /> // rendered over background route
<CreateFlow> // lazy
<FilePicker /> <CropStep /> <FilterStep /> <DetailsStep /> <UploadProgress />
Clicking a grid tile pushes /p/:id with history.state.background = '/alice'. The router renders the background
route (grid) and the modal. Closing the modal calls history.back(), so the grid's scroll position is intact.
Opening /p/:id directly (no background state) renders a full post page. Next.js parallel + intercepting routes
implement exactly this; in React Router you use a backgroundLocation in state.
type ID = string;
interface ImageAsset {
id: ID;
width: number; // original dimensions after crop
height: number;
dominantColor: string; // e.g. "#d8c3a5" for placeholder background
thumbhash?: string; // ~25-byte placeholder rendered to a tiny image
alt: string | null; // user-provided or auto-generated
// URL template rather than a list: the CDN resizes on demand
urlTemplate: string; // "https://img.example.com/{id}/{w}.{format}?v=3"
availableWidths: number[]; // [150, 320, 640, 1080, 1440]
}
interface Post {
id: ID;
authorId: ID;
media: ImageAsset[]; // carousel; 1..10
caption: string;
captionEntities: { type: 'mention' | 'hashtag'; offset: number; length: number }[];
likeCount: number;
viewerHasLiked: boolean;
viewerHasSaved: boolean;
commentCount: number;
createdAt: string;
}
interface Profile {
id: ID;
username: string;
fullName: string;
bio: string;
avatar: ImageAsset;
counts: { posts: number; followers: number; following: number };
viewerFollows: boolean;
isPrivate: boolean;
}
interface ClientState {
entities: { posts: Record<ID, Post>; profiles: Record<ID, Profile>; comments: Record<ID, Comment> };
lists: {
homeFeed: { ids: ID[]; cursor: string | null; hasMore: boolean };
profileGrid: Record<ID, { ids: ID[]; cursor: string | null; hasMore: boolean }>; // by profile id
};
ui: {
carouselIndex: Record<ID, number>; // per post, so returning to a post keeps its slide
composer: ComposerState | null;
};
}
interface ComposerState {
files: {
localId: ID;
file: File; // never stored in Redux devtools/serialised state
previewUrl: string; // object URL
crop: { x: number; y: number; width: number; height: number; aspect: '1:1' | '4:5' | '1.91:1' };
filter: 'none' | 'clarendon' | 'juno' | 'mono';
upload: { status: 'idle' | 'uploading' | 'done' | 'error'; progress: number; uploadId?: ID };
}[];
caption: string;
altTexts: Record<ID, string>;
}
Notes:
File objects and object URLs live outside serializable state (a ref or module-level map keyed by localId).File objects can be stored in IndexedDB too (they are structured-cloneable).GET /api/users/alice/posts?first=24&after=Y3Vyc29yOjI0
{
"posts": [
{ "id": "p_1", "media": [{ "id": "img_9", "width": 1080, "height": 1350, "dominantColor": "#c9b8a0",
"thumbhash": "3OcRJYB4d3h/iIeHeEh3eIhw+j2w", "alt": "Sunset over the harbour",
"urlTemplate": "https://img.example.com/img_9/{w}.{format}?v=1", "availableWidths": [150, 320, 640, 1080] }],
"likeCount": 210, "commentCount": 14 }
],
"pageInfo": { "endCursor": "Y3Vyc29yOjQ4", "hasNextPage": true }
}
The grid needs only thumbnails and counts; the detail view fetches caption, comments and full media. Separate list and detail shapes (or GraphQL fragments per component) keep the grid payload tiny.
Pagination: cursor-based (keyset on createdAt, id). New posts are added to the top of a profile while
someone scrolls it; offsets would produce duplicates. Page size 24 = 8 rows of 3, a multiple of the column count
so rows are always full.
PUT /api/posts/p_1/like -> 204 (idempotent)
DELETE /api/posts/p_1/like -> 204
POST /api/posts/p_1/comments { "text": "Wow", "clientMutationId": "c-12" }
PUT /api/users/alice/follow -> { "status": "following" | "requested" } // private accounts
POST /api/uploads
{ "fileName": "IMG_2041.jpg", "size": 1834221, "mimeType": "image/jpeg", "sha256": "…" }
-> { "uploadId": "up_7", "chunkSize": 1048576, "uploadUrl": "https://upload.example.com/up_7" }
PATCH https://upload.example.com/up_7
Upload-Offset: 0
Content-Type: application/offset+octet-stream
<first 1 MiB of bytes>
-> 204 No Content, Upload-Offset: 1048576
HEAD https://upload.example.com/up_7 -> Upload-Offset: 1048576 // after a network drop, resume from here
POST /api/posts
{ "media": [{ "uploadId": "up_7", "crop": {...}, "filter": "juno", "alt": "Dog on a beach" }],
"caption": "Saturday #beach", "clientMutationId": "post-55" }
-> { "post": { ...full post... } }
Resumable, chunked uploads (the tus protocol is an open standard for this) mean a 4G drop at 90% doesn't
restart the upload (the example above follows tus-style PATCH + Upload-Offset; Google-style resumable uploads
with Content-Range work the same way). Uploads start as soon as photos are selected, in the background, while the user crops and
writes a caption. By the time they hit "Share" the bytes are usually already on the server and publish is instant.
Whether to send the crop/filter as parameters (server renders) or as baked pixels (client renders) is a trade-off: parameters keep the original for re-editing and consistent output, baked pixels save server CPU and guarantee what-you-see-is-what-you-get. A common hybrid: upload the resized original + parameters; the server renders the final variants.
interface ResponsiveImageProps {
asset: ImageAsset;
sizes: string; // e.g. "(max-width: 600px) 100vw, 600px"
priority?: boolean; // LCP candidate
className?: string;
}
interface PhotoGridProps {
profileId: ID;
columns?: 3; // fixed for Instagram-like layout
onTileClick: (postId: ID) => void;
}
interface MediaCarouselProps {
media: ImageAsset[];
initialIndex?: number;
onIndexChange?: (i: number) => void;
onDoubleTap?: () => void; // like gesture
}
srcset built from availableWidths and an accurate sizes. A 3-column grid tile on a 390 px
phone needs ~130 CSS px × DPR 3 = 390 px, so the 320 or 640 variant; never the 1080.<picture> with type sources, or let the image
CDN negotiate via the Accept header (fewer bytes of HTML; needs Vary: Accept).fetchpriority="high", no
loading="lazy", and an SSR <link rel="preload" as="image" imagesrcset="…" imagesizes="…">.loading="lazy" + decoding="async".width/height attributes (or aspect-ratio) from the API dimensions. Paint dominantColor or a
decoded thumbhash as the placeholder, fade in on load.?v=), served with
Cache-Control: public, max-age=31536000, immutable. Re-edits produce a new version.content-visibility: auto on rows.pointerdown.<input type="file" accept="image/*" multiple> plus drag-and-drop. HEIC from iPhones: Safari converts to
JPEG when using the file input with accept="image/*" in most cases; otherwise convert server-side.createImageBitmap(file, { imageOrientation: 'from-image' }) handles EXIF
orientation; draw into an OffscreenCanvas in a Web Worker, resize to ≤ 2048 px long edge, encode with
convertToBlob({ type: 'image/jpeg', quality: 0.85 }). A 6 MB photo becomes ~500 KB, a 10× upload speedup on
mobile. Re-encoding through canvas strips EXIF (including GPS) as a side benefit.filter for preview
or a WebGL shader for exact parity with server output. Render a final pixel version only when needed.XMLHttpRequest
upload.onprogress (fetch upload progress is not yet broadly available).beforeunload
confirmation only while an upload is active.touch-action: manipulation so the
browser doesn't zoom. The heart animation uses transform/opacity only (compositor-friendly) and respects
prefers-reduced-motion.scroll-snap-type: x mandatory for native-feeling swipes without JS gesture code; JS only
tracks the active index via IntersectionObserver or scrollend.<title>, meta description, canonical URL, and Open Graph/Twitter tags
(og:image pointing to a 1080 px JPEG — some crawlers don't handle AVIF).ImageObject, ProfilePage schema.org types) where useful.noindex.<dialog> with showModal(), focus trapped, Escape
closes, focus returns to the tile).aria-pressed.Intl.NumberFormat(locale, { notation: 'compact' }) → "1.2M", "120万").dir="auto"; hashtags in non-Latin scripts must be supported by the entity parser
(Unicode-aware regex with \p{L}).img-src limited to the image CDN.img load errors per CDN region.srcset generation and sizes math.<img> must use the ResponsiveImage
component; CI checks on LCP image size).Why not just use loading="lazy" on all images? Lazy-loading the LCP image delays it until layout, hurting LCP
significantly. The first visible images must be eager and high priority.
How do you choose between thumbhash/blurhash and a dominant color? Dominant color is free (one CSS value) and looks clean; hashes look nicer but need a small decode step (do it once, cache as a data URL). Both avoid empty boxes.
How would you support video posts? Poster image as LCP, preload="none", mount the player near the viewport,
autoplay muted when ≥ 50% visible, adaptive streaming (HLS/DASH via MSE). See the video streaming question.
The modal and the full post page need the same data. How do you avoid fetching twice? Normalized cache: the grid already has a partial post; render that immediately and fetch the remaining fields (comments, full caption).
How would you handle a user uploading 10 photos on a slow connection? Resize client-side, upload 2–3 concurrently, resumable chunks, start during editing, show per-photo progress, allow the user to leave the screen (upload continues in the app; Background Fetch API is an option where supported).
Spotted a mistake or a rights concern? Report an issue