Products›📱 Social Media›Instagram
📸

Instagram

2 Billion+ users: solving the social media fan-out challenge

99.95%
SLA
14
SERVICES
12
NODES
REQ/SEC0
LATENCY0ms
ERROR RATE0%
CACHE HIT95%
ACTIVE CONNS0
QUEUE DEPTH0

Instagram Architecture Blueprint

Click ▶ RUN to animate active particle streams across microservices

client
gateway
service
database
cache
queue
cdn
storage
SYSTEM ARCHITECTURE WALKTHROUGH

How Traffic Flows Through Instagram

EDGE TIER01

1. Ingress & Edge Routing

User requests arrive at the edge network. Global CDNs cache static assets and media. API Gateways terminate TLS, validate JWT authentication tokens, enforce token-bucket rate limits, and scrub malicious bot traffic before forwarding to internal services.

User AppAPI GatewayGlobal Edge CDN
APPLICATION TIER02

2. Microservice Processing

Stateless domain services execute core business logic. Microservices communicate via high-performance internal gRPC/REST APIs and autoscaling worker pods, ensuring that high load on one domain never exhausts compute resources of another.

Upload ServiceFeed ServiceTAO Social GraphMedia Processing
DATA TIER03

3. In-Memory Caching & Storage

Read-heavy traffic is served from in-memory Redis clusters with sub-millisecond latencies, protecting primary databases. Persistent databases (PostgreSQL, Cassandra, DynamoDB) maintain ACID consistency for financial ledgers, user accounts, and immutable state records.

Haystack Object StoreRedis Feed CacheCassandra DB
MESSAGING TIER04

4. Asynchronous Event Streams

Heavy operations (notifications, audit logging, analytics, ML training, fan-out delivery) are decoupled into durable event logs like Kafka and SQS. This prevents user-facing requests from blocking on slow external networks.

Kafka Event Stream
📖 SYSTEM DESIGN WHITE PAPERS & LOW-LEVEL SPECIFICATIONS

Study Instagram's database schemas, capacity math & production contracts

Beyond the visual blueprint, explore the exhaustive 7-section engineering whitepaper with real DDL schemas, API endpoints, failure mitigation matrices, and 45-minute FAANG interview scripts.

🏆 #1 HARDEST SYSTEM CHALLENGE

The High-Fanout Celebrity Dilemma (Fan-Out on Write vs Read)

⚠️The Engineering Bottleneck

If an account like Cristiano Ronaldo (600M followers) posts a photo, a pure Fan-Out on Write model must immediately execute 600,000,000 Redis list insertions. This causes queue exhaustion, worker starvation, and cascading outages.

💡The Winning Architectural Solution

Instagram developed a Hybrid Fan-Out architecture: for regular users (<25,000 followers), posts are fanned out on write into each follower's in-memory Redis timeline. For celebrities (>25,000 followers), posts are NOT written to followers; instead, when a follower opens their app, celebrity posts are fetched on read and merged with their pre-computed feed in RAM.

SCALE & PRODUCTION METRICS:Sub-45ms feed retrieval P99, zero worker queue backlogs during celebrity posts, 2B+ active users.

⚖️ Architectural Trade-Offs & Decisions

Why the engineering team chose this specific stack over competing alternatives

Why Hybrid Fan-Out instead of pure Fan-Out on Read?
CHOSEN:✓ Hybrid Fan-Out Architecturevs Pure Fan-Out on Write, Pure Fan-Out on Read

Pure Fan-Out on Read requires querying the posts of all 500 people you follow every time you open the app, executing heavy multi-table joins and sorting thousands of posts on disk. Hybrid fan-out keeps feeds pre-computed in Redis for 99% of users, giving sub-50ms app launches.

Why Haystack instead of standard POSIX filesystems for photo storage?
CHOSEN:✓ Facebook / Instagram Haystackvs Standard Linux Ext4 filesystem, Standard S3 bucket without volume packing

Standard POSIX filesystems read disk inodes for every small file. Storing billions of 200KB photos creates massive disk seek overhead just to read file metadata. Haystack appends photos into massive multi-gigabyte volume files, holding photo offsets in memory for 1-seek reads.

🚨 REAL-WORLD POST-MORTEM

The Redis Memory Exhaustion Feed Outage

The Incident

Instagram feeds displayed blank screens globally as Redis feed cache nodes crashed with Out-Of-Memory (OOM) errors.

Root Cause Analysis

An engineering change increased the cached timeline length from 800 to 2,000 post IDs per user, doubling memory consumption and triggering kernel OOM killer terminations across the Redis cluster.

How They Re-Architected It

Strict timeline capping (maximum 800 post IDs per user) was enforced, Redis memory limits were hardened with LRU eviction policies, and cache sizing calculators were added to CI/CD deployment pipelines.

📋 Complete Microservice Specifications

Every service in the Instagram ecosystem with production tech stacks and failure impact

ComponentTier / LayerTech StackProduction FunctionStatus / Chaos
User AppCLIENT
iOSAndroidWeb
iOS, Android, and Web clients uploading posts and browsing personalized feeds
API GatewayGATEWAY
GraphQLNginxEnvoy
GraphQL and REST API gateway handling auth, rate limiting, and request routing
Upload ServiceSERVICE
PythonDjangoCelery
Handles photo and video uploads using pre-signed S3 URLs
Feed ServiceSERVICE
PythonDjango
Generates personalized home feeds by combining pre-computed timelines with ML ranking
TAO Social GraphSERVICE
TAOMySQLMemcached
Distributed graph datastore caching follower and following relationships
Media ProcessingSERVICE
PythonC++FFmpeg
Compresses, resizes, and encodes photos and videos into multiple formats
Global Edge CDNCDN
Facebook CDNAkamai
Edge CDN caching images, video segments, and static assets globally
Haystack Object StoreSTORAGE
HaystackAWS S3
Petabyte-scale object store optimized for billions of small photo files
Redis Feed CacheCACHE
RedisIn-Memory Lists
In-memory Redis lists holding pre-computed post IDs for active users
Cassandra DBDATABASE
CassandraRocksDB
Distributed NoSQL database storing post metadata, comments, and like records
Kafka Event StreamQUEUE
Kafka
Event pipeline decoupling post publishing from feed fan-out workers
Fan-out Worker FleetSERVICE
PythonCeleryAsync
Worker pool writing post IDs into followers' Redis feed caches