Sub topic 8
Estimating storage over a retention period
This chapter assumes you can convert daily active users into queries per second (covered earlier), know the powers of two and decimal size units, and can read short Python snippets. Here you turn write volume, record size, and retention into a total storage figure, then adjust it for the overhead that real systems add.
What you are estimating
Storage estimation answers one question: how much disk will the system need after it has run for its full retention period? The answer drives decisions about which database to pick, whether one machine is enough, and when you must shard (split data across machines).
The basic formula has three factors:
total storage = new records per day × bytes per record × retention daysEach factor is an assumption you state out loud. The result is only as good as those assumptions, so the goal is the right order of magnitude (gigabytes, terabytes, or petabytes), not an exact byte count.
Step 1: Estimate new records per day
Start from the traffic numbers you already have. Not every request creates a record. Reads do not add data, so only count the write path.
Suppose a service has 10 million daily active users (DAU), and 1 in 10 of them creates one new item per day:
- Writers per day: 10,000,000 × 0.1 = 1,000,000
- New records per day: 1,000,000 × 1 = 1,000,000
Keep the read/write ratio in mind. A system with a 100:1 read-to-write ratio has a small write volume compared to its read traffic, so storage may be modest even when QPS is high.
Step 2: Estimate bytes per record
Add up the fields in one record. Round each field to a convenient size.
| Field | Assumed size |
|---|---|
| ID | 8 bytes |
| User ID | 8 bytes |
| Timestamp | 8 bytes |
| Short text (about 200 characters) | 200 bytes |
| Other metadata | 276 bytes |
| Total | 500 bytes |
The total here is 500 bytes, a convenient round number. If a field is variable, such as text, use the average, not the maximum. If you are unsure, pick a value, write it down, and move on. You can revisit it later.
Large objects change the picture. Photos, videos, and file uploads are usually stored in object storage, and their sizes (for example 200 KB for a photo or 5 MB for a short video) dominate the metadata size. Estimate the media separately from the metadata row.
Step 3: Choose a retention period
Retention is how long you keep data before deleting or archiving it. It often comes from a product or legal requirement. Convert it to days:
- 30 days for logs
- 365 days for one year
- 365 × 5 = 1,825 days for five years
If the requirement is "keep forever", pick a planning horizon, such as five years, and say so.
Step 4: Multiply
Here is the calculation for a service that writes 100 million records per day, with 500-byte records kept for five 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)By hand, you would round 1,825 days to about 2,000 and compute 10^8 × 500 × 2,000 = 10^8 × 10^6 = 10^14 bytes, which is 100 TB. The exact figure is 91.25 TB, so the rounded answer is within 10 percent. That is close enough for a design discussion.
Step 5: Account for what raw size leaves out
The raw figure is a lower bound. Real deployments need more disk for several reasons.
Replication
Most production databases keep multiple copies of data so that one failed machine does not lose anything. A replication factor of 3 is common. Multiply raw storage by 3:
- 91.25 TB × 3 = about 274 TB
Indexes and storage overhead
Database indexes, row headers, and page padding add space. A rough allowance is 20 to 50 percent of the data size, though it varies widely by database and by the number of indexes. State the figure you use. For example, with a 30 percent allowance:
- 274 TB × 1.3 = about 356 TB
Headroom
Disks should not run at 100 percent. Filled disks slow down, and you need room for compaction and growth. Plan to use no more than 70 to 80 percent of capacity. Dividing by 0.7 gives:
- 356 TB / 0.7 = about 509 TB
So a "91 TB" requirement turns into roughly 500 TB of provisioned disk. The factor of five or six between raw and provisioned is normal, and it is why the overhead step matters.
Compression
Compression works in the other direction. Text and JSON often compress by 2 to 5 times, while already-compressed media barely compresses. If you assume compression, say which data it applies to and what ratio you used. A conservative approach is to ignore compression in the first estimate and mention it as upside.
A reusable function
Wrapping the formula in a function lets you try different assumptions quickly:
def estimate_storage_tb(
records_per_day,
bytes_per_record,
retention_days,
replication=3,
overhead=1.3,
max_utilization=0.7,
):
raw = records_per_day * bytes_per_record * retention_days
provisioned = raw * replication * overhead / max_utilization
return raw / 1e12, provisioned / 1e12
raw_tb, provisioned_tb = estimate_storage_tb(
records_per_day=100_000_000,
bytes_per_record=500,
retention_days=365 * 5,
)
print(round(raw_tb, 1)) # 91.2
print(round(provisioned_tb)) # 509Note that Python prints 91.2 here because round(91.25, 1) rounds to the nearest even digit in the last place under floating-point representation. For design purposes the difference is irrelevant.
Growth over time
Storage is not constant. It grows linearly if the write rate is constant, and faster if the user base is growing. A linear model gives the storage at the end of each year:
| Year | Cumulative raw storage |
|---|---|
| 1 | about 18 TB |
| 2 | about 37 TB |
| 3 | about 55 TB |
| 4 | about 73 TB |
| 5 | about 91 TB |
If the service has a retention window and deletes old data, storage levels off once the window is full. With a 30-day log window, storage stops growing after day 30 and stays at 30 days of data. Distinguish "keep forever" (grows without limit) from "keep for N days" (reaches a steady state).
Mixed data: metadata plus media
Many systems store small structured rows and large blobs side by side. Estimate each separately, then add them.
For example, a photo-sharing service with 1 million uploads per day:
- Metadata: 1,000,000 × 1 KB × 365 = about 0.37 TB per year
- Photos: 1,000,000 × 200 KB × 365 = about 73 TB per year
The photos are 200 times larger than the metadata, so the metadata can be ignored in a first pass. Recognizing which term dominates saves time. If one component is less than 5 percent of the total, drop it and say so.
If the service stores several sizes of each photo (thumbnail, medium, original), multiply by the number of variants, or add their sizes.
Common errors
- Mixing decimal and binary units. 1 TB is 10^12 bytes, while 1 TiB is 2^40, about 1.1 × 10^12. The gap is about 10 percent at terabyte scale and is acceptable for estimates, but pick one convention and keep it.
- Counting reads as writes. Only operations that create or change stored data add to storage.
- Using QPS instead of daily counts. If you start from peak QPS, you will overestimate daily volume. Convert from daily totals or from average QPS × 86,400.
- Forgetting replication. Raw size understates disk by a factor of 3 in typical setups.
- Using the maximum record size. The average record size gives a realistic total.
- Ignoring deletion. If data expires, the total plateaus. If you ignore this, you overestimate.
- Off-by-a-thousand mistakes. Writing out units at each step (bytes, KB, MB, GB, TB) catches these. Each step is a factor of 1,000 in decimal units.
Sanity checking the result
Compare your answer against known reference points:
- A single commodity server holds a few terabytes to tens of terabytes of disk. A 500 TB requirement therefore means dozens of machines, and that tells you the data must be sharded.
- A result of a few gigabytes means a single database instance is enough, and sharding would be unnecessary complexity.
- A result of tens of petabytes is the territory of the largest internet companies. If your small application produces this figure, recheck the inputs.
Summary of the method
- Count only records created per day.
- Estimate average bytes per record, adding up the fields.
- Choose the retention period in days.
- Multiply, writing the unit at each step.
- Apply replication, overhead, and headroom.
- Check whether the result is plausible and what it implies for the design.
Exercise
A messaging app has 20 million DAU. On average, each user sends 40 messages per day. Each message record is 300 bytes of text and metadata. Messages are kept for 2 years (use 730 days). Calculate the raw storage in terabytes, then the provisioned storage with replication factor 3 and no other overhead.
Show answer
Messages per day = 20,000,000 × 40 = 800,000,000 (8 × 10^8). Bytes per day = 8 × 10^8 × 300 = 2.4 × 10^11 (240 GB). Raw storage = 2.4 × 10^11 × 730 = 1.752 × 10^14 bytes, about 175 TB. With replication factor 3, provisioned storage is about 526 TB. Rounded by hand (700 days), the raw figure is about 168 TB, which is within 5 percent.
Exercise
A video service receives 500,000 uploads per day. Each video averages 20 MB. Metadata per video is 2 KB. Which component dominates storage, and how much raw storage does one year need?
Show answer
Video data per day = 500,000 × 20 MB = 10,000,000 MB = 10 TB. Metadata per day = 500,000 × 2 KB = 1,000,000 KB = 1 GB. Video is 10,000 times larger, so metadata can be ignored. One year of video = 10 TB × 365 = 3,650 TB, about 3.65 PB of raw storage, before replication.
Exercise
Application logs are produced at 50 GB per day and kept for 30 days. Does storage keep growing after the first month? What is the steady-state raw size?
Show answer
No. Once 30 days of data exist, each day's new logs are balanced by the deletion of the oldest day, so storage levels off. Steady state = 50 GB × 30 = 1,500 GB, or 1.5 TB raw.