The system operates on a ๐ฝ๐๐๐ต-๐ฝ๐๐น๐น ๐ต๐๐ฏ๐ฟ๐ถ๐ฑ ๐ฎ๐ฟ๐ฐ๐ต๐ถ๐๐ฒ๐ฐ๐๐๐ฟ๐ฒ that balances write amplification with read latency. When a user posts content, it is "fanned out" (pushed) to the feeds of active followers via a Feed Write Service. For users with millions of followers (celebrities), the system switches to a pull-based model where the feed is generated on-demand, avoiding the massive write overhead.
When a user opens the app, a Feed Read Service retrieves their personalized feed from a distributed cache. The feed is a pre-computed list of post IDs, ranked by the Ranking Service based on factors like recency, engagement, relationship with the author, and machine learning signals. Thumbnails and media are then fetched from a CDN for fast rendering.
The platform's core consists of ๐ต๐ถ๐ด๐ต๐น๐ ๐ผ๐ฝ๐๐ถ๐บ๐ถ๐๐ฒ๐ฑ, ๐ฒ๐๐ฒ๐ป๐-๐ฑ๐ฟ๐ถ๐๐ฒ๐ป ๐๐ฒ๐ฟ๐๐ถ๐ฐ๐ฒ๐:
- Feed Write Service: Handles fan-out of new posts to follower feed caches.
- Feed Read Service: Retrieves and paginates the ranked feed for users.
- Ranking Service: The ML-powered brain that scores and orders posts for personalization.
- Post Storage Service: Manages post metadata, captions, and comments.
- Media Service: Handles image/video upload, processing, and CDN delivery.
- Timeline Cache**: Distributed in-memory store (Redis) holding the pre-computed feed for each user.
Behind the scenes, an ๐ฎ๐๐๐ป๐ฐ๐ต๐ฟ๐ผ๐ป๐ผ๐๐ ๐ฒ๐๐ฒ๐ป๐-๐๐๐ฟ๐ฒ๐ฎ๐บ๐ถ๐ป๐ด ๐ฝ๐ถ๐ฝ๐ฒ๐น๐ถ๐ป๐ฒ powers personalization. Every view, like, and follow generates an event consumed by the Ranking Service, which continuously updates user embeddings and refines scoring models offline. Batch jobs pre-compute recommendations for cold-start users and generate the "Explore" feed.
This scale demands ๐ฎ๐ด๐ด๐ฟ๐ฒ๐๐๐ถ๐๐ฒ ๐ฐ๐ฎ๐ฐ๐ต๐ถ๐ป๐ด ๐ฎ๐ป๐ฑ ๐ถ๐ป๐๐ฒ๐น๐น๐ถ๐ด๐ฒ๐ป๐ ๐ณ๐ฎ๐ป๐ผ๐๐ ๐๐๐ฟ๐ฎ๐๐ฒ๐ด๐ถ๐ฒ๐. Active users have their feed pre-computed and cached. Inactive users have their feed generated on-demand. The fan-out process is sharded by follower ID and processed asynchronously via message queues to absorb write spikes.
๐๐ฟ๐ถ๐๐ถ๐ฐ๐ฎ๐น ๐๐ฒ๐๐ถ๐ด๐ป ๐ฃ๐ฟ๐ถ๐ป๐ฐ๐ถ๐ฝ๐น๐ฒ๐: ๐ญ) ๐๐๐ฏ๐ฟ๐ถ๐ฑ ๐ฃ๐๐๐ต/๐ฃ๐๐น๐น ๐๐ฟ๐ฐ๐ต๐ถ๐๐ฒ๐ฐ๐๐๐ฟ๐ฒ to handle celebrity users, ๐ฎ) ๐ ๐-๐ฃ๐ผ๐๐ฒ๐ฟ๐ฒ๐ฑ ๐ฅ๐ฎ๐ป๐ธ๐ถ๐ป๐ด for personalization, ๐ฏ) ๐ ๐๐น๐๐ถ-๐ง๐ถ๐ฒ๐ฟ ๐๐ฎ๐ฐ๐ต๐ถ๐ป๐ด (feed IDs โ post metadata โ media), ๐ฐ) ๐๐๐๐ป๐ฐ๐ต๐ฟ๐ผ๐ป๐ผ๐๐ ๐๐ฎ๐ป๐ผ๐๐ with queue-based processing, ๐ฑ) ๐๐๐ฒ๐ป๐-๐๐ฟ๐ถ๐๐ฒ๐ป ๐ฃ๐ฒ๐ฟ๐๐ผ๐ป๐ฎ๐น๐ถ๐๐ฎ๐๐ถ๐ผ๐ป for continuous model updates.
๐ง๐ฒ๐ฐ๐ต๐ป๐ถ๐ฐ๐ฎ๐น ๐๐ฟ๐ฐ๐ต๐ถ๐๐ฒ๐ฐ๐๐๐ฟ๐ฒ ๐ฆ๐๐ฎ๐ฐ๐ธ:
- ๐๐ฟ๐ผ๐ป๐๐ฒ๐ป๐ฑ: React, React Native, Swift (iOS), Kotlin (Android)
- ๐๐ฎ๐ฐ๐ธ๐ฒ๐ป๐ฑ ๐ฆ๐ฒ๐ฟ๐๐ถ๐ฐ๐ฒ๐: Python (Django), Java, Go, Node.js
- ๐๐ฎ๐๐ฎ๐ฏ๐ฎ๐๐ฒ๐: PostgreSQL, Cassandra, DynamoDB
- ๐๐ฒ๐ฒ๐ฑ ๐๐ฎ๐ฐ๐ต๐ฒ: Redis, Memcached (for pre-computed timeline IDs)
- ๐ ๐ฒ๐ฑ๐ถ๐ฎ ๐ฆ๐๐ผ๐ฟ๐ฎ๐ด๐ฒ: AWS S3 + Global CDN (CloudFront, Akamai)
- ๐ ๐ฒ๐๐๐ฎ๐ด๐ถ๐ป๐ด & ๐ฆ๐๐ฟ๐ฒ๐ฎ๐บ๐: Apache Kafka, AWS Kinesis
- ๐ ๐ฎ๐ฐ๐ต๐ถ๐ป๐ฒ ๐๐ฒ๐ฎ๐ฟ๐ป๐ถ๐ป๐ด: PyTorch, TensorFlow (for ranking and recommendation models)
- ๐ข๐ฟ๐ฐ๐ต๐ฒ๐๐๐ฟ๐ฎ๐๐ถ๐ผ๐ป: Kubernetes, Docker, AWS EKS
- ๐ ๐ผ๐ป๐ถ๐๐ผ๐ฟ๐ถ๐ป๐ด: Prometheus, Grafana, ELK Stack
๐ Learn more in The Modern System Design Handbook: codewithdhanian.gumroad.com/l/ntmcf
๐ Grab the Master System Design Case Studies: codewithdhanian.gumroad.com/l/oytfng
