Design a Photo and Video Sharing Platform at Scale
System DesignModel answerLast updated
Architect a social media platform where users upload media, follow others, and get a ranked home feed — covering storage, delivery, feed generation, and scaling trade-offs.
The Problem
You are tasked with designing the backend for a photo and video sharing social network. Users can create accounts, follow each other, post images and short videos, interact through likes and comments, receive activity notifications, and search for people or topics. Treat stories and direct messaging as stretch goals: acknowledge them and leave extension points, but do not design them in full.
Your answer should cover:
- Core APIs — the endpoints a mobile client would call, with pagination and idempotency considered
- Data models and storage choices — what goes where and why
- Media ingestion and delivery — upload flow, format transcoding, CDN strategy, and storage tiering
- Feed generation and ranking — how you build, store, and serve a personalized home feed efficiently
- Scaling and reliability — sharding, caching layers, hot accounts, consistency guarantees, and failure handling
- Back-of-the-envelope estimates — put rough numbers on storage, QPS, and egress before diving into design
- Evolution path — how the system grows from an MVP to global scale
What is expected:
State your assumptions clearly before designing. Interviewers reward structured thinking, honest trade-off discussions, and knowing which parts of the design are genuinely hard. You do not need to cover every bullet in equal depth — identify the two or three areas where interesting engineering decisions live and go deep there.
Hints
Hint 1
Start with scale assumptions and a quick capacity estimate — they should drive every storage and architecture choice you make afterward. Without numbers, trade-offs are just opinions.
Hint 2
The hardest parts are the media pipeline and feed generation. A good answer picks one of the two fan-out strategies (push vs pull), explains why neither alone works at scale, then describes the hybrid that most real systems use.
Hint 3
Hot accounts break your fan-out model and your engagement counters simultaneously. Call this out explicitly and explain the mitigation for each case — it signals that you understand where the real failure modes are.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Approach
This is a scoping and depth problem. A 45-minute design session cannot cover everything equally, so the goal is to set scope in the first five minutes, put rough numbers on the problem, and then go deep on the two genuinely hard parts: the media pipeline and feed generation. Everything else — auth, notifications, search — gets an honest sketch.
1. Requirements and Assumptions
Core functional scope: sign-up and auth, follow/unfollow, photo and video upload, personalized home feed, likes and comments, push notifications, user and hashtag search.
Key non-functional targets:
- Feed p99 latency under 300 ms
- Media first-byte under 1 s via CDN
- 99.95%+ availability
- Feeds can be eventually consistent (a few seconds of staleness is acceptable)
- A user's own actions must reflect immediately on their own profile (read-your-writes)
- Media must be durable — zero tolerance for loss
The system is heavily read-skewed. A reasonable read:write ratio is 100:1 for feed reads versus uploads.
2. Capacity Estimates
| Signal | Assumption | Result |
|---|---|---|
| Daily active users | 500M | — |
| Uploads | 100M / day | ~1,200 / s avg, ~5,000 / s peak |
| Storage per upload | 2 MB original + 3 MB renditions | ~500 TB / day added |
| Feed loads | 10 per user per day | ~60K QPS avg, ~200K peak |
| Likes and comments | 5B / day | ~60K writes / s |
| Media egress | 50 views × 200 KB × 500M users | ~5 PB / day |
Two things stand out: media egress dominates cost, so the CDN is not optional; and like counters on popular posts are a write hot spot that needs a specific solution.
3. Core APIs
POST /v1/media/upload-url → { upload_id, presigned_url }
POST /v1/posts { upload_ids[], caption, visibility } → post_id
GET /v1/feed?cursor=&limit=20 → { posts[], next_cursor }
GET /v1/users/{id}/posts?cursor=
POST /v1/users/{id}/follow
POST /v1/posts/{id}/likes
POST /v1/posts/{id}/comments
GET /v1/notifications?cursor=
GET /v1/search?q=&type=user|tag
Cursor-based pagination everywhere — offsets break under concurrent inserts. Write endpoints accept an Idempotency-Key header so network retries cannot create duplicate posts or double-likes.
4. Data Model and Storage
- Users: sharded relational DB (MySQL + Vitess) by
user_id. A separatehandle → user_idlookup table enforces uniqueness. - Posts: Cassandra or sharded MySQL, partitioned by
author_idand clustered bypost_id DESC. Post IDs come from a Snowflake-style generator so they are time-sortable without coordination. - Follow graph: two tables —
followers(user_id, follower_id)andfollowing(user_id, followee_id)— each partitioned by the first column. This makes both directions a single-partition read. - Likes:
likes(post_id, user_id)for deduplication; counts live in Redis with async rollup to the DB. - Materialized timelines: Redis sorted sets keyed by
feed:{user_id}, holding the 500–800 most recent candidate post IDs. - Media blobs: object storage (S3/GCS), keyed by content hash — identical uploads are stored once.
- Search: Elasticsearch fed by CDC from user and post tables.
5. Media Pipeline
Clients upload directly to object storage via a presigned URL — API servers never touch the byte stream. A storage event then triggers the media service:
- Validation and dedup: check file type, enforce size limits, strip EXIF location data, compute a content hash.
- Transcoding (async worker pool, autoscaled):
- Images → WebP/AVIF at 3–4 responsive widths, JPEG fallback.
- Video → HLS/DASH adaptive ladder (240p through 1080p) plus a poster frame.
- Moderation: CSAM hash matching and classifier-based nudity/violence scoring, blocking or flagging before the post goes live.
- Post status transitions
PROCESSING → READY. Fan-out begins only after this. The author sees an optimistic preview immediately — read-your-writes is satisfied locally. - CDN delivery: signed URLs with long TTLs work because media is immutable. Private-account media gets short-lived signed URLs regenerated per request.
- Storage tiering: hot object storage for recent uploads, infrequent-access tier after ~30 days, archive for originals after ~90 days.
6. Feed Generation
This is the hardest part of the design. The options form a spectrum:
Push (fan-out on write): when a user posts, write the post ID into every follower's timeline immediately.
- Fast reads, but catastrophic for accounts with millions of followers. A single post from a celebrity triggers hundreds of millions of writes.
Pull (fan-out on read): at read time, query recent posts from every account the user follows and merge.
- Cheap writes, but slow reads for users who follow thousands of accounts.
Hybrid (the correct answer for this scale):
- Regular accounts (below a threshold like 50K followers): push to the timelines of active followers only. Inactive users get no fan-out and their feeds are rebuilt from scratch on next login.
- Celebrity / high-follower accounts: skip fan-out entirely. Their recent posts live in a heavily cached "celebrity outbox." At read time, the feed service merges the materialized timeline with a real-time celebrity pull.
Ranking at read time:
- Pull ~500 candidates from the materialized timeline plus the celebrity merge.
- Filter: remove blocked accounts, already-seen posts, deleted or private content.
- Score with a lightweight model (GBDT or a two-tower retriever + heavier re-ranker) using signals like predicted like probability, comment probability, and dwell time, served from a feature store.
- Apply diversity and freshness rules, insert ads.
- Return top 20 with a cursor. Cache the ranked result per session for a few minutes to avoid re-ranking on every scroll.
7. Hot Account and Hot Post Problems
Hot account writes: the hybrid model above handles this — celebrities get no fan-out.
Hot post reads: a viral post generates millions of reads per second against the same cache key. Mitigations:
- In-process (L1) caches on API servers with a short TTL absorb the first layer.
- Request coalescing at the cache layer prevents stampedes on a cache miss.
- Like counters on hot posts use N sharded sub-counters summed at read time, rather than a single counter taking 60K writes per second.
8. Caching Layers
| Layer | What lives there |
|---|---|
| CDN | Media renditions, public profile assets |
| Redis (timeline) | Materialized feed post IDs per user |
| Redis (counters) | Like and follower counts |
| In-process (API tier) | Hot post metadata, celebrity outboxes |
9. Consistency and Reliability Trade-offs
Feed staleness of a few seconds is acceptable and simplifies the architecture enormously — eventual consistency is the right default here. Read-your-writes for the author's own content is a narrower guarantee and can be satisfied by routing the author's own reads to a primary replica or by using an optimistic local state on the client.
For multi-region resilience: media is replicated to at least two regions at write time. The follow graph and post metadata replicate asynchronously, with conflict resolution by last-write-wins on non-overlapping operations (follow/unfollow is idempotent). Feeds are rebuilt regionally — losing a Redis timeline is a latency hit, not a data loss event.
10. MVP to Planet Scale Evolution
MVP (single region, monolith + Postgres): build core flows with a simple pull-based feed and a single CDN origin. Validate product assumptions before optimizing.
Phase 2 (10M DAU): split media storage to object store, add Redis for feed timelines, introduce Kafka for async fan-out and notifications.
Phase 3 (100M+ DAU): shard databases, introduce the hybrid fan-out, add a ranking model, move to multi-CDN.
Planet scale: multi-region active-active for reads, regional fan-out workers, dedicated GPU transcoding fleet, ML feature store for real-time ranking signals.
Common Mistakes to Avoid
- Designing the feed as a pure push or pure pull — interviewers expect the hybrid.
- Forgetting that media egress at this scale costs more than storage; CDN strategy is not an afterthought.
- Using offset pagination on feed endpoints — inserts shift rows and produce duplicate or missing items.
- Ignoring the hot-counter write problem on viral posts.
- Skipping capacity estimates — every major architectural choice should trace back to a number.