·

System Design Deep Dive - 15 How Instagram Handles Story Delivery

Post by ailswan May. 26, 2026

中文 ↓

🎯 How Instagram Handles Story Delivery


1️⃣ Core Story Framework (Staff-Level)

When discussing an Instagram-like story delivery system, I frame it as:

  1. Story creation and media upload
  2. Media processing and CDN delivery
  3. Story metadata service
  4. Viewer tray generation
  5. Seen-state tracking
  6. Expiration lifecycle
  7. Ranking and privacy controls
  8. Trade-offs: freshness vs fan-out cost vs storage vs privacy

2️⃣ Core Problem

Stories are short-lived, media-heavy, and read-heavy.

The system must handle:


👉 Interview Answer

An Instagram-like story system separates heavy media delivery from lightweight story metadata. Media is processed and served through CDN, while metadata services handle ranking, privacy, seen state, and expiration.


3️⃣ High-Level Architecture

Creator Upload
        ↓
Media Upload Service
        ↓
Object Storage
        ↓
Processing Pipeline
        ↓
Story Metadata Service
        ↓
Story Tray Ranking
        ↓
CDN Media Delivery
        ↓
Viewer Seen-State Updates

4️⃣ Media Processing

Processing tasks:


👉 Interview Answer

Story media processing should be asynchronous. The upload path stores the raw media and creates metadata, while background workers produce renditions optimized for mobile playback and CDN delivery.


5️⃣ Story Metadata

Metadata includes:

Metadata is much smaller and changes more often than media.


6️⃣ Story Tray Generation

The story tray answers:

Which creators have active stories for this viewer?
In what order should they appear?
Which stories are unseen?

Signals:


7️⃣ Seen-State Tracking

Seen state can be high volume.

Options:


👉 Interview Answer

Seen state should be optimized separately from media delivery. It is high-write metadata, so I would keep it in a scalable store and avoid coupling it to the CDN media path.


8️⃣ Expiration Lifecycle

Stories expire after a fixed window, commonly 24 hours.

Expiration can be handled by:

Important:

Reads must respect expiration even if cleanup has not physically deleted the media yet.


9️⃣ Staff-Level Trade-offs

Decision Benefit Cost
CDN media delivery Fast playback Cache invalidation and privacy complexity
Metadata separate from media Scales better More service coordination
Precompute story trays Fast reads Staleness risk
Compute tray on read Fresh and accurate Higher latency
Detailed seen state Better UX High write volume

中文部分

中文速记

一句话

Instagram Stories 的核心是 media delivery 和 metadata/ranking 分离:媒体走 CDN,story tray、seen state、privacy 和 expiration 走元数据服务。


背诵要点


中文面试回答

我会把 Instagram Story 系统拆成 media pipeline、story metadata service、tray ranking 和 seen-state service。 创作者上传图片或视频后,系统先把原始媒体持久化,再异步做 resize、transcode、thumbnail、安全检查和 CDN-ready rendition。 媒体本身通过 CDN 分发,降低 origin 压力并提高播放速度。

Story metadata 记录 story ID、creator、media URL、创建时间、过期时间、privacy 和 close friends 等信息。 当用户打开 app 时,tray service 会根据关系强度、recency、unseen state、互动历史和 privacy eligibility 决定展示哪些 story 以及顺序。

Staff 级重点是:story 的媒体流量和状态流量特征完全不同。 媒体是重读、适合 CDN;seen state 和 tray ranking 是高频 metadata,需要单独扩展。


✅ Final Interview Answer

An Instagram-like story delivery system should separate media, metadata, ranking, and seen state. Creators upload media, the system stores it durably, processes it asynchronously, and serves final renditions from CDN. Story metadata stores creator, expiration, privacy, and media references. For viewers, a tray service selects active eligible stories, ranks creators, marks unseen stories, and returns metadata while media is fetched from the CDN.

At staff level, the important design point is that stories are read-heavy and ephemeral. Media delivery should be edge-optimized, while expiration, privacy, seen state, and ranking should be handled by metadata services with clear consistency rules.

Implement