๐ŸŽ“ A1Learner
๐Ÿ”
0 of 42 lessons completed

News Feed: Estimate the Scale

An estimate turns daily habits into the rates a design must handle. This lesson estimates the scale of the news feed.

Posts per day and per second

Two posts from each daily user give the daily post count. Dividing by the seconds in a day gives the post rate.

daily_users = 100000000
posts_each = 2
posts_day = daily_users * posts_each

print("posts per day:", posts_day)
print("posts per second:", round(posts_day / 86400))

Reads per day and per second

Ten feed checks from each daily user give the daily read count. The same division gives the read rate.

daily_users = 100000000
reads_each = 10
reads_day = daily_users * reads_each

print("reads per day:", reads_day)
print("reads per second:", round(reads_day / 86400))

What copying each post costs

Each post is copied into one feed per follower. The printout shows the write rate and the entries made in a day.

posts_day = 200000000
posts_second = round(posts_day / 86400)
followers = 200

print("feed writes per second:", posts_second * followers)
print("feed entries per day:", posts_day * followers)

Example

daily_users = 100000000
posts_day = daily_users * 2
reads_day = daily_users * 10
posts_second = round(posts_day / 86400)
reads_second = round(reads_day / 86400)
writes_second = posts_second * 200

print("posts per day:", posts_day)
print("posts per second:", posts_second)
print("reads per day:", reads_day)
print("reads per second:", reads_second)
print("feed writes per second:", writes_second)

rates = [("posts per second", posts_second), ("reads per second", reads_second), ("feed writes per second", writes_second)]
name, value = max(rates, key=lambda r: r[1])
print("largest rate:", name, value)

Key points

  • Daily users: 100,000,000 people use the service each day.
  • Posts: each user posts 2 times a day, so the service takes 200,000,000 posts a day.
  • Post rate: 200,000,000 posts a day is 2,315 posts per second.
  • Feed reads: each user checks the feed 10 times a day, so the service serves 1,000,000,000 reads a day.
  • Read rate: 1,000,000,000 reads a day is 11,574 reads per second.
  • Follows: the average account follows 200 accounts.
  • Feed writes: copying each post into 200 feeds at post time makes 463,000 feed writes per second.
  • Feed entries: those copies make 40,000,000,000 feed entries a day.

In this example, one set of habits gives every rate in the design. Feed writes form the largest rate, so the cost of copying posts drives the design.

Note

reads and feed writes run far ahead of posts, so both need a cheap path.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

How many feed writes per second does copying each post into 200 feeds make?