🎯 How Instagram Handles Story Delivery
1️⃣ Core Story Framework (Staff-Level)
When discussing an Instagram-like story delivery system, I frame it as:
- Story creation and media upload
- Media processing and CDN delivery
- Story metadata service
- Viewer tray generation
- Seen-state tracking
- Expiration lifecycle
- Ranking and privacy controls
- 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:
- fast media upload
- image/video processing
- audience privacy
- personalized story trays
- seen/unseen state
- 24-hour expiration
- high read traffic
- global CDN delivery
👉 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:
- validate upload
- transcode video
- resize images
- generate thumbnails
- safety checks
- create CDN-ready renditions
👉 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:
- story ID
- creator ID
- media URL
- creation time
- expiration time
- privacy settings
- close-friends flag
- viewer eligibility
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:
- relationship strength
- recency
- creator popularity
- viewer interaction history
- unseen status
- privacy eligibility
7️⃣ Seen-State Tracking
Seen state can be high volume.
Options:
- per-viewer per-story record
- compressed bitmap for large creators
- last seen timestamp per creator
- approximate counters for analytics
👉 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:
- expiration timestamp checks on read
- background cleanup jobs
- TTL storage
- cache invalidation
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 走元数据服务。
背诵要点
- story 是 media-heavy、read-heavy、ephemeral
- upload 后异步生成不同 rendition
- story metadata 存 creator、过期时间、privacy、media reference
- tray generation 决定谁的 story 出现在前面
- seen state 是高写入 metadata,不能和 CDN 路径耦合
中文面试回答
我会把 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