System Design intermediate LIVE DEMO
πŸ“Έ

Instagram Feed and Media Lifecycle Visualization

Walk through Instagram's feed and media lifecycle from upload to image processing, metadata commit, hybrid feed fan-out, Redis inbox reads, CDN media fill, cache stampede degradation

System DesignInstagramFeed Fan-outCDNHybrid FeedsNoSQLRedis Cachingvisualization
Interactive Demo

Continue with the guided workspace

Use the paired workspace to connect this guide's mental model with live component state, visible signals, and the outcome each step or scenario is meant to prove.

Instagram’s system architecture manages media uploads, metadata storage, and high-concurrency feed delivery for billions of active users.

Mental Model

At scale, the architecture must support high write loads for media uploads and high read volumes for feed viewing. This visualization focuses on the modeled path: validate the post, create media renditions, persist metadata, fan out ordinary posts, pull celebrity posts at read time, fill CDN media, and recover from a feed-cache stampede. Redis stores pre-computed feed inboxes while the Feed Service merges cached and pull-time results.

Components and Why They Exist

Creator Client

The client application used by creators to upload photos, videos, and stories. Initiates media uploads and submits post metadata to the backend services. In the demo, watch it send upload streams.

API Gateway

The single entry point for all API requests, providing routing, rate-limiting, and authentication. Validates request headers and routes media binaries to the processor. In the demo, watch it validate post metadata and forward transcoding jobs.

Image Processor

Prepares uploaded media for multiple devices and network conditions. Transcodes raw images into optimized renditions (WebP/AVIF formats at multiple resolutions). In the demo, watch it generate device-specific versions.

Object Storage

Highly scalable storage specifically designed for large, immutable binary files (like raw and transcoded images). Stores media assets and returns unique URLs for reference. In the demo, watch transcoded files save here.

Metadata DB

The source of truth for post entries, comments, likes, and user profiles. Commits ACID-compliant metadata rows including author, timestamp, and S3 URLs. In the demo, watch post records commit.

Social Graph

Handles high-velocity relationship lookups (who follows whom). Caches follow relationships in memory (e.g. TAO graph cache) to allow instant follow checks. In the demo, watch it queried for relationship matches.

Fan-Out Worker

Handles the background task of updating followers’ feed inboxes. Pushes post IDs into follower feed caches. For celebrity accounts, it skips fan-out to prevent cache bottlenecks. In the demo, watch it update follower caches or skip celebrity push tasks.

Redis Feed Cache

Pre-computes and stores home feeds for active users. Holds lists of recent post IDs in memory, allowing feeds to load instantly. In the demo, watch inboxes update during write fan-out.

Feed Service

Compiles and formats the home feed for readers. Merges the precomputed Redis feed inbox with live celebrity posts pulled from the Metadata DB and Social Graph. In the demo, watch it query caches and compile feed JSON.

CDN Edge

Caches heavy image assets physically close to viewers to reduce network latency. Serves cached media on hits; pulls from Object Storage on misses. In the demo, watch media requests fetch from CDN or trigger origin cache-fills.

Viewer App

The client-side application for end users reading feeds. Requests feed metadata and lazy-loads images from the CDN. In the demo, watch it fetch feed JSON and download images.

Stories Cache

Isolates ephemeral stories from the main feed cache. Stores active stories with a set TTL (e.g., 24 hours), causing them to expire and delete automatically. In the demo, watch story entries age and expire.

Edge Cases and Misconceptions

  • Misconception: Caches are only used to improve read performance: Caches like Redis and TAO are also used to shield downstream relational databases from being overwhelmed. During a cache outage (cache stampede), database CPU will spike to 100% and cause a system-wide collapse.
  • Misconception: Ephemeral content is deleted manually by database jobs: Stories are configured with an automatic Time-To-Live (TTL) in key-value stores. Runtimes automatically expire and reclaim memory for expired keys, ensuring zero manual database overhead.
  • Edge Case: Cache Stampede (Thundering Herd): If a popular post’s cache expires, or the CDN cache is purged, millions of requests will hit the metadata database simultaneously. System safety requires stale-while-revalidate (SWR) headers, mutual-exclusion locking (single-flighting), or proactive cache warming.

Open the Instagram System simulator sandbox after the walkthrough when you want to experiment with uploader count, upload rate, viewer count, read rate, celebrity follower count, story TTL, and failure modes.

Common Questions

What is the hybrid feed model in Instagram's architecture?

It combines write-path fan-out (push model) for regular users and read-path merge (pull model) for celebrity or high-following accounts. This protects Redis caching clusters from celebrity post write-storms while keeping home feed compilation fast.

What is a cache stampede or cache eviction wave?

A cache stampede occurs when cached data expires or is purged, and multiple client read requests fall back to the databases simultaneously, overloading PostgreSQL and the social graph storage. It is typically mitigated with request coalescing, single-flight fills, or early refresh (XFetch) so only one request rebuilds the cache while others wait.

Why do we separate image storage (S3) from post metadata (PostgreSQL)?

Binary media assets are massive and static, making them ideal for blob stores like S3 and CDN caching. Relational and graph metadata are dynamic, queryable, and require indexes to handle feeds, followers, and social relationships.

How are ephemeral Stories expired without a background cleanup job?

Stories are written with a Time-To-Live (TTL) on each key. In Redis, these key-value pairs expire automatically once the TTL elapses (e.g., 24 hours in production), removing them from active feeds without a scheduled scan, because Redis evicts expired keys lazily on access and actively via its background cycle.

What are the tradeoffs of Pure Push vs. Pure Pull feed generation?

Pure Push (write fan-out) has fast read latency (O(1) to read the precompiled feed inbox) but massive write complexity (O(N) writes for N followers). Pure Pull (read path compilation) has zero write overhead for posting but high read latency (O(N) queries to merge all followings' feeds on request).

How does the modeled feed service combine cached and celebrity posts?

The modeled Feed Service merges regular-user post ids from Redis with celebrity posts pulled from the Social Graph and Metadata DB. A production system may add ranking later, but this visualization isolates the storage and fan-out tradeoff.