How much space
After this: Multiply size by count by 365 by copies, and see which part of the data takes the space.
On this page · 6 sections · 3 checks
Lesson 3 counted how busy Snapshot's servers are. But an upload does not only keep a server busy for a moment. It leaves a photo behind, and that photo has to be kept, every day, for years. How much space does that take?
One day of photos
From lesson 3, Snapshot gets 1,000,000 uploads a day. Each photo is 2 MB.
- One day: 1,000,000 × 2 MB = 2,000,000 MB.
- Change units, one step of 1,000 at a time: 2,000,000 MB is 2,000 GB, which is 2 TB per day.
A year, and copies
- A year: 2 TB × 365 = 730 TB per year.
- Copies. A service never keeps one copy of a photo only: if the disk that holds it breaks, the photo is gone for good. So it keeps the same photo on several machines. We assume 3 copies, a common choice; the tutorial on databases at scale shows how a system keeps copies of its data up to date. 730 TB × 3 = 2,190 TB.
- 2,190 TB is 2.19 thousand TB, so it is 2.19 PB per year.
The general rule, now that you have seen it work:
space per year = size of one item × items per day × 365 × copies
The records
Each photo also has a record in the database: who uploaded it, when, and its caption. We assumed 1 KB per record.
- One day: 1,000,000 × 1 KB = 1,000,000 KB, which is 1 GB per day.
- A year: 1 GB × 365 = 365 GB per year.
Compare the two. One day of photos is 2 TB, which is 2,000 GB. That is more space than 5 years of records (2,000 ÷ 365 = 5.5). The photos are the problem, not the table. This is why designs usually keep large files such as photos outside the database, in storage made for big files, and keep only the small records in the database.
Run it
1e12 is how both languages write 10¹², a 1 followed by twelve zeros. Dividing a number of bytes by 1e12 gives TB, by 1e9 GB, by 1e15 PB. The result has a decimal point, which is why the output says 2.0 and not 2.
Try 3 MB photos instead of 2 MB. Every photo number grows by half: 1,095 TB a year, 3.285 PB with copies. The records do not change.
Check yourself
A video app gets 200,000 uploads a day, and each upload is 5 MB. How much space do the new uploads need per year, counting one copy only?
Snapshot's records take 365 GB a year. One day of its photos takes 2 TB. About how many years of records fit in the space of one day of photos?
Complete the line that turns one day of storage into a year of storage, so that the program prints 730.0 TB per year. Name it per_year: the print line uses it.Make it a long named perYear: the print line uses it.
uploads_per_day = 1_000_000photo_bytes = 2_000_000 # 2 MB
per_day = uploads_per_day * photo_bytes_______________________________ # ← storage for a whole yearprint(per_year / 1e12, "TB per year")public class Main { public static void main(String[] args) { long uploadsPerDay = 1_000_000; long photoBytes = 2_000_000; // 2 MB
long perDay = uploadsPerDay * photoBytes; _______________________________ // ← storage for a whole year System.out.println(perYear / 1e12 + " TB per year"); }}Honesty notes
- Work out space as size of one item × items per day × 365 × copies.
- Snapshot's photos take 2 TB a day, 730 TB a year, and 2.19 PB a year with 3 copies.
- Its records take only 365 GB a year: the large files, not the database table, need the planning.
- In Java, keep large counts in a long: two ints multiplied past about 2.1 billion wrap around with no error.