Case study boundary
Use this as a learning model.
This page explains architectural patterns and constraints inspired by Instagram. It should not be read as the exact private production architecture or as a one-size-fits-all recommendation.
Evidence
Public info + inference
Learn first
Concepts behind this architecture
Object Storage
Store large immutable blobs behind keys instead of rows and file paths.
Cache-Aside
Let the application read through the cache and repopulate missing data on demand.
CDN
Cache and serve content close to users so origin systems stay fast and protected.
Eventual Consistency
Allow replicas to temporarily disagree while guaranteeing they converge later.
Overview
Instagram is one of the world’s largest social media platforms, serving over 2 billion monthly active users. Its architecture handles the challenge of generating personalized feeds from billions of posts, processing massive volumes of image and video uploads, and delivering real-time interactions. Originally built as a Django monolith by a team of 3, it has evolved into a sophisticated microservices architecture within the Meta infrastructure.
Scale
2B+
Monthly active users
~100M
Photos uploaded daily
~1M
Likes per second
Exabytes
Media storage
Requirements
Functional
- Photo and video upload with filters
- Personalized news feed (algorithmic + chronological)
- Stories (ephemeral 24-hour content)
- Direct messaging
- Explore/discovery page
- Likes, comments, and sharing
- User profiles and following system
Non-Functional
- Sub-second feed generation
- Low-latency media delivery globally via CDN
- High availability (99.99%)
- Eventual consistency for social graph
- Support for viral content spikes
- Efficient storage of billions of images
High-Level Architecture
Key Components
Feed Service
Generates personalized feeds using a hybrid push/pull model. Pre-computes feeds for active users (fanout-on-write) and computes on-demand for inactive users (fanout-on-read).
Media Service
Handles image and video upload, processing (filters, resizing, transcoding), and storage. Generates multiple resolutions for different device sizes.
User Service
Manages user profiles, the social graph (follow/unfollow), and authentication. The social graph uses a TAO-based system for efficient traversal.
Story Service
Manages ephemeral content with 24-hour TTL. Uses a separate storage pipeline optimized for write-heavy, short-lived data.
Recommendation Service
Powers the Explore page and suggested follows using collaborative filtering and deep learning models trained on user interaction data.
Search Service
Full-text search across users, hashtags, and locations using Elasticsearch with custom analyzers for multilingual support.
Data Model
Feed Generation Architecture
Instagram uses a hybrid fanout model for feed generation, combining push and pull strategies:
Fanout-on-Write (Push Model): When a user publishes a post, the Feed Service pushes the post ID into the feed caches of all followers. This pre-computes feeds, enabling instant feed loading.
- Used for users with < 10K followers
- Feed stored in Redis sorted sets (post_id, timestamp)
- Each user’s feed cache holds ~500 most recent post IDs
Fanout-on-Read (Pull Model): For celebrity accounts with millions of followers, fanout-on-write is too expensive. Instead, their posts are fetched on-demand when a follower loads their feed.
- Used for users with > 10K followers
- Merged with pre-computed feed at read time
Ranking: Once candidate posts are assembled, an ML ranking model scores each post based on ~1000 features (user affinity, content type, timeliness, engagement signals) and returns the final ordered feed.
Media Processing Pipeline
Every photo uploaded to Instagram goes through a sophisticated processing pipeline:
- Upload: Client uploads the original image to a staging area
- Validation: File format, size, and content policy checks
- Processing: Apply user-selected filters using GPU-accelerated pipelines
- Resizing: Generate multiple resolutions (thumbnail 150px, low 320px, medium 640px, high 1080px)
- CDN Distribution: Push processed images to edge locations worldwide
- Metadata Extraction: EXIF data, location, and computer vision (object detection, alt-text)
For videos, the pipeline also includes transcoding to multiple bitrates for adaptive streaming, generating preview thumbnails, and audio normalization.
Instagram stores images in a custom storage system built on top of Haystack (Meta’s photo storage), which reduces metadata overhead by storing multiple images in a single physical file.
Social Graph with TAO
Instagram uses Meta’s TAO (The Associations and Objects) system for the social graph — a distributed, highly-cached graph data store.
TAO Architecture:
- Objects: Nodes in the graph (users, posts, comments)
- Associations: Edges between nodes (follows, likes, comments-on)
- Caching Layer: Multi-tier cache (L1 per-region, L2 per-datacenter) with >99% hit rate
- Storage: MySQL sharded by object ID as the persistent backend
Query Pattern: TAO optimizes for the most common social queries:
- “Who does User X follow?” — Forward association query
- “Who follows User X?” — Inverse association query
- “Does User X follow User Y?” — Point association query
The cache handles billions of queries per second with median latency under 1ms.
Architectural Tradeoffs
Hybrid fanout (push + pull)
Pros
- +Fast feed loading for most users
- +Avoids write storms for celebrities
- +Balances read/write costs
Cons
- −Complex merging logic at read time
- −Feed staleness for pull-based posts
- −Two code paths to maintain
Django monolith evolved to microservices
Pros
- +Rapid initial development
- +Gradual migration possible
- +Python ecosystem for ML integration
Cons
- −GIL limits concurrency
- −Large monolith is hard to deploy
- −Migration to microservices is costly
Cassandra for feed storage
Pros
- +Excellent write throughput
- +Linear horizontal scaling
- +Tunable consistency
Cons
- −No complex queries
- −Eventual consistency can show stale data
- −Operational complexity
Learn From Instagram
Copy a learning context prompt for an AI assistant. It keeps assumptions visible and asks for tradeoffs, cost drivers, failure modes, and what to measure before adding complexity.