Bandwidth and how many servers
After this: Turn bytes per second into bits per second, see what a smaller picture saves, and count servers from the peak.
On this page · 8 sections · 3 checks
Lesson 3 counted Snapshot's requests and lesson 4 counted the space its photos take. Two questions are left. Every view sends a photo out to a phone: how many bytes leave the service each second? And the question from lesson 1: how many servers?
Bytes going out
How much data a service sends every second is its . Work it from the views:
- Snapshot gets 5,787 views per second on average (lesson 3).
- Each view sends one 2 MB photo: 5,787 × 2 MB = 11,574 MB per second.
- One step of 1,000 turns MB into GB: about 11.6 GB per second.
Bytes into bits
Network speeds are not given in bytes. They are given in bits per second. A is a single 0 or 1, and one byte is 8 bits.
- 11,574 MB per second is 11.574 GB per second. × 8 = 92.6 Gbit per second, about 93 Gbit per second.
Read the letters carefully. GB is gigabytes and Gbit is gigabits, and the two differ by a factor of 8. Some writers shorten gigabits to Gb, with a small b, and a reader can mistake it for GB.
A smaller picture
Does the feed need full-size photos? A phone screen shows a list of small pictures, and the full photo is only needed when someone opens one. A is a small version of a photo, made for lists like that. Say it is 200 KB: one tenth of 2 MB.
- 5,787 views per second × 200 KB = 1,157,400 KB per second, about 1.16 GB per second.
- × 8 = about 9.3 Gbit per second.
One tenth of the bytes per view gives one tenth of the bandwidth. The estimate shows where a design change pays off: this one removes nine tenths of the data the service sends.
How many servers
Servers have to cope with the peak, so start there.
- Peak views per second: 11,574 (lesson 3, with peak = 2 × average).
- One server handles 400 per second: 11,574 ÷ 400 = 28.9.
- You cannot run 0.9 of a server, and 28 servers would handle only 11,200. Round up: 29 servers.
Rounding up to the next whole number is called the : math.ceil in Python, Math.ceil in Java. What about the uploads? At the peak they add 2 × 11.6, about 23 per second. 11,574 + 23 = 11,597, and 11,597 ÷ 400 = 28.99, which rounds up to 29: still 29 servers.
The quick way, with 10⁵ seconds in a day: 500,000,000 views ÷ 10⁵ = 5,000 per second, 10,000 at the peak, and 10,000 ÷ 400 = 25 servers. 25 and 29 have the same order of size. Both say "a few dozen servers": not one, and not a thousand.
Run it
Change per_serverperServer to 200, as if each request did twice the work: the servers double to 58. Change the views per user to 5 and the answer drops to 3.
The whole estimate
The table from lesson 1, turned into answers:
| Question | Answer |
|---|---|
| Views per second | 5,787 on average, 11,574 at the peak |
| Uploads per second | 11.6 on average |
| New photos per year | 730 TB; 2.19 PB with 3 copies |
| New records per year | 365 GB |
| Bandwidth | about 93 Gbit/s; 9.3 Gbit/s with thumbnails |
| Servers at the peak | 29 |
Check yourself
A service's peak is 6,100 requests per second, and one server handles 400 per second. How many servers does it need at the peak?
A service sends 5 GB of data per second. What is that in Gbit per second, the unit network speeds are given in?
Snapshot sends about 93 Gbit per second when every view is a full 2 MB photo. If every view in the feed sends a 200 KB thumbnail instead, about how much does it send?
Interview lens and honesty
- Work out bandwidth as requests per second × bytes each: 5,787 × 2 MB is about 11.6 GB per second.
- Turn bytes into bits by multiplying by 8, because network speeds are given in bits: about 93 Gbit per second.
- See what a smaller picture saves: a 200 KB thumbnail sends one tenth of the data, about 9.3 Gbit per second.
- Count servers as the peak divided by what one server handles, rounded up: 11,574 ÷ 400 = 28.9, so 29.