← System Design

Design an Image Carousel / Photo Gallery

easy
Asked at
Airbnb
Airbnb

Problem statement

Design a masonry photo grid with lazy loading, a full-screen lightbox with keyboard and swipe navigation, pinch-to-zoom, adjacent-image prefetching, and CLS-free thumbnails.

Asked In

InstagramPinterestUnsplashAirbnbGoogle Photos

Key Challenges

  • ·Preventing Cumulative Layout Shift (CLS) with skeleton placeholders and intrinsic aspect ratios
  • ·Predictive Prefetching: Loading the 'next' and 'previous' images before the user swipes
  • ·Memory Management: Virtualizing large galleries to avoid 1GB+ browser heaps on mobile
  • ·High-Performance Animations: Using transform/opacity and GPU acceleration for 60fps swiping
  • ·Pinch-to-Zoom and Pan: Handling complex touch gestures and boundary constraints
  • ·Responsive Delivery: Serving WebP/AVIF based on DPR (Device Pixel Ratio) and bandwidth
  • ·Accessibility (WCAG 2.1): Keyboard traps in lightboxes, ARIA live regions for slide changes
★

2-Minute Answer — High-Level TL;DR

Read this before your interview

HLD Interview Focus

I would window the gallery so only a small DOM strip exists — typically previous, current, and next — while metadata for the album stays in a normalized store. Aspect-ratio boxes reserve space before decode to kill CLS. A prefetch engine warms neighbors; decoded bitmaps outside the window are released to cap memory. Keyboard arrows and focus rings are first-class; swipe uses transforms, not layout thrash. Deep links land on an index via scroll/jump without mounting the whole album. The hard part is memory + layout stability under thousands of assets.

→

My Approach: Building the Solution

How to think about this problem

I'll start from a 1,000-image album on a phone — what stays mounted — then design windowing, LQIP, prefetch, and lightbox focus.

Why This Approach?

Most candidates map images into a flex row of <img> tags. That answer melts a phone on a 1,000-photo album and shoves the layout when aspect ratios arrive late. Strong answers window the DOM, reserve aspect ratios to prevent CLS, and treat decode memory as a hard product constraint.

A gallery is a film strip behind a small window: you only light the frames in view plus a couple on each side. Lighting the whole reel melts the projector (the phone).

R

Requirements: What Makes a Great Solution?

Clarify scope before designing anything

Requirements Exploration Questions

Ask your interviewer these questions to refine requirements

What is the scale of the gallery?

  • ·Single carousel vs Infinite masonry grid
  • ·Total image count (10 vs 10,000)
  • ·Thumbnail vs Full-screen lightbox transition

What are the interaction requirements?

  • ·Swipe/Momentum scrolling (mobile)
  • ·Pinch-to-zoom / Pan support
  • ·Keyboard navigation (Arrow keys/Escape)
  • ·Download / Share / Full-screen API

What is the network/device target?

  • ·Adaptive bitrate (Low-res on 3G)
  • ·DPR-aware delivery (Retina vs Standard)
  • ·Offline access / PWA caching

Functional Requirements

Must Have — MVP

  • ✓Zero CLS layout with intrinsic ratios
  • ✓Lazy loading with Intersection Observer
  • ✓Adjacent image prefetching
  • ✓Responsive image support (srcset)
  • ✓Full-screen Lightbox mode
  • ✓Keyboard and Screen Reader support

Advanced (If Time Permits)

  • +Pinch-to-zoom with momentum
  • +Blur-hash or LQIP (Low Quality Image Placeholder)
  • +Video support in gallery
  • +Download as ZIP or batch actions
  • +Exif data metadata viewer

Non-Functional Requirements

Performance

  • ·LCP < 2.5s for the primary image
  • ·CLS = 0 (No layout shifts during load)
  • ·Interaction Latency < 16ms (60fps)
  • ·Memory heap footprint < 50MB for 100+ images

Reliability

  • ·Graceful degradation (Alt text if images fail)
  • ·Retry logic for network timeouts
  • ·Handling of corrupt binary data

Accessibility

  • ·Aria-live slide announcements
  • ·Focus trapping in lightbox
  • ·Semantic <figure> and <figcaption> usage
Premium

The full solution is part of HelloFrontend Pro

The question above is free to read in full. Upgrade to unlock the interactive workspace and the senior-level walkthrough that go with it.

  • Full RADIO-framework walkthrough with architecture diagrams
  • Data model, API design, and rendering strategy trade-offs
  • Performance, accessibility, and offline sections plus a model answer
Unlock the full solution →

Already a member? Log in to open the workspace.

More System Design questions

View all System Design →