Sub topic 8
Estimating storage over a retention period
This chapter assumes you can do arithmetic with powers of ten, know the data size units from the earlier chapter on powers of two, and can read short Python snippets. It also assumes you already have a write rate from the traffic chapters.
The basic formula
Storage estimation is a multiplication chain. You start with how many new records the system creates per day, then multiply by the size of one record and by the number of days you keep the data.
total storage = new records per day × bytes per record × retention daysEach factor is an assumption. State it, round it, and keep going. The goal is the right order of magnitude (gigabytes, terabytes or petabytes), not an exact byte count.
A worked calculation
Suppose a service creates 100 million new records per day. Each record is about 500 bytes. You must keep records for 5 years.
new_records_per_day = 100_000_000
bytes_per_record = 500
retention_days = 365 * 5
total_bytes = new_records_per_day * bytes_per_record * retention_days
print(total_bytes / 1e12) # 91.25 (terabytes, decimal units)The result is about 91 TB. In a discussion you would round it: 100 million × 500 bytes is 50 GB per day, and 5 years is about 1,800 days, so the total is roughly 90 TB.
Where the record size comes from
The 500 bytes above is a guess, so build it from parts. Add up the fields and then add overhead.
| Part | Example size |
|---|---|
| IDs and foreign keys | 8 to 16 bytes each |
| Timestamps | 8 bytes each |
| Short text fields | 50 to 200 bytes |
| Row and index overhead | Often 20 to 100 percent extra |
A small row with a few IDs, two timestamps and a short string is a few hundred bytes. Large objects such as images or video are different. Store them as separate blobs and estimate them on their own, because they can be thousands of times larger than the metadata that points to them.
Factors that change the total
The simple formula leaves out several things that matter in practice.
- Replication. If the database keeps 3 copies, multiply by 3. The 91 TB above becomes about 270 TB of raw disk.
- Indexes. Secondary indexes add storage. A common rough allowance is 20 to 50 percent.
- Growth. If traffic doubles each year, the last year holds much more than the first. Estimate the final year's volume, or sum the years.
- Headroom. Disks should not run full. Planning for 60 to 70 percent utilization is common, which adds roughly 40 to 60 percent to the disk you buy.
- Compression. Text often compresses by 2 to 5 times. Treat this as an optional reduction, and state it separately so readers can see its effect.
Common errors
- Forgetting retention. A daily figure alone says nothing about the total. Always multiply by how long you keep the data.
- Mixing units. Bytes, KB and GB in the same line cause factor-of-1,000 mistakes. Convert everything to bytes first, then convert once at the end.
- Counting only the happy path. Updates, deletes and soft-deleted rows can keep data around longer than the retention rule suggests.
- Using today's volume for a five-year plan. Include growth, or say clearly that you assumed none.
Checking the result
Compare the answer with known scales. One server disk holds a few TB, so 91 TB raw is tens of disks, which is reasonable for one database cluster. A result of 91 PB would suggest a unit slip or an assumption that is far too large.
Exercise
A messaging app stores 20 million new messages per day. Each message averages 200 bytes. Messages are kept for 2 years, with 3 replicas. How much raw disk is needed, in rounded terabytes? Ignore indexes and headroom.
Show answer
Per day: 20,000,000 × 200 = 4 GB. Retention: 2 × 365 = 730 days, roughly 700. One copy is 4 GB × 730 ≈ 2.9 TB, about 3 TB. With 3 replicas, the total is about 9 TB (8.8 TB exact).