Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 1 of 5 · Worked example · 20 min · revision 1

Scoping the feed and estimating fan-out

Turn a one-line feed prompt into a scope with testable targets, then estimate write fan-out with a seeded model of a heavy-tailed follower distribution: mean against median, the share held by the largest accounts, inserts per second, and the burst a single post can cause.

Contentsand lesson path

What you will learn

  • Compare fan-out on write, fan-out on read and hybrid strategies using follower distribution and read/write rates.

Prerequisites: Caching Strategies

01. The problem

Suppose you join a team that builds a social app. People follow other accounts and open a home feed: the recent posts of everyone they follow, newest first for now (ranking comes in lesson 4). The prompt is one line: design the home feed. Before any box goes on a whiteboard you need two things, and this lesson produces both: a scope that says what the feed must and must not do, and an estimate of fan-out, the work caused by one post reaching the people who follow its author.

The app has 2 million accounts; this and every other figure here is an assumption for the exercise, not data from a real company. What makes a feed hard is less the size of the numbers than their shape: some accounts have a handful of followers and others hundreds of thousands, and the cost of delivering one post grows with its author's audience. The method is the one from the photo-sharing estimate; this lesson adds the distribution that an average hides.

02. Step 1: scope the feed

Write the use cases as sentences a user would say:

  • I can post a short text, with an optional image.
  • I can follow and unfollow an account.
  • I can open my home feed and scroll back through older posts.
  • A new post from someone I follow appears within seconds.

Then write the non-goals, the plausible features this round leaves out: search, direct messages, notifications, ads, and recommended posts from accounts you do not follow. Each non-goal changes the numbers you are about to compute. Recommended posts would add a second source of posts to every feed, and notifications would add a second fan-out to every post.

Next, turn qualities into targets you can test, as in non-functional targets you can test:

  • Read latency: a feed page is served in under 300 ms at p99, measured at the server.
  • Freshness: 99% of posts appear in followers' feeds within 10 seconds of being accepted. The words 99% and within matter: they allow a few posts to take longer, and the largest accounts will need that room.
  • Degradation: reading the feed matters more than posting quickly. If something must give, a slightly stale feed is better than an error page (lesson 4).
  • Durability: an accepted post survives the loss of any cache. The database is the source of truth, and caches can be rebuilt from it (lesson 3).

03. Step 2: write the assumptions down

Assumptions table · home feed, today
Input                               value                     basis
accounts                            2,000,000                 today's count
share active on a given day         40%                       product forecast
posts per daily active user         0.5 per day               guess, measure
feed opens per daily active user    8 per day                 guess, measure
busiest hour / average hour         3                         guess, measure
followers per account               Pareto, shape 1.5, min 25 synthetic model
how often each account posts        the same for everyone     simplification

The follower row needs a word of explanation. A Pareto distribution is heavy-tailed: most values are small, but very large values are far more common than in a bell curve, and the largest few can be thousands of times the typical one. Its shape parameter controls how heavy the tail is: lower means heavier. Real follower counts behave this way too. A 2010 paper by researchers at Yahoo noted that one celebrity's posts went to over 4.6 million followers (as of March 2010) and that both audience sizes and posting rates vary widely between accounts.

The exact shape in your app is unknown until you can count it, so the model is a stand-in: synthetic numbers that show what a heavy tail does to an estimate, not data from any real network. Equal posting rates are a simplification that step 4 removes.

04. Step 3: run the model

Save the script as fanout_estimate.py. It needs Python 3.12 or later and only the standard library. It draws one follower count for each account from a seeded random generator, so every run prints the same numbers, and it took under two seconds on our test machine.

Python · fanout_estimate.py
"""Fan-out estimate for a home feed on a seeded, SYNTHETIC follower distribution.

Follower counts come from a Pareto distribution, chosen so that a few accounts have
huge audiences. They are not data from any real network. Python 3.12, stdlib only.
Usage: python3 fanout_estimate.py [accounts] [pareto_shape]
"""
import random
import statistics
import sys

ACCOUNTS = int(sys.argv[1]) if len(sys.argv) > 1 else 2_000_000
SHAPE = float(sys.argv[2]) if len(sys.argv) > 2 else 1.5  # lower = heavier tail
DAU_SHARE = 0.4  # share of accounts that open the app on a given day
POSTS_PER_DAU = 0.5  # posts per daily active user per day
OPENS_PER_DAU = 8  # feed opens per daily active user per day
PEAK = 3  # busiest hour divided by the average hour
BIG = 10_000  # "big account" line used in parts 2 and 4
DAY_S = 86_400

rng = random.Random(2026)
# Followers per account: Pareto with minimum 25, capped at ACCOUNTS - 1.
followers = sorted(
    (min(int(25 * rng.paretovariate(SHAPE)), ACCOUNTS - 1) for _ in range(ACCOUNTS)),
    reverse=True,
)
edges = sum(followers)  # one follow edge per (follower, followed) pair
mean = edges / ACCOUNTS


def pct(p: float) -> int:
    """Follower count that p% of accounts stay at or below."""
    return followers[int(ACCOUNTS * (1 - p / 100))]


print(f"1. Followers per account, {ACCOUNTS:,} accounts, shape {SHAPE} (synthetic)")
print(f"   follow edges   {edges:>13,}")
print(f"   mean           {mean:>13,.0f}")
for p in (50, 90, 99, 99.9):
    print(f"   p{p:<13} {pct(p):>13,}")
print(f"   largest        {followers[0]:>13,}")

print("2. Share of all follow edges held by the largest accounts")
for share in (0.0001, 0.001, 0.01):
    top = int(ACCOUNTS * share)
    held = sum(followers[:top]) / edges
    print(f"   top {share:>6.2%} ({top:>6,} accounts)   {held:>6.1%}")
big = [f for f in followers if f >= BIG]
print(f"   {len(big):,} accounts with {BIG:,}+ followers hold {sum(big) / edges:.1%}")

print("3. Load, if every account is equally likely to post")
posts_s = ACCOUNTS * DAU_SHARE * POSTS_PER_DAU / DAY_S
opens_s = ACCOUNTS * DAU_SHARE * OPENS_PER_DAU / DAY_S
inserts_s = posts_s * mean  # each post goes into every follower's timeline
print(f"   posts/s        {posts_s:>9,.1f} average {posts_s * PEAK:>9,.1f} peak")
print(f"   feed opens/s   {opens_s:>9,.1f} average {opens_s * PEAK:>9,.1f} peak")
print(f"   inserts/s      {inserts_s:>9,.0f} average {inserts_s * PEAK:>9,.0f} peak")
print(f"   one post by the largest account = {followers[0]:,} inserts")
print(f"   = {followers[0] / inserts_s:,.0f} s of average insert traffic")

print(f"4. Accounts with {BIG:,}+ followers post 5 times as often")
weights = [5 if f >= BIG else 1 for f in followers]
per_post = sum(w * f for w, f in zip(weights, followers)) / sum(weights)
print(f"   followers per post {per_post:,.0f} (was {mean:,.0f})")
big_inserts = sum(5 * f for f in big) / sum(w * f for w, f in zip(weights, followers))
print(f"   share of inserts from those accounts {big_inserts:.1%}")

print("5. Mean followers estimated from 20 random samples of 1,000 accounts")
means = sorted(statistics.fmean(rng.sample(followers, 1_000)) for _ in range(20))
print(f"   lowest {means[0]:,.0f}  median {statistics.median(means):,.0f}"
      f"  highest {means[-1]:,.0f}  (true mean {mean:,.0f})")
Terminal
python3 fanout_estimate.py
Expected output
1. Followers per account, 2,000,000 accounts, shape 1.5 (synthetic)
   follow edges     146,904,850
   mean                      73
   p50                       39
   p90                      115
   p99                      532
   p99.9                  2,423
   largest              622,454
2. Share of all follow edges held by the largest accounts
   top  0.01% (   200 accounts)     3.8%
   top  0.10% ( 2,000 accounts)     9.1%
   top  1.00% (20,000 accounts)    20.7%
   234 accounts with 10,000+ followers hold 4.1%
3. Load, if every account is equally likely to post
   posts/s              4.6 average      13.9 peak
   feed opens/s        74.1 average     222.2 peak
   inserts/s            340 average     1,020 peak
   one post by the largest account = 622,454 inserts
   = 1,830 s of average insert traffic
4. Accounts with 10,000+ followers post 5 times as often
   followers per post 85 (was 73)
   share of inserts from those accounts 17.4%
5. Mean followers estimated from 20 random samples of 1,000 accounts
   lowest 59  median 70  highest 90  (true mean 73)

05. Step 4: read the numbers

Mean against median. The median account has 39 followers, the mean is 73, and the largest account has 622,454. For capacity the mean is the right average, because total inserts are posts times the mean followers per post. A median-based estimate would size the workers at about half of what they need. The mean also needs no sampling: it is the number of follow edges divided by the number of accounts, one count on the follows table. Part 5 shows why that matters. Twenty random samples of 1,000 accounts give means from 59 to 90, and their median, 70, is low, because a small sample rarely contains one of the giants.

Concentration. Part 2 shows how concentrated the audience is. The top 1% hold about a fifth of all follow edges, and the 234 accounts with 10,000 or more followers hold 4.1%. With equal posting rates, 4.1% is also their share of all inserts.

Load. Part 3 turns the model into rates: 4.6 posts per second on average become 340 timeline inserts per second, about 1,000 at peak. Feed opens outnumber posts 16 to 1, which is why building feeds ahead of time is attractive (lesson 2). None of these averages is alarming on its own.

Burst. The last two lines of part 3 would. One post by the largest account means 622,454 inserts, as many as the whole app makes in 1,830 seconds of average traffic, about half an hour. The averages hide it because the account posts rarely, but when it does, all that work arrives at once and competes with every other post for the same workers. At this scale, that is the real fan-out problem: a few posts that cost about 16,000 times as much as a post by a median account. The 99% freshness target leaves room for them, but their followers could wait half an hour, which is why lesson 2 looks for a design that caps the burst.

Posting rates. Part 4 removes the equal-rate simplification. If accounts with 10,000+ followers post five times as often as others, followers per post rise from 73 to 85, and those 234 accounts cause 17.4% of all inserts instead of 4.1%. Followers per account and followers per post are different numbers. Capacity needs the second, which weights each author by how often they post; once the app runs, the posts table gives it to you.

06. Step 5: change one input and predict first

Before running the next command, predict: with a heavier tail (shape 1.3 instead of 1.5), does the share of inserts from big accounts roughly double, or does it barely move?

Terminal
python3 fanout_estimate.py 2000000 1.3
Expected output
1. Followers per account, 2,000,000 accounts, shape 1.3 (synthetic)
   follow edges     205,355,622
   mean                     103
   p50                       42
   p90                      146
   p99                      853
   p99.9                  4,897
   largest            1,999,999
2. Share of all follow edges held by the largest accounts
   top  0.01% (   200 accounts)     8.3%
   top  0.10% ( 2,000 accounts)    16.8%
   top  1.00% (20,000 accounts)    31.6%
   803 accounts with 10,000+ followers hold 12.9%
3. Load, if every account is equally likely to post
   posts/s              4.6 average      13.9 peak
   feed opens/s        74.1 average     222.2 peak
   inserts/s            475 average     1,426 peak
   one post by the largest account = 1,999,999 inserts
   = 4,207 s of average insert traffic
4. Accounts with 10,000+ followers post 5 times as often
   followers per post 155 (was 103)
   share of inserts from those accounts 42.5%
5. Mean followers estimated from 20 random samples of 1,000 accounts
   lowest 72  median 91  highest 157  (true mean 103)

It more than doubles, from 17.4% to 42.5%: the top 1% now hold 31.6% of the edges, and in this world a few accounts dominate write fan-out as a whole, not only its worst moments. The largest account has also hit the model's cap, followed by every other account, which says the shape is too heavy for a network this small, unless one official account really is followed by everyone.

The second change is growth. Run the base shape on 5 million accounts:

Terminal
python3 fanout_estimate.py 5000000 | head -8
Expected output
1. Followers per account, 5,000,000 accounts, shape 1.5 (synthetic)
   follow edges     369,508,983
   mean                      74
   p50                       39
   p90                      115
   p99                      538
   p99.9                  2,495
   largest            1,002,122

The mean barely moves (74), but the largest account grows from about 622,000 to about 1 million followers. In a heavy-tailed network the biggest audiences grow with the network, so a burst that fits your freshness target today may not fit it next year.

07. Check your understanding

Practice check · 3 questions

Estimating fan-out

New numbers, same method. Pick the best answer to each question.

Q1. A teammate samples 1,000 random accounts and finds a mean of 45 followers. The follows table has 600 million rows for 5 million accounts. Which figure should size the fan-out workers?
Q2. A follower histogram gives p50 = 60, mean = 150, p99 = 2,000 and largest = 900,000. Which pairing is right?
Q3. Product adds reposts: a repost puts the original post into the feeds of the reposter's followers. Posts get 0.2 reposts on average, by accounts whose follower counts match the average poster. What happens to timeline inserts per second?
Practice only: not graded, not saved, not evidence.

08. Apply it

The practice task of this skill is a feed design doc whose celebrity threshold comes from measured numbers. Start it now:

  1. Copy the assumptions table and replace the inputs with a product of your choice, for example a professional network where accounts follow about 300 others and post once a week, or a local news app with a few hundred publishers and many readers.
  2. Edit the constants in fanout_estimate.py and run it for shapes 1.3, 1.5 and 1.7.
  3. Record inserts per second (average and peak), the largest single-post burst in seconds of average insert traffic, and the share of inserts from accounts above 10,000 followers, for each shape.
  4. Write your freshness target, and name which accounts it cannot cover if every post is delivered to every follower one insert at a time.

09. Review prompt

Without looking back, answer in your own words:

  1. Why does capacity planning use the mean follower count, and how can you get it exactly?
  2. What is the difference between followers per account and followers per post, and when do they differ?
  3. How did the largest account's single post compare with average insert traffic, and why does that matter for a freshness target?
  4. What happened to the biggest audience when the network grew from 2 to 5 million accounts, and what does that predict for next year?

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

6 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check