Data volume and traffic
Picture a warehouse where boxes arrive every day. To know whether there is enough room, you count three numbers: how many boxes arrive a day, how big they are and how many years they are kept. To know whether there are enough gates, you count how many boxes leave an hour.
Data volume and traffic are counted the same way. The analogy breaks in one place: a box leaves the warehouse for good, while a file is served any number of times and stays where it is.
The volume formula
Volume = record size × records a day × days kept.
Count the photo feed in parts: a post and its photos are different data, and they live in different places.
Post text
- A post is a caption, an author, a time and links to three photos: about 1 KB.
- 10 million posts × 1 KB = 10 GB a day.
- Over 5 years: 10 GB × 365 × 5 ≈ 18 TB.
That is not much: it fits on the disks of a few database servers.
Photos
- A post holds 3 photos of 200 KB each, 600 KB in all.
- 10 million posts × 600 KB = 6 TB a day.
- Over a year: 6 TB × 365 ≈ 2.2 PB, over 5 years about 11 PB.
Photos take 600 times more space than post text. Volume like that does not go into a database. An object store is a service for files where each file sits under its own key and space grows without limit, as in S3. The service writes photos there and only their keys into the database.
Copies
The numbers so far are the volume of one copy. Data that must not be lost is kept in at least three copies: 11 PB of photos become 33 PB.
Give the one-copy volume and the volume with copies separately. That way the interviewer sees where each number came from and can correct an assumption without recomputing the rest.
Traffic
Traffic is counted the same way, but per second:
- Each feed open loads 10 photos of 200 KB each: 2 MB.
- On average 12,000 opens a second × 2 MB = 24 GB/s.
- At peak, 240 GB/s.
Network speed is given in bits, so multiply by 8: 240 GB/s is about 2 Tbit/s. One server's network card carries 10–25 Gbit/s. Serving the photos from one place would take about a hundred machines, and users on the other side of the world would still wait.
So photos are served by a CDN. A CDN is a network of servers in many cities that keep copies of popular files and serve them to the nearest users. A request from Moscow gets the photo from a server in Moscow and reaches the store only if that server has no copy yet.
Uploads in the other direction are modest: 120 posts a second × 600 KB ≈ 72 MB/s on average. The post service handles that itself.
Try to place the photos on the diagram.
10 million posts are published a day, each with 3 photos of 200 KB: 6 TB a day. The feed is opened up to 120,000 times a second, and each open loads 10 photos of 200 KB. Add where the photos will be stored and where they are served from, and connect the blocks.
Common mistake
Forgetting to turn bytes into bits. The candidate gets 240 GB/s, compares it with a 25 Gbit/s network card and decides ten servers are enough. But a byte is 8 bits, so 8 times more servers are needed, about eighty.
Key points
- Volume = record size × records a day × days kept; text and files are counted separately.
- The photo feed's photos are 6 TB a day and about 11 PB over 5 years, so they live in an object store, not in the database.
- Copies are added as a separate line: three copies triple the volume.
- Peak traffic is 240 GB/s, about 2 Tbit/s, so a CDN serves the photos.