System Design AI

Design a Photo Sharing Service like Instagram: Junior, Senior, and Staff Answers

When you get asked to design a photo-sharing service like Instagram, the interviewer is looking for three things: how you break down a user-facing request, how you model the data, and how you reason about trade-offs at scale. Below is a step-by-step walk through the request path, the data model, and the design choices you should highlight at each interview level.

What the Interviewer Is Testing

  • Scalability reasoning – can you estimate traffic and size the system accordingly?
  • Data modeling – do you choose the right storage for photos, metadata, and timelines?
  • Trade-off awareness – consistency vs. latency, cost vs. performance, operational complexity.
  • Communication – clear, concise articulation of each component and why it exists.

Core Requirements and Driving Numbers

RequirementTypical Value (hedged)
Active users~100 M
Photos stored~1 B (each ~200 KB, total ~200 TB)
Feed reads per second~10 k reads/sec (assuming each user loads the feed 8 to 9 times a day)
Write throughput~12 photo uploads/sec (about 1 M a day, which reaches ~1 B photos in roughly three years)
Latency goal<200 ms for feed, <500 ms for upload

These numbers drive the choice of storage, caching, and async pipelines.

Request Path – One Hop at a Time

  1. Upload request – Mobile client sends a multipart POST to an API Gateway endpoint.
  2. Auth check – Lambda authorizer validates JWT against Cognito; passes user ID downstream.
  3. Photo storage – The service writes the raw bytes to S3 (object key = userId/timestamp.jpg).
  4. Metadata write – A Lambda writes photo metadata (userId, caption, tags, S3 URL) to DynamoDB (partition key = photoId).
  5. Feed propagation – An event is placed on an SQS queue; a worker (EC2 or Fargate) reads it and pushes the new photoId onto each follower’s timeline stored in DynamoDB (or a sorted set in ElastiCache for hot users).
  6. Edge caching – Nothing is pushed to CloudFront: it caches the photo and its thumbnail at the edge the first time each is requested, so a new photo needs no invalidation.
  7. Response – The API returns the photo ID and CDN URL to the client.

Read path (feed request)

  1. Client calls /feed?userId=… → API Gateway → Lambda.
  2. Lambda checks a recent-feed cache in ElastiCache (Redis). If hit, returns list of photoIds.
  3. If miss, Lambda queries DynamoDB for the user’s timeline, stores result in Redis with a TTL, and returns it.
  4. Client loads each photo from CloudFront, which pulls from S3 if not cached.

Data Model Overview

  • Photos – S3 objects, key pattern userId/timestamp.jpg.
  • Metadata table (DynamoDB) – photoId (PK), userId, timestamp, caption, tags, s3Url.
  • User timeline table (DynamoDB) – userId (PK), timestamp#photoId (sort key), so a query returns the newest photos first. Hot users may have a Redis sorted set for faster reads.
  • Followers table (DynamoDB) – userId (PK), followerId (sort key), one item per follow edge, because a single item is capped at 400 KB. Used by the async worker to fan-out updates.

Key Choice and What It Was Chosen Over

  • DynamoDB vs. Aurora – DynamoDB gives single-digit millisecond latency and scales write throughput without manual sharding, which matters for the fan-out: uploads are only ~12/sec, but each one writes a timeline item per follower, so at, say, 300 followers on average that is ~3,600 timeline writes/sec. Aurora would add relational joins but would need read replicas and careful partitioning to meet the same latency.
  • Redis (ElastiCache) vs. in-process cache – A managed Redis cluster with replicas in several AZs stays available when a node or AZ fails and can be sized independently of the compute layer. An in-process cache would not survive instance failures and would limit horizontal scaling.
  • SQS vs. Kafka on MSK – SQS is fully managed, offers at-least-once delivery, and is sufficient for the fan-out pattern. Kafka would add operational overhead for a use case that does not need ordered processing across partitions.

What a Complete Junior Answer Covers

  • Lists functional requirements (upload, feed, likes, comments) and non-functional goals (latency, scalability).
  • Sketches a simple three-tier architecture: client → API Gateway/Lambda → S3 + DynamoDB.
  • Mentions a CDN (CloudFront) for photo delivery.
  • Shows the basic upload flow and a cache-less read path.
  • Names one obvious risk (for example, DynamoDB throttling during a traffic spike) but does not dive deeper.

What a Senior Answer Adds

  • Introduces caching (ElastiCache) for hot timelines.
  • Adds an asynchronous fan-out via SQS and worker nodes to avoid write amplification on the upload path.
  • Discusses sharding the timeline table by user ID hash to balance load.
  • Considers rate limiting (API Gateway throttling) and basic monitoring (CloudWatch metrics, alarms).
  • Mentions photo processing (thumbnail generation) with Lambda triggered by S3 events.

What a Staff Answer Adds

  • Failure modes – explains how to handle S3 upload failures, DynamoDB throttling, and SQS dead-letter queues. Shows a retry/back-off strategy.
  • Operations – outlines a deployment pipeline (CodePipeline → CloudFormation), blue-green releases, and canary testing for new features.
  • Cost analysis – names the cost drivers: ~200 TB of photos in S3 (billed per GB-month), read capacity for ~10 k feed reads/sec in DynamoDB, a small ElastiCache cluster, and CDN transfer for every photo view. Storage and CDN transfer dominate, so lifecycle rules that move older photos to cheaper storage classes and right-sized thumbnails are the first levers.
  • Trade-off defense – justifies eventual consistency of timelines for scalability, argues that strong consistency is unnecessary for a feed that tolerates a few seconds of staleness.
  • Observability – recommends structured logging, distributed tracing (X-Ray), and health checks on each service.
  • Security – mentions IAM roles, bucket policies, and encryption at rest (S3 SSE-S3, DynamoDB server-side encryption).

Common Mistakes That Sink This Question

MistakeWhy It Hurts
Ignoring storage costsPhoto blobs dominate cost; forgetting S3 leads to unrealistic budgets.
Over-engineering with microservicesAdds latency and operational burden without clear benefit at interview scale.
Forgetting the feed fan-outDirectly writing to every follower’s timeline synchronously kills write latency.
No caching strategyFeed reads become DB-bound, cannot meet sub-200 ms latency.
Skipping consistency discussionInterviewer expects you to articulate why eventual consistency is acceptable.

How to Practice This

  1. The worked design, Design a Photo Sharing App like Instagram, is part of Pro ($10/month). It opens on a walkthrough whose diagram grows from the junior answer to the staff answer.
  2. On a blank canvas, draw your own end-to-end diagram: start with the client request, place each AWS component, and annotate the data model.
  3. Use the practice brief's rubric (free to read) to rehearse explaining each component, the trade-offs you chose, and how you would handle failures.

Questions people ask

What are the most important scalability concerns for a photo sharing service?

You need to handle a high write rate for uploads, massive storage for photos, and fast reads for feeds. Use S3 for objects, DynamoDB for metadata, and a cache like ElastiCache to keep hot timelines quick.

Why is DynamoDB preferred over a relational database for this design?

DynamoDB provides single-digit millisecond latency, automatic scaling, and easy partitioning, which matches the bursty write pattern of photo uploads better than a relational DB that would need manual sharding.

How do you ensure the feed stays fresh without hurting upload latency?

Use an asynchronous fan-out: after a photo is stored, place an event on SQS. Workers read the event and update follower timelines in DynamoDB or Redis, decoupling the upload path from the fan-out work.

What is a common pitfall when designing the read path for a photo feed?

Skipping caching. Without a Redis layer, each feed request hits DynamoDB directly, leading to high latency and unnecessary load. A tiered cache keeps hot timelines fast and reduces DB reads.