Frontend System Design: Multi-Device Photo Albums
System DesignModel answerLast updated
Design the client architecture, normalized state, paginated sorted photo lists, direct-to-storage uploads, and near-real-time sync for a multi-device photo album web app.
You are asked to design, at a whiteboard level, the frontend architecture of a browser-based photo album product. Mockups exist for three screens:
- Albums screen — a grid of albums, each with a cover photo and a name.
- Album screen — the photos belonging to one album; from here the user can add photos and rename the album.
- Photo screen — metadata for one photo (capture time, city, etc.).
Required behaviors:
- Browse albums.
- Open an album and page through its photos.
- Rename an album.
- Upload one or several photos into an album.
- Edits made on one device show up on the user's other devices within seconds.
- Photos and albums can be sorted by city, in ascending or descending order.
Assume:
- Primary scenario is one user with several devices; sharing/collaboration is a future extension only.
- An account has tens to a few hundred albums; one album can hold thousands of photos, so the photo list must paginate.
- Photos are multi-megabyte binaries; metadata is tiny; reads vastly outnumber writes.
- "Near real time" means seconds, with eventual consistency; conflicting concurrent edits may be resolved rather than prevented.
cityis assigned by the server by reverse-geocoding photo EXIF GPS at ingest, ornullif unavailable. Users never type it.- The client is a modern SPA; binaries sit in object storage behind a CDN. Choose your own API style/transport and defend it.
The interviewer will probe component/data boundaries, normalization, where each piece of state lives, how sorting interacts with pagination, the upload lifecycle, the sync transport plus recovery from dropped events, and how thousands of photo tiles get rendered. Be explicit about your single source of truth — duplicate state is the thing they will attack hardest. State any further assumptions you need.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Assumptions I'll state first. One user, many devices; albums are private to that user (future sharing is an extension I'll call out). Album count is small; photos per album are large, so the photo list is cursor-paginated and windowed in the UI. Binaries go to object storage behind a CDN via signed URLs; the API only handles metadata. Metadata reads dominate; a few seconds of staleness is fine, so I'll design for eventual consistency with a reconcile path.
Single source of truth. All server data lives in one normalized client cache, keyed by entity type and id:
albums: { id, name, coverPhotoId, version, updatedAt }photos: { id, albumId, city, capturedAt, thumbUrl, fullUrl, status, updatedAt }albumPhotoIds: { albumId → { pages, idsBySortKey } }— the ordered id list per album per active sort, not copies of photo objects.ui: { route, albumId, sortBy, order, uploadQueue }— ephemeral, never persisted to the server cache.
Everything rendered is derived from these maps through memoized selectors; nothing is stored twice. A photo's city appears only in photos[id].city; the album grid's ordered ids point at those records. That kills the classic bug of a rename showing in the header but not the sidebar — there is one place to update. Sort order and filter are not materialized lists of objects; they are id sequences over the same records, recomputed by a selector when order changes. Local UI selections (current sort, open album) are the only state the server never owns.
Why normalize. Album rows, photo tiles, and the photo screen all reference overlapping records. If each screen held its own copy (e.g. the albums list storing a cover photo object), a rename or a completed upload would have to fan out to every copy. Normalizing collapses that into one write plus cache-invalidation. The cost is more selector plumbing; worth it here.
API surface (REST is fine and simplest; I'd pick it over GraphQL because the shapes are fixed and few):
GET /albums— small list, returns all.GET /albums/:id/photos?sortBy=city&order=desc&cursor=…&limit=…— returns photo records plus a next cursor.PATCH /albums/:id { name, version }— optimistic concurrency; server rejects ifversionmismatches.POST /uploads— create upload session, returns per-file signed PUT URLs and a photo id.POST /uploads/:id/complete— client tells server the bytes landed; server enqueues thumbnail/EXIF/geocode processing.- Sync channel (below) delivers
photo.ready,album.updated, etc.
Sorting + pagination — the subtle part. city is server-derived and can be null. Sorting must be server-side over the whole album, because the client only holds a few pages. The query keyset-paginates on (city, id) with nulls ordered last (or first — I'll pick last, documented) and a tie-break on id so pages are stable. When the user flips order, the client resets the id sequence for that album/sort and refetches page one; already-loaded photo records stay in the cache but the sequence is replaced. This is why the ordered ids live separately from the photo records: reordering the view doesn't touch the data. If the user asks to sort only loaded photos, that's a client-side sort of the sequence — I'd ask which they want, since "sort entire album" is what the pagination implies.
Upload flow. Two-step, binary-bypassing-the-API:
- User selects files; client immediately inserts optimistic placeholder photo records (
status: 'uploading', local blob preview) intophotosand the current sequence so they appear in the grid. - Client calls
POST /uploads, gets signed PUT URLs, uploads bytes directly to storage (parallel, retryable, resumable). - Client calls
complete; server runs async thumbnail + EXIF + reverse-geocode, then emitsphoto.readywithcity,thumbUrl,capturedAt. - Client's sync handler patches that photo record in place (still one source of truth — the placeholder becomes the real record). Placeholders that fail get
status: 'failed'and a retry affordance. Progress is tracked inui.uploadQueue, not in the photo record, so server cache stays clean.
Real-time sync. I'd use a WebSocket for bidirectional-ish needs and low latency, or SSE if I only push server→client (which is all I need here — writes go over REST). Either works; I'd pick SSE for simplicity if the backend already does REST, WebSocket if I expect to later multiplex interactive features. Message payloads are small deltas referencing ids (album.updated {id, name, version}), and the client applies them by patching the normalized cache. Crucially: a socket alone is not a correctness mechanism. On connect/reconnect, and on tab visibility change, the client runs a catch-up: refetch albums and the currently loaded photo page(s), reconcile by updatedAt/version. Deltas may arrive out of order or be missed while a tab slept; reconcile fixes both. This is eventual consistency handled explicitly rather than assumed away.
Rename concurrency. Album carries a version. Rename sends the version the user saw; a mismatch returns 409 and the client shows "this was changed elsewhere, reload." Alternative is last-write-wins (simpler, occasional lost edit) — I'd defend versioned writes because renames are deliberate and losing one silently is worse than a rare 409 toast.
Rendering thousands of tiles. Use a windowed/virtualized grid: only tiles in (or near) the viewport are mounted, with fixed-size cells so scroll height is computable. Images lazy-load via IntersectionObserver, requesting CDN thumbnail variants (?w=400) rather than originals. The virtual list consumes the ordered id sequence, so pagination just extends the sequence as the user nears the end.
States & caching. Each screen has loading, empty, error, and upload-in-flight states. Cache keys are the normalized ids; mutations invalidate by patching the single record. Browser caching for thumbnails is aggressive (immutable URLs), metadata is cheap to refetch.
Common mistakes to flag: storing album names in both a header component and the album record; sorting the wrong scope (loaded vs whole album); sorting a page after fetching it; uploading bytes through the API server; trusting the socket with no catch-up; and putting the whole album's photo objects in a flat array so reordering copies data. My design keeps one source of truth, sorts and paginates server-side, streams bytes around the API, and treats real-time as optimization with reconciliation as the safety net.