EasyStarter

Image Gallery & Album Service

StorageDatabasesCDNAPI Design

Problem Statement

SnapAlbum is building a simple photo gallery service. Users can:

- Upload photos - drag and drop images (JPEG, PNG, WebP) up to 20 MB each. Auto-generate thumbnails (small, medium, large).Albums - organize photos into albums with a title, description, and cover photo.Sharing - generate public gallery links. Viewers can browse photos in a masonry grid layout.EXIF data - extract and display camera info, date taken, and GPS coordinates (if present).Slideshow - full-screen slideshow mode for viewing albums.Download - download individual photos or entire albums as a ZIP file.

Targeting 20,000 users with 5 million photos total.

What You'll Learn

Design an image gallery service where users upload photos, organize them into albums, and share galleries. Build this architecture under realistic production constraints, then validate tradeoffs in the design lab simulation.

StorageDatabasesCDNAPI Design

Constraints

Registered users~20,000
Total photos~5,000,000
Uploads per day~20,000
Gallery load time< 500 ms
Thumbnail sizes3 (150px, 600px, 1200px)
Availability target99.5%
ApproachClick to expand

Interview-Ready Approach

1) Clarify Scope and SLOs

  • Problem statement: Design an image gallery service where users upload photos, organize them into albums, and share galleries.
  • Design for a peak load target around 100 RPS (including burst headroom).
  • Registered users: ~20,000
  • Total photos: ~5,000,000
  • Uploads per day: ~20,000
  • Gallery load time: < 500 ms
  • Thumbnail sizes: 3 (150px, 600px, 1200px)

2) Capacity Planning Method

  • Convert traffic and growth constraints into request rate, storage growth, and concurrency budgets.
  • Keep at least 2-3x safety margin per tier (ingress, compute, storage, async workers).
  • Reserve explicit latency budgets per hop so p95 can be defended in review.

3) Architecture Decisions

  • Storage: Use object storage for large blobs and keep metadata/authorization separate in the API tier.
  • Databases: Define a clear system-of-record and design read/write paths separately before adding optimizations.
  • CDN: Serve static and cacheable content from edge and keep origin strictly for misses and dynamic requests.
  • API Design: Standardize API boundaries, idempotency keys, pagination, and error contracts first.

4) Reliability and Failure Strategy

  • Enforce lifecycle policies, retention tiers, and checksum validation.
  • Use strong write constraints (transactions or conditional writes) and explicit backup/restore strategy.
  • Define cache keys and purge workflows before launch to avoid stale/global outages.
  • Apply strict input validation and backward-compatible versioning.

5) Validation Plan

  • Run one peak-load test, one dependency-degradation test, and one failover test.
  • Verify idempotency for all retried writes and async consumers.
  • Track user-facing SLOs first: p95 latency, error rate, and successful throughput.

6) Trade-offs to Call Out in Interviews

  • Storage: Object storage is cheap and durable, but random low-latency reads are weaker than databases/caches.
  • Databases: SQL gives stronger transactional guarantees; NoSQL often gives better write scaling and flexibility.
  • CDN: Long TTL improves latency/cost; short TTL improves freshness.
  • API Design: Rich APIs improve developer speed but can create long-term compatibility burden.

Practical Notes

  • Store originals in S3; generate thumbnails on upload using an image processing library (Sharp, Pillow) and store alongside.
  • Serve thumbnails from CDN for fast gallery loading - only fetch the full-resolution image when the user clicks to view.
  • Lazy-load images in the gallery grid (Intersection Observer) to reduce initial page load size.

Learn the Concept

Practice Next

Reference SolutionClick to reveal

Why This Solution Works

Request path: The solution keeps ingress, service logic, and stateful dependencies separated so each layer can scale independently.

Reference flow: Web Clients -> DNS -> CDN Edge -> API Gateway -> API Service -> Primary SQL DB -> Object Storage

Design strengths

  • The architecture keeps synchronous paths short and isolates stateful dependencies behind clear boundaries.

Interview defense

  • This design makes bottlenecks explicit (ingress, core compute, persistence, async workers).
  • It supports progressive scaling without re-architecting the core request path.
  • It keeps correctness-sensitive state changes in durable systems while offloading background work asynchronously.