Photo and video sharing with a home feed — worked through the TOGAF ADM so media storage, the follow graph, and feed fan-out each land in the right phase.
Instagram, the ADM way, in 30 seconds
- Why TOGAF here: it separates the two halves of the problem — storing media and assembling a feed — so neither gets solved with the wrong tool.
- A (Vision): upload photos/videos, follow people, and see a fast, fresh home feed; principles — read-optimized, media-heavy, horizontally scalable.
- B (Business): capabilities — upload media, follow users, view a profile, and the big one, build the home feed.
- C (Data/App): media blobs vs. small metadata rows; a follow graph; a feed built from both.
- D (Technology): media to blob storage + CDN, metadata in a DB, the follow graph sharded, and the feed via fan-out — push for normal users, pull for celebrities.
- E–H: ship upload + profile, then the feed, then the hybrid fan-out; govern with freshness SLOs and storage budgets.
- The lesson: the feed's hard part — the celebrity problem — is the same hybrid fan-out from the news feed; TOGAF just puts it in Phase D where it belongs.
Like a gallery wall and a daily bulletin, run by the same building
Think of a huge art building. One job is the gallery: hang each artist's photos somewhere a visitor can walk up and see them instantly, in full size, no matter which room they're standing in. A totally different job is the daily bulletin board by the entrance: for each visitor, pin up a fresh list of the newest pieces from exactly the artists that visitor chose to follow. Same building, two completely different jobs — and if you try to run them with one system, both get worse.
The gallery problem is about big, unchanging files served fast to crowds everywhere (that's photos and videos). The bulletin problem is about assembling a personalized list quickly for every visitor, every time they walk in (that's the home feed). Instagram is these two problems bolted together, and the whole design is about giving each its own right tool — then noticing that one artist with ten million fans breaks the naive bulletin approach.
What makes it hard — the problem before the solution
- A post is three different data shapes. The media bytes (huge, immutable), the post metadata (tiny, queryable), and the follow graph (billions of edges) each want a different home.
- Media is petabyte-scale and must load fast everywhere. You can't push photos and videos through app servers or a database — the bytes and the bandwidth bill would crush both.
- The feed is read far more than it's written. Everyone scrolls constantly and posts rarely, so the feed must be pre-built for instant reads, not assembled live from the graph on every open.
- One celebrity breaks the obvious feed design. Pushing a new post to every follower is fine for normal users but catastrophic for an account with ten million followers — a single post would mean ten million writes.
Why the ADM fits
Instagram is really two systems wearing one app: a media pipeline (upload a big file, serve it fast worldwide) and a feed system (merge the recent posts of everyone you follow). They have totally different data shapes and failure modes, and the quickest way to make a mess is to blur them together. The ADM keeps them apart: Phase C names media blobs, metadata, and the follow graph as distinct things, so Phase D can give each the right technology — object storage and a CDN for media, a sharded database for metadata, and fan-out for the feed.
Phase A — Architecture Vision
Intent: agree what we're building and the principles that constrain every later choice.
- Vision: let people upload photos and videos, follow others, and open the app to an instant, fresh home feed of the accounts they follow.
- Stakeholders: viewers (want the feed and media to load instantly), creators (want uploads to be reliable and appear quickly), the business (wants storage and bandwidth costs controlled at huge scale).
- Principles (the constraints that cascade): read-optimized first (feed views and media loads dwarf uploads); media-heavy (the bytes are photos/videos, not text); horizontally scalable (no single box is the ceiling).
Phase B — Business Architecture
Intent: model the business capabilities before any technology talk.
- Value stream: creator uploads media → followers' feeds update → a follower opens the app → sees recent posts → taps to view full media.
- Capability 1 — Upload media: moderate volume, large payloads, must be reliable and durable.
- Capability 2 — Follow / unfollow: builds the social graph that the feed depends on.
- Capability 3 — View profile / post: read a specific user's or post's media and metadata.
- Capability 4 — Build the home feed: the highest-volume, most latency-sensitive capability, and the hardest to scale.
Impact: reads dominate overwhelmingly, and the feed is both the hottest and the trickiest capability because of users with millions of followers. That asymmetry, found in Phase B, is what forces the hybrid fan-out decision in Phase D.
Phase C — Information Systems Architecture (Data & Application)
Intent: define the data and application architecture and the distinct entities hiding in 'a post'.
Data architecture
- Media blobs: the actual photos and videos — large, immutable, best served from the edge.
- Post metadata: small rows —
postId, authorId, caption, createdAt, and pointers to the media in blob storage. - Follow graph: who follows whom — a huge set of
(follower, followee)edges that the feed reads constantly. - Feed data: per-user timelines of recent post IDs, which can be precomputed or assembled on demand.
- Conclusion: media, metadata, and the graph are three different shapes with three different stores. (See SQL vs NoSQL.)
Application architecture
- Stateless app tier for upload, profile, and feed, scaling horizontally per the Phase A principle.
- A separate media pipeline that handles upload, processing (thumbnails, transcoding), and storage, off the request path.
- A feed service that assembles timelines, decoupled from upload via a queue so a post publish does not block the uploader.
Phase D — Technology Architecture (the core)
Intent: choose the concrete technologies that realize Phase C and justify each against the principles. This is where an interviewer spends the time, so we cover every step.
D1 — Estimate the load (sizing drives technology)
# 500M daily active users, ~100M posts/day
upload_per_sec = 100_000_000 / 86_400 # ~1,160 uploads/sec
# Read-heavy: each user opens the feed several times a day
# say 500M * 20 feed-views/day
feed_view_per_sec = 500_000_000 * 20 / 86_400 # ~115,000 feed views/sec
# Media storage: 100M posts/day * ~2 MB avg * 365 * 5y ~ 365 PB
# Metadata: 100M/day * ~300 B * 365 * 5y ~ 55 TB of small rows
#
# Verdict: reads crush writes (~100:1); media is petabyte-scale.
# -> media to object storage + CDN; feed must be precomputed, not joined live.The numbers confirm the Phase B asymmetry: a ~100:1 read:write ratio, petabytes of media, and a feed read rate far too high to assemble by querying the follow graph on every request. Those facts dictate the media path and the fan-out decision below.
D2 — The media pipeline
- Upload to object/blob storage (e.g. S3-style); the app server returns quickly and never streams bytes through the database.
- Process asynchronously: generate thumbnails and transcode video to multiple bitrates in a worker off the request path, triggered via a queue.
- Serve through a CDN (see CDN) so media is delivered from an edge near the viewer — the heart of read-optimized first and media-heavy.
- Store only a pointer (the object key / URL) in the post metadata, never the bytes.
Why media in blob + CDN, and not the obvious database?
The naive instinct is 'a post is a record, store the whole thing — photo included — in the database.' It even works for a prototype. But a database is built for small rows you query and update; it is miserable at holding and shipping multi-megabyte files, and every byte you serve from it leaves your most expensive network. At Instagram scale that choice doesn't just cost more, it caps your growth. Blob storage holds the bytes cheaply and durably; the CDN caches them at the edge so the bandwidth leaves cheap edge networks near the viewer.
| Approach | What it buys | The gap it can't fill |
|---|---|---|
| Media in the database | One store; a post is a single row. | Rows bloat to megabytes, backups explode, every view burns premium egress — it won't reach petabyte, global scale. |
| Media on app-server disk | Simple; fast for one box. | Not shared or durable; lost when a server dies; no global delivery. |
| Blob storage + CDN (chosen) | Cheap, durable, unbounded; served from an edge near the viewer; origin shielded. | The post row now holds only a pointer and media is eventually consistent after processing — both fine. |
D3 — Metadata & the follow graph
- Post metadata lives in a horizontally scalable store, sharded by postId or authorId (see Sharding), holding the caption, timestamps, and media pointers.
- Follow graph is a massive edge set; store it so both directions are cheap to read — who do I follow (to build my feed) and who follows me (to fan a new post out).
- Replicate partitions (see Replication) so a node loss never loses posts or edges.
-- Small, queryable rows; the photo/video itself sits in blob storage + CDN (D2).
CREATE TABLE post (
post_id BIGINT PRIMARY KEY, -- shard key
author_id BIGINT NOT NULL,
caption TEXT,
media_url VARCHAR(256) NOT NULL, -- CDN URL of the blob, not the blob
media_type VARCHAR(16) NOT NULL, -- 'photo' | 'video'
created_at TIMESTAMP NOT NULL
);
-- Read a user's own posts (profile view), newest first.
CREATE INDEX idx_post_author ON post (author_id, created_at DESC);D4 — The home feed (the hard part: fan-out)
- Fan-out on write (push): when a normal user posts, push the post ID into each follower's precomputed timeline. Feed reads then just read a ready-made list — blazing fast.
- Fan-out on read (pull): for a celebrity with millions of followers, pushing to every timeline on each post is wasteful and slow, so instead pull their recent posts at feed-read time and merge them in.
- Hybrid is the answer: push for the many normal accounts, pull for the few huge accounts — exactly the model worked out in the news feed design. This is the single most important Phase D decision.
- Cache aggressively: keep hot timelines and hot post metadata in memory (see Caching); the feed read should rarely touch the primary store.
CELEBRITY_THRESHOLD = 1_000_000 # followers above this = pull, not push
def on_new_post(post, author):
if author.follower_count < CELEBRITY_THRESHOLD:
# Fan-out on WRITE: push the post ID into each follower's timeline.
for follower_id in author.followers():
timeline_cache.prepend(follower_id, post.id)
# else: do nothing now -> celebrity posts are pulled at read time.
def build_feed(user):
feed = timeline_cache.get(user.id) # precomputed (push) part
for celeb in user.following_celebrities(): # merge the pulled part
feed += recent_posts(celeb.id, limit=10)
return rank_by_recency(feed)Why hybrid fan-out, and why not just pick push or pull?
Each single strategy is tempting and each hits a wall. Pure push (write a new post into every follower's precomputed timeline) makes reads instant — but when a celebrity with ten million followers posts, that one tap becomes ten million writes, and the write tier drowns. Pure pull (assemble every feed live by querying the graph on each open) makes posting trivial — but a user following 500 accounts triggers 500 lookups per app-open, multiplied across hundreds of millions of opens a day, and the read tier drowns.
The hybrid wins because the two failure modes don't overlap. Ordinary accounts have few followers, so pushing their posts is cheap and keeps the common read instant. Celebrities have enormous reach but few posts relative to it, so pulling their handful of recent posts at read time is cheap and dodges the write explosion. You use each strategy exactly where its cost is low, and merge the two at read time — the same model as the news feed.
| Approach | What it buys | The gap it can't fill |
|---|---|---|
| Pure push (fan-out on write) | Instant reads from a ready-made timeline. | A celebrity post = millions of writes; the write tier melts on big accounts. |
| Pure pull (fan-out on read) | Trivial, cheap writes; nothing precomputed. | Every app-open fans out to hundreds of followee lookups; the read tier drowns. |
| Hybrid push + pull (chosen) | Push the many cheap accounts, pull the few huge ones, merge at read. | Needs a tuned follower threshold and a read-time merge — a small price for surviving both extremes. |
D5 — Edge, delivery & cross-cutting concerns
- Front everything with a load balancer (see Load balancing) and route media through the CDN.
- Rate-limit uploads and API calls at the gateway (see Rate limiting) to resist abuse and runaway clients.
- Idempotency: a retried upload or post must not create duplicates (see Idempotency).
- Consistency: a new post appearing in followers' feeds a few seconds later is fine — eventual consistency is an accepted trade (see Consistency models).
- Observability: track feed-build p99, cache hit-rate, fan-out lag, and media delivery (see Observability).
Scaling & bottlenecks — what breaks first
Turn the dial up and Instagram fails in a predictable order. The media path is engineered to be sturdy, so the first thing to buckle is almost always the fan-out — the place where one post multiplies into many writes.
| Breaks first as you scale | The symptom | The fix |
|---|---|---|
| Fan-out worker lag | New posts take minutes to appear in followers' feeds during a spike. | Autoscale fan-out workers; shard the queue; raise the celebrity threshold so fewer posts push. |
| A rising star just under the threshold | An account blows up but is still on the push path, causing write spikes. | Make the threshold dynamic; promote hot accounts to the pull path on the fly. |
| Cold CDN edge for viral media | A viral photo hammers the origin as every edge misses at once. | Pre-warm edges for predicted-hot media; tiered/origin-shield caching so one fetch fills many edges. |
| Timeline cache memory | Precomputed timelines for hundreds of millions of users overflow RAM. | Cap timeline length; evict inactive users; store post IDs and media pointers, never media bytes. |
def recent_posts(celeb_id, limit=10):
key = f"celeb_recent:{celeb_id}"
cached = cache.get(key)
if cached is not None:
return cached[:limit] # millions of followers reuse THIS one copy
posts = post_store.recent_by_author(celeb_id, limit)
# Short TTL: fresh enough for a feed, one DB read serves everyone until it expires.
cache.set(key, posts, ttl=30)
return posts
# Without this, N followers would each re-pull the same celebrity posts N times.Phases E & F — Migration Planning
- Sequence by risk: ship upload + profile view against blob storage, CDN, and a metadata DB first — a working photo app.
- Add the feed with pure push fan-out next, since most users are normal-sized.
- Introduce the pull path for celebrities only once big accounts make all-push too costly — the same expand-contract spirit as the TOGAF commerce scenario.
Phases G & H — Governance & Change
- Governance (G): define SLOs (feed-build p99, media availability), set storage and bandwidth budgets, and set content and moderation policies for uploaded media.
- Change (H): adding Stories, Reels, or ads is a bounded change — new post types and new feed-ranking inputs behind the same media pipeline and feed service, not a re-architecture, because media, metadata, graph, and feed were kept separate.
Instagram is the canonical 'media + social graph + feed' problem — the place where blob storage, a CDN, a sharded graph, and fan-out all meet.
Why it matters
- It teaches the media pattern: big immutable files to object storage + CDN, tiny pointers in the database.
- It forces the celebrity problem and the hybrid push/pull fan-out that answers it.
- It shows read-optimization at petabyte and six-figure-QPS scale.
If ignored
- Stream media through app servers or the database and bandwidth and storage costs explode.
- Assemble the feed by querying the follow graph live and feed reads collapse under load.
- Push to every follower of a celebrity and a single post triggers millions of writes.
Where it fits
- Phase D holds the media pipeline, metadata/graph stores, hybrid fan-out, and edge delivery.
- Phase C's three data shapes drive three stores; Phase A's media-heavy, read-first principles justify blob + CDN.
- It sits right beside the news feed as the richer 'now with media' version of the same feed problem.
Related topics
- Design a news feed: the hybrid push/pull fan-out reused for the home feed
- CDN: serves photos and videos from the edge
- Message queues: decouples upload, media processing, and fan-out
- Sharding: spreads post metadata and the follow graph across nodes
Interview lens
Questions it unlocks
- Design Instagram / a photo-sharing app.
- How do you store and serve media at scale?
- How do you build the home feed, and what about users with millions of followers?
60-second answer
I'd walk it as an ADM track so the two halves stay separate. Phase A sets principles — read-optimized, media-heavy, horizontally scalable. Phase B names upload, follow, view, and the big one, build the home feed, with reads dominating. Phase C splits the data into media blobs, small post metadata, and the follow graph. Phase D makes it concrete: media uploads go to object storage, are processed async into thumbnails and bitrates, and serve through a CDN, with only pointers stored in a sharded metadata DB; the follow graph is sharded for cheap reads both ways; and the feed uses hybrid fan-out — push post IDs into followers' precomputed timelines for normal users, pull at read time and merge for celebrities, exactly the news-feed model — all cached hard. Cross-cutting: load balancing, rate limits, idempotency, eventual consistency, and observability. E–H ship media and profile first, then push fan-out, then add the celebrity pull path, governed by freshness SLOs and storage budgets. The headline is that the celebrity problem forces the hybrid, and every choice traces to a principle or a number.
Common traps
- Routing media bytes through the app servers or the database instead of object storage and a CDN.
- Building the feed by querying the follow graph on every read instead of precomputing timelines.
- Using pure push fan-out and melting down when a celebrity with millions of followers posts.