The celebrity problem, and the hybrid strategy that fixes it
Eager fan-out means an author's follower count sets the latency of everyone's write path.
The problem
Fan-out-on-write turns one post.created event into one write per follower. That’s a bounded, cheap operation for a normal account. It’s a different problem entirely for an author with a million followers: one post now means a million Redis writes, all triggered synchronously by fanout-service consuming a single event. Worse, that cost is imposed on the system by someone else’s popularity — a property no individual author should be able to inflict on the write path.
Approaches considered
Uniform eager fan-out. Push to every follower, every time, regardless of follower count. Simple, and it’s the version that falls over the moment one account gets popular.
Uniform lazy fan-out. Never push proactively — write to an author-side buffer, and have every follower’s feed-service read merge in posts from everyone they follow at read time. This removes the celebrity problem entirely but reintroduces the cost fan-out-on-write was built to avoid, for every author, all the time.
Hybrid, chosen per author. Below a follower-count threshold, fan out eagerly as before. Above it, buffer on the author’s side and merge at read time. In between, push to an active-follower shard and buffer the rest.
Trade-offs
Hybrid means fanout-service carries branching logic instead of one code path, and it means feed-service’s read is no longer uniformly a bare Redis lookup — for high-follower authors, it now does a small merge between the precomputed timeline and the author’s buffer. That’s a real complexity cost against the alternative of one simple rule.
The decision
Per-author strategy selection in fanout-service: eager under the threshold, lazy above it, hybrid in a configurable middle band.
Why
The uniform strategies each optimize one end of the follower-count distribution at the expense of the other. Most authors are nowhere near the threshold, so eager fan-out is free to keep for them — no reason to pay a merge cost on every read for accounts that will never trigger the celebrity problem. The branch only exists for the accounts that actually need it, which keeps the common case as simple as post 05 described while bounding the worst case instead of hoping it doesn’t happen.
Implementation
// fanout-service — the strategy is chosen once per event, based
// on the author's follower count, not hardcoded per deployment.
const eagerThreshold = 10_000
func (f *Fanout) HandlePostCreated(ctx context.Context, evt PostCreatedEvent) error {
count, err := f.userClient.FollowerCount(ctx, evt.AuthorID)
if err != nil {
return err
}
switch {
case count < eagerThreshold:
return f.fanOutEager(ctx, evt)
case count < eagerThreshold*10:
return f.fanOutHybrid(ctx, evt) // push to active shard, buffer the rest
default:
return f.bufferOnly(ctx, evt) // lazy: author-side buffer only
}
}
// feed-service — for hybrid/lazy authors, the read merges the
// precomputed timeline with the author's buffer at request time.
func (s *FeedService) mergeHybridSources(ctx context.Context, userID string, timeline []string) []string {
buffered := s.bufferStore.PostsSince(ctx, userID, s.lastReadAt(userID))
return mergeSortedByTime(timeline, buffered)
}