Bài toán: khi user mở app, lấy nhanh các post mới nhất từ những người họ follow.
Fan-out on write (push): ngay khi A đăng post, ghi sẵn post id vào feed cache của tất cả follower (Redis list). Đọc feed cực nhanh (chỉ đọc list dựng sẵn).
- Tốt cho user thường.
- Vấn đề celebrity: A có 50M follower → một post sinh 50M lần ghi → "fan-out storm", trễ và tốn.
Fan-out on read (pull): không dựng sẵn; khi user mở feed thì truy vấn post mới của từng người họ follow rồi merge tại thời điểm đọc. Ghi rẻ, nhưng đọc nặng (đọc khuếch đại) và chậm nếu follow nhiều.
Hybrid (giải pháp thực tế):
- Đa số user → push (fan-out on write).
- Celebrity → không push; post của họ được pull lúc đọc rồi merge vào feed đã dựng sẵn.
- Ngưỡng theo số follower để phân loại.
Hình dung: báo giao tận nhà (push) cho người thường; còn "tin nóng từ ngôi sao" thì độc giả tự ghé sạp lấy lúc đọc (pull) để khỏi in 50M bản.
Lưu ý: feed list cache có giới hạn (vài trăm id gần nhất); ranking/ML re-rank đặt sau bước merge; cần xử lý unfollow/block khi merge.
Problem: when a user opens the app, quickly fetch the latest posts from people they follow.
Fan-out on write (push): as soon as A posts, pre-write the post id into every follower's feed cache (Redis list). Reads are extremely fast (just read the prebuilt list).
- Great for normal users.
- Celebrity problem: A has 50M followers → one post triggers 50M writes → a "fan-out storm", slow and costly.
Fan-out on read (pull): nothing prebuilt; when a user opens the feed, query each followee's recent posts and merge at read time. Cheap writes, but heavy reads (read amplification) and slow if they follow many.
Hybrid (real solution):
- Most users → push (fan-out on write).
- Celebrities → no push; their posts are pulled at read time and merged into the prebuilt feed.
- A follower-count threshold classifies accounts.
Picture: home-delivered newspapers (push) for ordinary writers; "breaking news from stars" the reader grabs at the newsstand (pull) to avoid printing 50M copies.
Note: the feed cache list is bounded (a few hundred recent ids); ranking/ML re-rank runs after merge; handle unfollow/block during merge.