Part 5 of 9 · 2 min read
Describing load
Why "users" is not enough, and how a few numbers called load parameters describe growth.
Think of a restaurant. "Busy" is vague. The useful numbers are guests per hour, the share who order the slow dish, and how many arrive in a group.
To discuss growth, one must say what is growing. "Load" can be described with a few numbers.
Load parameters
Load parameters are the few numbers that describe how much work a system has to do. The right ones depend on the system.
Example: for a web server, requests each second. For a database, how many reads there are for each write. For a chat room, how many people are online together. For a cache, how often it already holds the answer.
A famous example from the book is a social network, using figures that its authors report from 2012. There are two main actions:
- Posting. A user publishes a message. On average about 4,600 posts arrive per second, and over 12,000 at peak.
- Reading the home feed. A user sees the posts of the people they follow. About 300,000 reads per second.
Posting at 12,000 per second is not hard to handle. The real challenge is fan-out.
Fan-out
Fan-out means the number of other requests that one request causes. When one user posts, the post may need to reach all of that user's followers, so one request fans out into many.
Example: a user with 1,000 followers who posts once causes 1,000 deliveries.
There are two ways to build the feed:
- Read-time work. A post is saved once in a global list. When a user opens the feed, the system looks up everyone they follow, collects their posts and merges them by time. Posting is cheap, but reading is expensive.
- Write-time work. Each user has a ready-made feed, like a mailbox. A new post is copied into the mailbox of every follower. Reading is cheap, because the feed is already built, but posting is expensive.
Look at the numbers. Reads (300,000 per second) outnumber posts (4,600 per second) by about 65 to 1. When reads dominate, it pays to do the work at write time. With 75 followers on average, 4,600 posts a second become 4,600 × 75 = 345,000 deliveries per second. That is about the same as the read rate, but spread to the moment of posting.
But the average hides something. Some users have 30 million followers. One post from such a user means 30 million deliveries. The number of followers per user, and how often users post, are the load parameters that matter most. The book says the real system ended up mixing both ways: most users get write-time delivery, and the few very popular accounts are read at read time.
Read it as
Do not ask "how many users?". Ask "which number decides how hard the work is?". For this feed, it was followers per user.
Check yourself:
- If reads were only twice as common as posts, which of the two feed methods would look better?
- Which load parameter makes celebrity accounts a special case?