2 Billion+ users: solving the social media fan-out challenge
Instagram Architecture Blueprint
Click ▶ RUN to animate active particle streams across microservices
How Traffic Flows Through Instagram
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.
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.
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.
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.
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.
The High-Fanout Celebrity Dilemma (Fan-Out on Write vs Read)
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.
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.
⚖️ Architectural Trade-Offs & Decisions
Why the engineering team chose this specific stack over competing alternatives
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.
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.
The Redis Memory Exhaustion Feed Outage
Instagram feeds displayed blank screens globally as Redis feed cache nodes crashed with Out-Of-Memory (OOM) errors.
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.
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
| Component | Tier / Layer | Tech Stack | Production Function | Status / Chaos |
|---|---|---|---|---|
| User App | CLIENT | iOSAndroidWeb | iOS, Android, and Web clients uploading posts and browsing personalized feeds | |
| API Gateway | GATEWAY | GraphQLNginxEnvoy | GraphQL and REST API gateway handling auth, rate limiting, and request routing | |
| Upload Service | SERVICE | PythonDjangoCelery | Handles photo and video uploads using pre-signed S3 URLs | |
| Feed Service | SERVICE | PythonDjango | Generates personalized home feeds by combining pre-computed timelines with ML ranking | |
| TAO Social Graph | SERVICE | TAOMySQLMemcached | Distributed graph datastore caching follower and following relationships | |
| Media Processing | SERVICE | PythonC++FFmpeg | Compresses, resizes, and encodes photos and videos into multiple formats | |
| Global Edge CDN | CDN | Facebook CDNAkamai | Edge CDN caching images, video segments, and static assets globally | |
| Haystack Object Store | STORAGE | HaystackAWS S3 | Petabyte-scale object store optimized for billions of small photo files | |
| Redis Feed Cache | CACHE | RedisIn-Memory Lists | In-memory Redis lists holding pre-computed post IDs for active users | |
| Cassandra DB | DATABASE | CassandraRocksDB | Distributed NoSQL database storing post metadata, comments, and like records | |
| Kafka Event Stream | QUEUE | Kafka | Event pipeline decoupling post publishing from feed fan-out workers | |
| Fan-out Worker Fleet | SERVICE | PythonCeleryAsync | Worker pool writing post IDs into followers' Redis feed caches |