Estimation and Capacity Sizing Questions
Structured back-of-the-envelope estimation for engineering systems: decomposing a system's load into requests per second, storage, bandwidth, memory, connections and machine counts from stated assumptions, turning average load into a provisioned peak with headroom, sizing shards, partitions and nodes, estimating the infrastructure cost those resources imply (storage, egress, requests, compute), using latency and throughput reference numbers, arriving at a defensible order-of-magnitude answer, and sanity-checking it. The fast approximate reasoning probed in system-design and engineering screens. Market sizing, business-impact and general Fermi estimates, project effort and schedule estimation, business-case arithmetic, statistical inference, and the choice of scaling strategy are covered elsewhere.
Your service averages 2,000 requests per second over a day. Walk through how you would estimate the peak you must provision for, using the daily traffic curve, weekly and seasonal patterns and a launch-day spike, and turn that peak into a server count when one server handles 400 requests per second at the target latency.
Sample Answer
The idea in plain words
The average (2,000 requests per second, RPS) is not what you provision for. Servers must survive the busiest minute you expect, and that minute is the daily average multiplied by several independent effects: the shape of the day (the diurnal curve), the busiest day of the week, the busiest season, and a one-off launch. Each effect is a multiplier. You estimate each one, multiply them for the scenarios that can really coincide, then divide the resulting peak by what one server can sustain, and add headroom so a failure does not take you under.
Terms used below: the peak-to-average ratio is the busiest moment divided by the mean; headroom is capacity you keep unused on purpose; a zone is an independent failure domain (a data centre or a section of one); autoscaling adds servers automatically when load rises, but a new server takes minutes to start and warm up.
Method, in the order to do it
- Pin down what the 2,000 means. Is it the mean over 24 hours of a typical day, of a typical week, or of last Tuesday? Here it is taken as the mean over a typical week. If it was measured on a quiet day, every multiplier below is applied to the wrong base.
- Get the daily shape. With metrics available, take hourly request counts for four to eight weeks, divide each hour by that day's mean, and read the curve. Without data, assume a smooth curve. Here the multiplier for hour h is
where a is the swing (an assumption, plausible range 0.3 to 0.9) and hpeak is the busiest hour. The 24 cosine values add to zero, so m averages exactly 1 and the daily mean stays 2,000. With a=0.6 the evening peak hour runs at 1.6 times the mean and the overnight trough at 0.4. The formula draws a smooth wave that is highest at hpeak and lowest 12 hours later. With hpeak=20 (20:00) and a=0.6 it gives:
| Clock hour | 02:00 | 05:00 | 08:00 | 11:00 | 14:00 | 17:00 | 20:00 | 23:00 |
|---|---|---|---|---|---|---|---|---|
| m(h) | 1.00 | 0.58 | 0.40 | 0.58 | 1.00 | 1.42 | 1.60 | 1.42 |
For example at 14:00 the angle is 2π×(−6)/24=−π/2, whose cosine is 0, so m=1; at 08:00 it is −π, cosine −1, so m=1−0.6=0.4.
3. Add the minute-level burst. Hourly counts hide the busiest minute. Assume the busiest minute is 1.15 times its hour (range 1.05 to 1.5; measure it from minute-level data if you have it).
4. Layer the calendar. Assume the busiest weekday is 1.15 times the weekly average (range 1.05 to 1.3) and the busiest season is 1.3 times a normal week (range 1.1 to 2.0). All of these are assumptions to be replaced by your own history.
5. Treat the launch separately. A launch is a planned, short event. Assume it multiplies the traffic of the hour it lands in by 2 (range 1.5 to 5). It raises the fleet only when the launch hour, doubled, exceeds the ordinary busiest hour: 2m(h)>m(hpeak), which here means m(h)>0.8. On this curve that is every hour from 13:00 through 03:00 (so a launch at 14:00 still raises the peak, and a launch at 20:00 raises it most); a launch from 04:00 through 12:00 does not. Its timing is a decision, not a fact.
6. Combine and convert to servers. The peak is
and the fleet is
N=⌈cuRpeak⌉,Ntotal=⌈N⋅Z−1Z⌉The brackets ⌈x⌉ mean round up to the next whole number, because you cannot run 13.2 servers. The factor Z/(Z−1) comes from losing one zone: with Z=3 zones, the two surviving zones must carry all of the load, so each zone must be able to hold half of the base count N, and the total is 3×N/2=1.5N. For N=14 that is 21 servers, 7 per zone, and after losing a zone the remaining 14 still cover the peak.
Here rˉ=2000, c=400 RPS per server (given, at the target latency), u=0.8 is the share of that figure you plan to use (an assumption, range 0.6 to 0.9, for uneven load balancing and deploys), and Z=3 zones, so that losing one zone leaves N servers running. The burst factor corrects for coarse time buckets and u corrects for imperfect server behaviour, so they are different effects and are not double counting.
Worked example by hand
- Normal weekday peak: 2000×1.6=3200, then 3200×1.15=3680 (weekday), then 3680×1.15=4232 (burst). Servers: 4232/(400×0.8)=4232/320=13.2, so 14. With a zone lost: 14×3/2=21.
- Seasonal peak: 4232×1.3=5501.6, call it 5,502 RPS. Servers: 5502/320=17.2, so 18, and 18×1.5=27.
- Launch in the evening peak hour during the season: 5501.6×2=11003.2, so 11,003 RPS. Servers: 11003/320=34.4, so 35, and 35×1.5=52.5, so 53.
- Launch at 10:00 instead: the curve at 10:00 is 1+0.6cos(2π⋅(−10)/24)=0.48, and 0.48×2=0.96, below the evening's 1.6, so the launch hour is not the busiest hour and the fleet stays at the seasonal-peak size.
- Launch at 14:00 instead: the curve is 1.0, doubled it is 2.0, above the evening's 1.6, so the peak becomes 2000×2.0×1.15×1.3×1.15=6877 RPS. Servers: 6877/320=21.5, so 22, and 22×1.5=33. Moving a launch off the evening peak helps, but only a launch in the morning window (04:00 to 12:00) leaves the fleet unchanged.
The program below does the same with every input visible, checks that the curve averages 1.0 (the check fails if a constant is added to the curve, which would silently change the daily mean), prints which launch hours raise the peak, recomputes the seasonal row by direct multiplication, and varies one input at a time.
import math
# ---- Assumptions (each with a plausible range) ----
MEAN_RPS = 2000 # given: daily average, taken as a typical-week day
AMPLITUDE = 0.6 # diurnal swing around the mean, range 0.3 to 0.9
PEAK_HOUR = 20 # busiest hour of the day (local evening), range 12 to 22
BURST = 1.15 # busiest minute vs its hour average, range 1.05 to 1.5
WEEKLY = 1.15 # busiest weekday vs weekly average, range 1.05 to 1.3
SEASON = 1.30 # busiest season vs normal weeks, range 1.1 to 2.0
LAUNCH = 2.0 # launch hour traffic vs a normal hour, range 1.5 to 5
CAP_PER_SERVER = 400 # given: requests/s one server handles at target latency
UTIL = 0.80 # run servers at no more than 80% of that figure, range 0.6 to 0.9
ZONES = 3 # servers spread over 3 zones, survive losing one
def curve(h, amp=AMPLITUDE):
return 1 + amp * math.cos(2 * math.pi * (h - PEAK_HOUR) / 24)
def servers(rps, cap=CAP_PER_SERVER, util=UTIL):
need = math.ceil(rps / (cap * util)) # servers if every zone is healthy
total = math.ceil(need * ZONES / (ZONES - 1)) # enough left after losing one zone
return need, total
def peak_rps(amp=AMPLITUDE, weekly=WEEKLY, season=1.0, launch=1.0, launch_hour=PEAK_HOUR):
best = 0.0
for h in range(24):
m = curve(h, amp) * (launch if h == launch_hour else 1.0)
best = max(best, MEAN_RPS * m * weekly * season * BURST)
return best
# Check 1: the curve must average 1.0 or the daily mean is not 2000
mean_mult = sum(curve(h) for h in range(24)) / 24
assert abs(mean_mult - 1.0) < 1e-9, mean_mult
print(f"curve mean={mean_mult:.3f} min={min(curve(h) for h in range(24)):.2f} max={max(curve(h) for h in range(24)):.2f}")
scen = [
("normal weekday peak", peak_rps()),
("seasonal peak", peak_rps(season=SEASON)),
("launch at evening peak in season", peak_rps(season=SEASON, launch=LAUNCH)),
("launch at 10:00 in season", peak_rps(season=SEASON, launch=LAUNCH, launch_hour=10)),
("launch at 14:00 in season", peak_rps(season=SEASON, launch=LAUNCH, launch_hour=14)),
]
print(f"{'scenario':36s}{'peak rps':>10s}{'x mean':>8s}{'servers':>9s}{'with 1 zone lost':>18s}")
for name, r in scen:
need, total = servers(r)
print(f"{name:36s}{r:10.0f}{r/MEAN_RPS:8.2f}{need:9d}{total:18d}")
# A launch raises the fleet only if the launch hour, doubled, beats the ordinary busiest hour
raising = [h for h in range(24) if LAUNCH * curve(h) > curve(PEAK_HOUR)]
print("launch hours that raise the peak:", " ".join(f"{h:02d}" for h in raising))
# Check 2: independent recomputation of the seasonal-peak row, straight multiplication
direct = MEAN_RPS * (1 + AMPLITUDE) * WEEKLY * SEASON * BURST
assert abs(direct - scen[1][1]) < 1e-6, (direct, scen[1][1])
need = math.ceil(direct / (400 * 0.8)); total = math.ceil(need * 3 / 2)
assert (need, total) == servers(scen[1][1])
print(f"check: direct product {direct:.0f} rps, {need} servers, {total} with a zone lost")
# Sensitivity: change one input at a time on the launch-at-peak scenario
print("sensitivity (launch at evening peak in season), servers with a zone lost:")
base = servers(scen[2][1])[1]
tests = [
("amplitude 0.3 / 0.9", lambda: [servers(peak_rps(amp=a, season=SEASON, launch=LAUNCH))[1] for a in (0.3, 0.9)]),
("weekly 1.05 / 1.30", lambda: [servers(peak_rps(weekly=w, season=SEASON, launch=LAUNCH))[1] for w in (1.05, 1.30)]),
("season 1.1 / 2.0", lambda: [servers(peak_rps(season=s, launch=LAUNCH))[1] for s in (1.1, 2.0)]),
("launch 1.5 / 5", lambda: [servers(peak_rps(season=SEASON, launch=l))[1] for l in (1.5, 5)]),
("per-server rps 300 / 500", lambda: [servers(scen[2][1], cap=c)[1] for c in (300, 500)]),
]
print(f" base case: {base}")
for label, f in tests:
lo, hi = f()
print(f" {label:26s} -> {lo} / {hi}")
Output:
curve mean=1.000 min=0.40 max=1.60
scenario peak rps x mean servers with 1 zone lost
normal weekday peak 4232 2.12 14 21
seasonal peak 5502 2.75 18 27
launch at evening peak in season 11003 5.50 35 53
launch at 10:00 in season 5502 2.75 18 27
launch at 14:00 in season 6877 3.44 22 33
launch hours that raise the peak: 00 01 02 03 13 14 15 16 17 18 19 20 21 22 23
check: direct product 5502 rps, 18 servers, 27 with a zone lost
sensitivity (launch at evening peak in season), servers with a zone lost:
base case: 53
amplitude 0.3 / 0.9 -> 42 / 62
weekly 1.05 / 1.30 -> 48 / 59
season 1.1 / 2.0 -> 45 / 80
launch 1.5 / 5 -> 39 / 129
per-server rps 300 / 500 -> 69 / 42
Computed with Python 3.12 (standard library only).
What to recommend
Commit to this plan under the stated assumptions:
- Permanent fleet: 27 servers, sized for the seasonal peak with one zone lost. The normal-day peak needs only 21, so about six servers sit idle outside the season; that is the price of surviving the season and a zone failure together. Whether to buy that or to add servers when the season starts is a cost question; the season is predictable, so scheduled scale-up a few days ahead is the cheaper option.
- Launch: schedule it in the morning window and pre-scale anyway (add servers before the expected spike instead of reacting to it). Between 04:00 and 12:00 the doubled curve stays under the evening peak, so at 10:00 the model says 27 servers still cover it; a launch at 14:00 would need 33. But the 2x applies to a whole hour; a launch can front-load a spike (put most of the hour's extra traffic into its first minutes), which a model built on hourly means understates. If it must coincide with the evening peak, 53 servers are needed for the launch window only (35 servers, or 53 with a zone lost, against the 18 and 27 of the seasonal peak). Autoscaling cannot fill that gap on its own because a spike arrives in seconds and a new server takes minutes to start and warm up (load its code and fill its caches before it runs at full speed), so add the servers before the announcement and remove them afterwards.
- Validate the 400 per server figure with a load test at the target latency (state which percentile, such as the 99th: the latency that 99 percent of requests beat). The whole result moves with it: 300 per server gives 69 and 500 gives 42 in the sensitivity block.
The sensitivity block shows which assumption deserves the effort. With the launch landing at the peak, the launch multiplier moves the answer from 39 to 129 servers (a spread of 90) and the season factor from 45 to 80 (a spread of 35). The amplitude (42 to 62, a spread of 20) and the weekday factor (48 to 59, a spread of 11) move it less, and the per-server figure (42 to 69, a spread of 27) matters almost as much as the season, which is why it gets a load test. Spend the research time on the launch size, the season and the per-server capacity, not on the third digit of the daily curve.
What would change the plan: a measured daily curve that is flatter or sharper than the cosine; a user base spread over time zones, which flattens the curve because each region peaks at a different clock hour; a growth rate (provisioning for next quarter means multiplying everything by expected growth); a launch size taken from marketing's forecast rather than guessed.
Common mistakes
- Dividing the average by 400 (2000 / 400 = 5 servers) and stopping.
- Multiplying every worst case together without asking whether they coincide: launch, season, weekday and evening all at once is a stress scenario, not the expected peak, and the plan above treats it as a temporary one.
- Forgetting the burst and headroom, so the fleet runs at its limit at the busiest minute and the target latency is missed.
- Forgetting that failures remove capacity: a fleet sized exactly for peak has no room for losing a server or a zone.
- Using the average of a quiet period as the base.
Running the code
python peak.py
Save the program as peak.py. It needs only the Python 3.12 standard library (math) and no input files.
You are asked to size a URL shortener before designing it: 100 million new short links a month and a read-to-write ratio of 100 to 1. Estimate the write and read requests per second at average and at peak, and the storage needed for five years of links. State every assumption and sanity-check the result.
Sample Answer
The idea in plain words
Sizing means turning a few stated numbers into the three quantities that shape a design: how many requests per second (RPS, requests arriving each second) the system must handle, how much data it must store, and how big the gap is between a normal moment and a peak. The one insight for a URL shortener is that it is a read-heavy system with a tiny write rate: 100 million new links a month sounds large, but it is only a few dozen writes per second, while the reads (people following a short link, which the service answers with a redirect) are 100 times more frequent and set the load on the serving path. Storage is the other half: each link is a small row, so even five years of links is a few terabytes.
Every input below is an assumption, labelled with a plausible range. None of it is a statistic about a real service.
Method, in the order you would do it
- Fix the time unit. A month is assumed to be 30 days, so it has 30×86,400=2,592,000 seconds (a day has 86,400 seconds). The calendar mean of 30.4 days changes every rate by about 1.3 percent, which is far below the uncertainty of the other inputs.
- Average write rate. writes per second=seconds per monthnew links per month
- Average read rate. The 100 to 1 ratio is read requests per write request, so reads per second=100×writes per second
- Peak rate. Traffic is not flat. The peak-to-average ratio (how much busier the busiest moment is than the mean) is an assumption: 3 here, with a range of 2 to 10 depending on how spiky the traffic is. peak=peak-to-average ratio×average
- Storage. bytes=links stored×bytes per record×copies kept where links stored is 100M×12×5 and copies kept is the replication factor (how many copies of each row are stored for durability).
- Sanity-check against a size that can be checked independently: the number of distinct short codes available, the bandwidth the reads imply, and what a single machine can hold.
Assumptions
| Input | Value | Plausible range | Note |
|---|---|---|---|
| New links per month | 100 million | given | |
| Read requests per write | 100 | given | redirects per link creation |
| Days per month | 30 | 30 to 30.4 | |
| Peak-to-average ratio | 3 | 2 to 10 | applied to reads and writes alike |
| Years retained | 5 | given | no expiry or deletion assumed |
| Bytes per record | 500 | 200 to 1000 | 7-character code, long URL (often 100 bytes or more), timestamps, owner id, index overhead |
| Copies kept | 3 | 2 to 3 | one primary plus two replicas (the primary is the copy of the database that accepts writes; replicas are copies of it that serve reads and keep the data if a machine is lost) |
| Short-code length | 7 | 6 to 8 | characters from a 62-symbol alphabet (a to z, A to Z, 0 to 9), which is what "base62" means: each character carries one of 62 values |
All sizes use decimal units: 1 TB is 1012 bytes.
Worked example, computed by a program
The program prints every intermediate quantity and a sensitivity table, then recomputes the average and peak rates, the link count and the storage (one copy and replicated) by a different route (links per day, exact fractions) and prints PASS or FAIL.
from fractions import Fraction
# Assumptions (ranges in comments)
new_links_per_month = 100_000_000 # given
read_write_ratio = 100 # given: 100 read requests per write request
days_per_month = 30 # assumption: 30 (30.4 is the calendar mean)
peak_multiple = 3 # assumption: peak = 3 x average (range 2 to 10)
years = 5 # given
bytes_per_record = 500 # assumption: code + long URL + timestamps + owner + index overhead (range 200 to 1000)
replicas = 3 # assumption: copies kept for durability (range 2 to 3)
code_len = 7 # assumption: base62 short code length
seconds_per_month = days_per_month * 86_400
write_avg = new_links_per_month / seconds_per_month
read_avg = write_avg * read_write_ratio
write_peak = write_avg * peak_multiple
read_peak = read_avg * peak_multiple
links_total = new_links_per_month * 12 * years
storage_bytes = links_total * bytes_per_record
storage_tb = storage_bytes / 1e12
stored_tb = storage_tb * replicas
keyspace = 62 ** code_len
print(f"seconds per month : {seconds_per_month:,}")
print(f"writes/s avg, peak : {write_avg:.1f}, {write_peak:.1f}")
print(f"reads/s avg, peak : {read_avg:,.0f}, {read_peak:,.0f}")
print(f"links in {years} years : {links_total:,}")
print(f"data (1 copy), TB : {storage_tb:.2f}")
print(f"data x{replicas} replicas, TB : {stored_tb:.2f}")
print(f"base62^{code_len} keyspace : {keyspace:,} used {100*links_total/keyspace:.3f}%")
print("sensitivity of stored TB (x3 replicas) to bytes per record:")
for b in (200, 500, 1000):
print(f" {b:>4} B/record -> {links_total*b*replicas/1e12:.1f} TB")
print("sensitivity of peak reads/s to peak multiple:")
for m in (2, 3, 10):
print(f" x{m:<2} -> {read_avg*m:,.0f}")
# Independent recomputation with exact fractions, via a per-day route
per_day = Fraction(new_links_per_month, days_per_month)
write_avg_b = per_day / 86_400
write_peak_b = write_avg_b * peak_multiple
read_avg_b = write_avg_b * read_write_ratio
read_peak_b = read_avg_b * peak_multiple
links_b = per_day * days_per_month * 12 * years
tb_b = links_b * bytes_per_record / Fraction(10**12)
ok = (abs(float(write_avg_b) - write_avg) < 1e-9
and abs(float(write_peak_b) - write_peak) < 1e-9
and abs(float(read_avg_b) - read_avg) < 1e-6
and abs(float(read_peak_b) - read_peak) < 1e-6
and links_b == links_total
and abs(float(tb_b) - storage_tb) < 1e-9
and abs(float(tb_b * replicas) - stored_tb) < 1e-9)
print("check (per-day route, exact fractions):", "PASS" if ok else "FAIL")
Output:
seconds per month : 2,592,000
writes/s avg, peak : 38.6, 115.7
reads/s avg, peak : 3,858, 11,574
links in 5 years : 6,000,000,000
data (1 copy), TB : 3.00
data x3 replicas, TB : 9.00
base62^7 keyspace : 3,521,614,606,208 used 0.170%
sensitivity of stored TB (x3 replicas) to bytes per record:
200 B/record -> 3.6 TB
500 B/record -> 9.0 TB
1000 B/record -> 18.0 TB
sensitivity of peak reads/s to peak multiple:
x2 -> 7,716
x3 -> 11,574
x10 -> 38,580
check (per-day route, exact fractions): PASS
Reading the output:
- Writes: 100,000,000 / 2,592,000 is 38.6 per second on average and 115.7 at the assumed peak of 3 times average.
- Reads: 100 times that, 3,858 per second on average and 11,574 at peak.
- Storage: 100M links a month for 60 months is 6,000,000,000 links. At 500 bytes each that is 3.00 TB for one copy and 9.00 TB with three copies.
Sanity checks
- Is 6 billion links possible with 7 characters? Seven symbols from a 62-symbol alphabet give 627=3,521,614,606,208 codes, so five years of links use 0.170 percent of the space. Six characters (626≈5.7×1010) would also fit, with about 10.6 percent of the space used.
- Is the read bandwidth sane? A redirect response is small. At an assumed 500 bytes: 11,574×500=5,787,000 bytes per second, which is about 5.8 MB/s or 46 Mbit/s (megabits, millions of bits, per second; multiply bytes by 8 to get bits). That is trivial for one network interface.
- Does the data fit on one machine? 3 TB for one copy fits on a single modern server's SSD storage, so storage alone does not force sharding (splitting data across machines by key). Replicas exist for durability and read capacity, not because the data is too big.
- Cache effect. The cache hit ratio is the share of requests answered from the cache (a fast in-memory copy of hot links). If an assumed 80 percent of redirects are hits, the database sees the other 20 percent of the peak: 0.2×11,574≈2,315 reads per second.
The judgment
The numbers say this service is easy to size and the design risk is elsewhere. Write capacity (about 116 per second at peak) is not a constraint for a single primary database (the copy that takes the writes). The read path (about 11,600 per second at peak) is best served from a cache in front of a replicated store, so the database tier sees a small fraction of it. Storage of roughly 3 TB (9 TB with three copies) is the number to plan disks around.
What changes the conclusion:
- A 10 times peak instead of 3 times raises peak reads to 38,580 per second (see the sensitivity lines) and makes the cache hit ratio (the share of reads the cache answers) the thing to design, not the database.
- Per-click analytics. If every redirect also writes a 100 byte analytics event, that adds 3,858×100 B≈385,800 bytes per second, about 33.3 GB per day (385,802 bytes per second times 86,400), which would dominate the link table over time. That is a separate store with different needs.
- Larger records (long URLs, tracking parameters) move storage linearly: 200 to 1000 bytes per record gives 3.6 to 18.0 TB with three copies.
Common mistakes
- Using 365 times 24 times 60 times 60 for a month, or dividing by seconds per day instead of seconds per month.
- Applying the 100 to 1 ratio to the wrong base: reads per second are 100 times writes per second (3,858 against 38.6 on average), not 100 times the 6 billion links stored.
- Quoting the average as if it were the peak, or the peak as if it were the average.
- Forgetting replication, or mixing TB and TiB (1 TiB, the binary terabyte of 10244 bytes, is 1.0995 TB) without saying which.
- Stopping at the arithmetic with no sanity check against the code space or one machine's capacity.
Running the code
Python 3.12, standard library only.
python url_shortener_sizing.py
A relational database holds 30 TB today, grows by 50 GB a day and must absorb 40,000 writes per second at peak. If one node comfortably handles 5,000 writes per second and 4 TB of data, estimate how many shards you need today and in two years, and which constraint drives the number.
Sample Answer
The idea in plain words
A shard is one horizontal slice of a database: each shard holds a different subset of the rows and runs on its own primary node (the node that accepts the writes for that shard; replicas are copies of it kept for availability), so adding shards adds both storage room and write capacity. A node has two limits at once: how much data it can hold (4 TB here) and how many writes per second it can absorb (5,000 here). The number of shards is the larger of the two counts, and the constraint that produces the larger count is the one that drives the design. Here the two counts tie today at 8, but data grows and writes (as stated) do not, so storage takes over within weeks and is what sets the two-year number.
Method, in the order you would do it
- Count shards for each constraint separately. shards by data=⌈4data in TB⌉shards by writes=⌈5,000peak writes per second⌉ The brackets mean round up, because you cannot buy part of a node.
- Take the maximum. The shard count is the larger of the two.
- Project the inputs forward. Data in two years is 30+50 GB per day×730 days÷1000=66.5 TB (decimal units, 1 TB is 1,000 GB). The question gives no growth rate for writes, so treat peak writes as flat and test growth as a scenario.
- Add a buffer. "Comfortably handles" is a design figure, but real data and traffic are not spread perfectly evenly across shards. A buffer (1.25 times is assumed here, with a plausible range of 1.1 to 1.5) covers uneven spread and growth between hardware purchases. It is applied to the data count and to the write count separately because each limit can be hit separately: skew (some shards getting more data or traffic than others) can fill one shard's disk while another stays half empty, and a busy key can saturate one shard's write capacity while the others idle.
- Say which constraint binds, and when it changes.
Worked example, computed by a program
The program evaluates the five cases, finds the day each shard count is first needed by stepping through the days in whole gigabytes, and compares that with a closed-form calculation.
import math
# Given
data_now_tb = 30
growth_gb_per_day = 50
writes_peak_now = 40_000
node_writes = 5_000
node_tb = 4
# Assumptions
days = 730 # two years
write_growth_2y = 1.0 # peak writes in two years / today (1.0 = flat; range 1 to 3)
headroom = 1.25 # skew and growth buffer on the binding limit (range 1.1 to 1.5)
def shards(data_tb, writes, buffer=1.0):
by_data = math.ceil(data_tb * buffer / node_tb)
by_writes = math.ceil(writes * buffer / node_writes)
return by_data, by_writes, max(by_data, by_writes)
data_2y_tb = data_now_tb + growth_gb_per_day * days / 1000
print(f"data in 2 years, TB : {data_2y_tb:.1f}")
print(f"{'case':<28}{'by data':>8}{'by writes':>10}{'shards':>8}")
cases = [
("today, no buffer", data_now_tb, writes_peak_now, 1.0),
("2 years, writes flat", data_2y_tb, writes_peak_now * write_growth_2y, 1.0),
("2 years, writes x2.2", data_2y_tb, writes_peak_now * 2.2, 1.0),
(f"today, {headroom}x buffer", data_now_tb, writes_peak_now, headroom),
(f"2 years flat, {headroom}x buffer", data_2y_tb, writes_peak_now, headroom),
]
for name, d, w, b in cases:
bd, bw, n = shards(d, w, b)
print(f"{name:<28}{bd:>8}{bw:>10}{n:>8}")
capacity_tb = 8 * node_tb
print(f"days until 8 shards are full by data: {(capacity_tb - data_now_tb) * 1000 / growth_gb_per_day:.0f}")
print("sensitivity of 2-year shards (no buffer, writes flat) to growth per day:")
for g in (25, 50, 100):
d = data_now_tb + g * days / 1000
print(f" {g:>3} GB/day -> data {d:.1f} TB -> {math.ceil(d / node_tb)} shards")
# Independent recomputation: walk the days in whole GB and find when each shard count is first needed
need = {}
for day in range(0, days + 1):
data_gb = data_now_tb * 1000 + growth_gb_per_day * day
n = max(math.ceil(data_gb / (node_tb * 1000)), math.ceil(writes_peak_now / node_writes))
need.setdefault(n, day)
first_day_9 = (capacity_tb - data_now_tb) * 1000 // growth_gb_per_day + 1 # closed form
ok = (max(need) == shards(data_2y_tb, writes_peak_now)[2] and need[9] == first_day_9 and need[8] == 0)
print("first day each count is needed:", {k: need[k] for k in (8, 9, 10, 17)})
print("check (day-by-day walk vs closed form):", "PASS" if ok else "FAIL")
Output:
data in 2 years, TB : 66.5
case by data by writes shards
today, no buffer 8 8 8
2 years, writes flat 17 8 17
2 years, writes x2.2 17 18 18
today, 1.25x buffer 10 10 10
2 years flat, 1.25x buffer 21 10 21
days until 8 shards are full by data: 40
sensitivity of 2-year shards (no buffer, writes flat) to growth per day:
25 GB/day -> data 48.2 TB -> 13 shards
50 GB/day -> data 66.5 TB -> 17 shards
100 GB/day -> data 103.0 TB -> 26 shards
first day each count is needed: {8: 0, 9: 41, 10: 121, 17: 681}
check (day-by-day walk vs closed form): PASS
Reading the output:
- Today. 30 TB / 4 TB is 7.5, rounded up to 8. 40,000 / 5,000 is exactly 8. The two constraints tie at 8 shards, which means that at 8 shards writes sit at 100 percent of the stated comfortable rate and data at 30/32=93.75 percent of capacity. There is no slack on either.
- Why storage takes over immediately. Eight shards hold 32 TB, so with 50 GB arriving each day they are full after (32−30)×1000/50=40 days, and a ninth shard is needed on day 41 (the day-by-day walk finds the same day). Writes do not move unless they grow.
- In two years. 66.5 TB / 4 TB is 16.6, so 17 shards by data against 8 by writes. Storage drives the number.
- When writes would take over. 17 shards absorb 17×5,000=85,000 writes per second, which is 2.125 times today's peak. If peak writes grew faster than that, writes would drive. With writes growing 2.2 times (roughly in line with data, since 66.5/30≈2.2), the write count is 18 and edges ahead of the data count of 17.
- With the buffer. Applying 1.25 times to both gives 10 shards today and 21 in two years.
The judgment
Plan for roughly 10 primary shards now and 21 in two years, with storage as the driver. In an interview the commitments are:
- Answer both asks. Today: 8 minimum, 10 with a buffer, and the constraint is a tie that storage breaks within weeks. Two years: 17 minimum, 21 with a buffer, and storage drives.
- Design the shard map for growth. Hash the key into many fixed logical slots (for example 64 or 128), and assign slots to nodes with a lookup table, the shard map. Going from 10 to 21 nodes then means moving slots, not rehashing every row. For example, 64 slots on 10 nodes is 4 nodes with 7 slots and 6 nodes with 6 (4×7+6×6=64). On 21 nodes it is 20 nodes with 3 slots and one with 4 (20×3+4=64), so the 11 new nodes take about 33 slots, roughly half the slots, from the old nodes. Every key still hashes to the same slot as before; only the shard map changes, and only the rows in moved slots travel. Hashing the key straight to a node number (hash mod 10, then hash mod 21) would instead leave only about 1 key in 21 on its old node.
- Replication is separate. The counts above are primaries. Keeping, say, two replicas per shard for availability (copies of the shard's data on other machines, so it survives losing the primary) triples the machine count (30 today with the buffer) but adds no write capacity, because every write must still be applied on the primary.
- Cheaper levers than more shards. Because storage drives, archiving or compressing old rows lowers the count directly. If writes ever drive, batching writes or removing secondary indexes (extra lookup structures on columns other than the key, each of which must be updated on every write) lowers the per-write cost.
What would flip it: faster data growth (100 GB per day gives 103.0 TB and 26 shards in two years; 25 GB per day gives 13, per the sensitivity lines), or a write rate that grows faster than 2.125 times.
Common mistakes
- Giving only the writes figure (8) or only the data figure (8) and calling it done, instead of computing both and taking the maximum.
- Rounding down. 7.5 nodes means 8.
- Ignoring skew: one very popular key can saturate one shard even when the average is fine.
- Forgetting replicas when counting machines, or counting them as extra write capacity.
- Mixing TB and TiB, or assuming the stated per-node limits are hard ceilings rather than comfortable operating points.
Running the code
Python 3.12, standard library only.
python shard_sizing.py
A teammate's back-of-the-envelope estimate says a photo service needs 4 petabytes of new storage per day for 10 million daily uploads. Find what is wrong with the estimate, explain the checks that catch this kind of error (units, bits versus bytes, per-second versus per-day, order of magnitude against a known system), and give a corrected figure.
Sample Answer
The idea in plain words
Divide the claim back into a size per item. 4 petabytes (PB; 1 PB is 1015 bytes) per day spread over 10 million uploads is 4×1015/107=4×108 bytes, which is 400 megabytes (MB) per photo. A photo from a phone is typically a few MB (an assumption, range 1 to 10 MB for a stored original). So the estimate is about 100 times too high. The check that found it, dividing a total by a count to see whether the unit looks believable, takes ten seconds and works on almost any estimate.
All sizes below are decimal (1 MB = 106 bytes, 1 TB = 1012 bytes) so the prefixes stay consistent; the 1024-based versions differ by roughly 5 percent at the megabyte level and 10 percent at the terabyte level, which does not change an order of magnitude.
The checks, in the order to run them
- Write every quantity with its unit and basis. "4 PB per day" is bytes per day. "10 million uploads per day" is a count per day. Both are per day, so the division is legitimate.
- Divide back to a per-item size. 400 MB per photo. Compare with objects you know: a phone photo is a few MB, a short video clip is tens to hundreds of MB. A 400 MB "photo" is the size of a video clip, which a photo service is not expected to store as a photo.
- Check the common slips one by one. Compare the claim with an honest estimate (10 million times 4 MB) and see whether the ratio matches a known factor:
- bits versus bytes: a factor of 8 (1 byte is 8 bits);
- per second versus per day: a factor of 86,400 (seconds in a day);
- a prefix mistake such as KB for MB: a factor of 1,000;
- 1000 versus 1024 conventions: a factor of 1.024 per prefix step (about 1.05 at megabytes, 1.10 at terabytes, 1.13 at petabytes);
- miscounting zeros in the count or the size: a factor of 10, 100 and so on.
- Recompute forward by a second route. Go per day, then go per second and multiply back by 86,400. If the two disagree, there is a unit slip in one of them.
- Cross-check a second quantity. The ingest rate implied by the claim should look believable too.
- Compare with a reference of known scale. Express the result in something you can picture: how many large disks fill up per day, and whether the implied network rate is plausible for the service.
Worked example by hand
Assumptions: 10 million uploads per day (given), 4 MB average stored original (range 1 to 10), derived copies such as thumbnails and resized versions add 25 percent of the original (range 10 to 60 percent), 3 full replicas (replication factor 3; 1.5 if erasure coded, a scheme that stores parity pieces instead of whole copies).
- Originals per day: 107×4×106=4×1013 bytes = 40 TB.
- With derived copies: 40×1.25=50 TB.
- Physical disk after 3 replicas: 50×3=150 TB per day.
- Per year, originals only: 40×365=14,600 TB = 14.6 PB.
- Upload rate: 107/86400=115.7 per second on average. At 4 MB each that is 463 MB/s, and times 8 bits per byte it is 3,704 megabits per second, about 3.70 gigabits per second (Gbit/s). If the peak is 3 times the average (an assumption), the figure to design for is 3.70×3=11.1 Gbit/s.
- The claim, as a rate: 4×1015/86400=4.63×1010 bytes per second = 46.3 GB/s = 370 Gbit/s on average, which is 100 times the 3.70 Gbit/s.
- In disks: with 20 TB disks (assumption), the claim fills 4000/20=200 disks per day before replication; the corrected physical figure fills 150/20=7.5.
Ratios: the claim is 100 times the 40 TB of originals, and 4000/150=26.7 times the 150 TB of physical storage. Pushing every assumption to the top of its range (10 MB, derived copies at 0.6, 3 replicas) gives 107×10×1.6×3/106=480 TB per day, still 4000/480=8.3 times below the claim. No choice inside the stated ranges reaches 4 PB.
import math
# ---- Assumptions (decimal units: 1 MB = 10**6 bytes, 1 TB = 10**12, 1 PB = 10**15) ----
UPLOADS_PER_DAY = 10_000_000 # given
PHOTO_MB = 4.0 # average stored original, range 1 to 10
DERIVED = 0.25 # thumbnails and resized copies as a fraction of the original, range 0.1 to 0.6
REPLICAS = 3 # full copies kept, 1.5 if erasure coded, range 1.5 to 3
CLAIMED_PB_PER_DAY = 4.0 # the teammate's figure
SECONDS_PER_DAY = 86_400
PLAUSIBLE_PHOTO_MB = (0.05, 100) # illustrative band for one uploaded image
claimed_bytes = CLAIMED_PB_PER_DAY * 1e15
implied_mb = claimed_bytes / UPLOADS_PER_DAY / 1e6
print(f"implied size per upload: {implied_mb:.0f} MB")
lo, hi = PLAUSIBLE_PHOTO_MB
print(f"inside the {lo}-{hi} MB photo band: {lo <= implied_mb <= hi}")
# Which single slip would explain the claim, given a 4 MB photo and 10 million uploads?
honest_bytes = UPLOADS_PER_DAY * PHOTO_MB * 1e6
ratio = claimed_bytes / honest_bytes
slips = {"bits vs bytes (x8)": 8, "KB vs MB (x1000)": 1000, "per second vs per day (x86400)": 86400,
"1024 vs 1000 (x1.024 to x1.13)": 1.024, "two extra zeros (x100)": 100}
print(f"claim / honest estimate = {ratio:.0f}")
for name, f in slips.items():
print(f" {name:32s} reproduces claim: {math.isclose(f, ratio, rel_tol=0.01)}")
# Corrected estimate, step by step
original_tb = UPLOADS_PER_DAY * PHOTO_MB * 1e6 / 1e12
with_derived_tb = original_tb * (1 + DERIVED)
physical_tb = with_derived_tb * REPLICAS
print(f"originals per day: {original_tb:.0f} TB")
print(f"with derived copies: {with_derived_tb:.1f} TB")
print(f"physical with {REPLICAS} replicas: {physical_tb:.1f} TB")
print(f"originals per year: {original_tb * 365 / 1000:.2f} PB")
# Bandwidth view (bytes vs bits)
avg_upload_rate = UPLOADS_PER_DAY / SECONDS_PER_DAY
avg_mb_s = avg_upload_rate * PHOTO_MB
print(f"uploads per second (average): {avg_upload_rate:.1f}")
print(f"ingest: {avg_mb_s:.0f} MB/s = {avg_mb_s * 8 / 1000:.2f} Gbit/s")
print(f"claimed figure would be {claimed_bytes / SECONDS_PER_DAY / 1e9:.1f} GB/s = {claimed_bytes / SECONDS_PER_DAY * 8 / 1e9:.0f} Gbit/s")
# Independent recomputation: per-second route (with seconds per day spelled out as 24*60*60) must match the per-day route
per_second_route_tb = avg_upload_rate * PHOTO_MB * 1e6 * (24 * 60 * 60) / 1e12
assert math.isclose(per_second_route_tb, original_tb, rel_tol=1e-9), (per_second_route_tb, original_tb)
assert not (lo <= implied_mb <= hi), "claim should fail the size check"
print("check: per-second route equals per-day route")
# Sensitivity on physical TB per day
def phys(mb=PHOTO_MB, d=DERIVED, r=REPLICAS, n=UPLOADS_PER_DAY):
return n * mb * 1e6 * (1 + d) * r / 1e12
print(f"photo size 1 / 10 MB -> {phys(mb=1):.1f} / {phys(mb=10):.1f} TB")
print(f"derived 0.1 / 0.6 -> {phys(d=0.1):.1f} / {phys(d=0.6):.1f} TB")
print(f"replication 1.5 / 3 -> {phys(r=1.5):.1f} / {phys(r=3):.1f} TB")
print(f"uploads 5M / 20M -> {phys(n=5_000_000):.1f} / {phys(n=20_000_000):.1f} TB")
drive_tb = 20
print(f"drives of {drive_tb} TB filled per day: claim {claimed_bytes / 1e12 / drive_tb:.0f} (before replicas), corrected {physical_tb / drive_tb:.1f}")
Output:
implied size per upload: 400 MB
inside the 0.05-100 MB photo band: False
claim / honest estimate = 100
bits vs bytes (x8) reproduces claim: False
KB vs MB (x1000) reproduces claim: False
per second vs per day (x86400) reproduces claim: False
1024 vs 1000 (x1.024 to x1.13) reproduces claim: False
two extra zeros (x100) reproduces claim: True
originals per day: 40 TB
with derived copies: 50.0 TB
physical with 3 replicas: 150.0 TB
originals per year: 14.60 PB
uploads per second (average): 115.7
ingest: 463 MB/s = 3.70 Gbit/s
claimed figure would be 46.3 GB/s = 370 Gbit/s
check: per-second route equals per-day route
photo size 1 / 10 MB -> 37.5 / 375.0 TB
derived 0.1 / 0.6 -> 132.0 / 192.0 TB
replication 1.5 / 3 -> 75.0 / 150.0 TB
uploads 5M / 20M -> 75.0 / 300.0 TB
drives of 20 TB filled per day: claim 200 (before replicas), corrected 7.5
Computed with Python 3.12 (standard library only). The size band in the program is an illustrative test for one uploaded image; a real review would also cover video, RAW files and very large panoramas.
What is wrong, and the corrected figure
The estimate implies 400 MB per photo. Of the slips tried, only a factor of 100 reproduces it: either the per-photo size was entered as roughly 400 MB instead of roughly 4 MB, or the count was read as about a billion uploads instead of 10 million. The list of slips is not exhaustive and the number alone cannot say which happened, so ask the author for the derivation line by line. The bits-versus-bytes factor of 8, the per-second factor of 86,400 and the prefix factor of 1,000 each fail to match.
The corrected figure, under the assumptions above: about 40 TB per day of new original photos, about 50 TB with derived copies, and about 150 TB per day of physical disk with 3 replicas. Varying one assumption at a time, the physical figure ranges from 37.5 TB (1 MB photos) to 375 TB (10 MB photos), and with every assumption at the top of its range it reaches 480 TB, still far below 4 PB. Name the basis whenever you quote one: logical bytes (what users uploaded) versus physical bytes (what the disks hold).
Judgment
State the corrected figure with its range and its basis, and say what would change it: if the service also accepts video, the average object size and the whole answer change, and video should be estimated as its own line. Reconcile with real data when it exists: the storage system's growth over the last few weeks is a measurement that overrides any estimate here.
Common mistakes
- Comparing two numbers on different bases, such as a claim meant as physical disk against 40 TB of logical originals.
- Reporting the corrected figure without saying what it includes (originals only, derived copies, replicas).
- Fixing the arithmetic but not testing the result against a size you know.
- Mixing MB/s and Mbit/s: network links are quoted in bits, storage in bytes.
- Treating 86,400 as 100,000 and calling it close enough; that is fine for an order of magnitude only if it is stated.
Running the code
python photo.py
Save the program as photo.py. It needs only the Python 3.12 standard library (math) and no input files.
Estimate the peak outbound bandwidth and the monthly data egress for a video streaming service with 5 million daily viewers who each watch about an hour a day across a mix of resolutions. Show how the bitrate mix and the evening peak change the answer, and what the egress figure implies for serving it from a CDN.
Sample Answer
The idea in plain words
Egress is data leaving your servers toward viewers, and it is what you serve and (usually) what you pay for. For video it comes from one product: viewing time multiplied by bitrate, the number of bits per second the player receives (a sharper picture needs more bits per second).
The one insight is that the bitrate mix sets the volume (total data per month) while the shape of the day sets the peak (how many bits per second you must be able to push at the busiest moment), and the two are sized separately. A CDN (content delivery network: servers placed near viewers that keep copies of popular video so it does not travel from your own servers each time) then decides how much of that peak your own origin servers actually see. Two names recur below: the origin is your own servers, which hold the master copy of every video, and an edge server is one of the CDN's cache machines placed near viewers, answering most requests so the origin does not have to.
Every input below is an assumption with a plausible range, not a statistic about a real service.
Method
- Viewer-seconds per day (one viewer watching for one second). 5,000,000×1 hour×3600=1.8×1010 viewer-seconds.
- Average bitrate from the mix. Each resolution tier has an assumed bitrate and a share of viewing time. The weighted mean is average Mbps=∑isharei×ratei where Mbps is megabits (millions of bits) per second.
- Daily and monthly volume. bytes per day=viewer-seconds×average bits per second÷8 then multiply by 30 days. Dividing by 8 turns bits into bytes.
- Average and peak bandwidth. average bits per second=86,400bytes per day×8 and the peak is the average times the peak-to-average ratio (how much busier the busiest hour is than the mean hour), which comes from an assumed hour-by-hour viewing profile.
- CDN implications. Origin load is (1−cache hit ratio) times the total, where the hit ratio is the share of bytes an edge server hands out without going back to the origin. Edge server count is peak bandwidth divided by the usable output of one server.
Assumptions
| Input | Value | Plausible range |
|---|---|---|
| Daily viewers | 5 million | given |
| Viewing per viewer | 1 hour a day | given |
| Delivered bitrate, SD (480p) | 1.5 Mbps | 0.7 to 2.5 |
| Delivered bitrate, HD (1080p) | 5 Mbps | 3 to 8 |
| Delivered bitrate, UHD (4K) | 15 Mbps | 10 to 25 |
| Viewing-time mix SD / HD / UHD, base | 30% / 55% / 15% | varies by audience and devices |
| Evening profile | 24 relative weights, one per clock hour (listed below), busiest hour about 11% of the day | the shape is the assumption; flat would be 4.2% |
| Edge cache hit ratio | 95% | 85% to 99% |
| One edge server, usable output | 40 Gbps, run at 50% at peak (headroom for failures, bursts inside the hour and uneven load) | 10 to 100 Gbps |
Units are decimal: 1 PB (petabyte) is 1015 bytes or one million GB, and 1 Tbps is 1012 bits per second. The model counts delivered video bytes and ignores audio, retransmissions (packets sent again after being lost) and players that buffer ahead of playback (download several seconds beyond the current position).
The bitrate comes from a ladder of quality levels, called rungs, that the player can pick from; the top rung is the highest quality offered. A codec is the method that compresses the video into those bits, and an encoder is the program that applies it, so a more efficient codec delivers the same picture at a lower rung bitrate.
The evening profile, step by step. The 24 weights, from midnight onward, are 1, 1, 1, 1, 1, 1, 1.5, 2, 2, 2, 2, 2.5, 3, 3, 3, 3.5, 4, 5, 6.5, 8, 9, 9, 7, 3. They add up to 82. The busiest hours (20:00 and 21:00, weight 9) therefore carry 9/82=11.0 percent of the day's viewing, against 1/24=4.2 percent if viewing were flat, and the peak-to-average ratio is 9×24/82=2.63.
Worked example, computed by a program
The program evaluates three bitrate mixes, applies the evening profile, derives the CDN figures for the base mix, and cross-checks the base mix by summing tier by tier and hour by hour.
import math
viewers = 5_000_000 # given: daily viewers
hours_each = 1.0 # given: about an hour of viewing per viewer per day
days = 30 # assumption: days per month
# Assumed delivered bitrates in megabits per second (range given), and shares of VIEWING TIME
rates = {"SD (480p)": 1.5, "HD (1080p)": 5.0, "UHD (4K)": 15.0} # ranges: 0.7-2.5, 3-8, 10-25
mixes = {
"mobile-heavy": (0.60, 0.38, 0.02),
"base": (0.30, 0.55, 0.15),
"premium": (0.15, 0.55, 0.30),
}
# Assumed share of a day's viewing that falls in each clock hour, as relative weights (evening bump)
weights = [1, 1, 1, 1, 1, 1, 1.5, 2, 2, 2, 2, 2.5, 3, 3, 3, 3.5, 4, 5, 6.5, 8, 9, 9, 7, 3]
hour_share = [w / sum(weights) for w in weights]
peak_to_avg = max(hour_share) * 24
hit_ratio = 0.95 # assumption: share of bytes served from CDN edge caches (range 0.85 to 0.99)
edge_gbps = 40 # assumption: usable output of one edge server (range 10 to 100)
edge_util = 0.5 # assumption: run edge servers at 50% of that at peak
viewer_seconds = viewers * hours_each * 3600
def summary(mix):
avg_mbps = sum(s * r for s, r in zip(mix, rates.values()))
daily_bytes = viewer_seconds * avg_mbps * 1e6 / 8
avg_tbps = daily_bytes * 8 / 86_400 / 1e12
return avg_mbps, daily_bytes, avg_tbps
print(f"peak hour carries {max(hour_share):.1%} of the day; peak-to-average = {peak_to_avg:.2f}")
print(f"{'mix':<14}{'avg Mbps':>9}{'PB/day':>8}{'PB/month':>10}{'avg Tbps':>10}{'peak Tbps':>11}")
for name, mix in mixes.items():
a, d, t = summary(mix)
print(f"{name:<14}{a:>9.2f}{d/1e15:>8.2f}{d*days/1e15:>10.1f}{t:>10.2f}{t*peak_to_avg:>11.2f}")
a, d, t = summary(mixes["base"])
peak_tbps = t * peak_to_avg
peak_concurrent = viewers * hours_each * max(hour_share) * 1.0 # viewers watching in the peak hour (1 hour each)
print(f"base: concurrent viewers at peak hour ~ {peak_concurrent:,.0f}; peak {peak_tbps:.2f} Tbps")
print(f"base: monthly egress {d*days/1e15:.1f} PB = {d*days/1e9/1e6:.1f} million GB (decimal, 1 PB = 1 million GB)")
origin_tbps = peak_tbps * (1 - hit_ratio)
edge_servers = math.ceil(peak_tbps * 1000 / (edge_gbps * edge_util))
print(f"origin load at {hit_ratio:.0%} hit ratio: peak {origin_tbps*1000:.0f} Gbps, month {d*days*(1-hit_ratio)/1e15:.1f} PB")
print(f"edge servers at {edge_gbps} Gbps x {edge_util:.0%} utilisation: {edge_servers}")
print(f"each 0.01 USD per GB of delivery price = {d*days/1e9*0.01/1e6:.2f} million USD per month")
# Independent recomputation: tier-by-tier viewer-seconds, and hour-by-hour bandwidth integrated over the day
mix = mixes["base"]
tier_bytes = sum(viewer_seconds * share * r * 1e6 / 8 for share, r in zip(mix, rates.values()))
hourly_bytes = sum((d * s) for s in hour_share) # each hour's bytes = day total x its share
hourly_bps = [d * 8 * s / 3600 for s in hour_share]
ok = (abs(tier_bytes - d) / d < 1e-12 and abs(hourly_bytes - d) / d < 1e-12
and abs(max(hourly_bps) / 1e12 - peak_tbps) < 1e-9)
print("check (per-tier sum, hour-by-hour integral):", "PASS" if ok else "FAIL")
Output:
peak hour carries 11.0% of the day; peak-to-average = 2.63
mix avg Mbps PB/day PB/month avg Tbps peak Tbps
mobile-heavy 3.10 6.97 209.2 0.65 1.70
base 5.45 12.26 367.9 1.14 2.99
premium 7.47 16.82 504.6 1.56 4.10
base: concurrent viewers at peak hour ~ 548,780; peak 2.99 Tbps
base: monthly egress 367.9 PB = 367.9 million GB (decimal, 1 PB = 1 million GB)
origin load at 95% hit ratio: peak 150 Gbps, month 18.4 PB
edge servers at 40 Gbps x 50% utilisation: 150
each 0.01 USD per GB of delivery price = 3.68 million USD per month
check (per-tier sum, hour-by-hour integral): PASS
Hand check of the base row: 0.30×1.5+0.55×5+0.15×15=0.45+2.75+2.25=5.45 Mbps. One viewer-hour is 5.45×106×3600/8=2.4525×109 bytes, about 2.45 GB. Times 5 million viewers is 12.26 PB per day, and times 30 days is 367.9 PB per month.
How the bitrate mix and the evening peak change the answer
- Bitrate mix moves volume. Mobile-heavy (60% SD) gives 3.10 Mbps average and 209.2 PB per month; premium (30% UHD) gives 7.47 Mbps and 504.6 PB. That is 0.57 and 1.37 times the base, a range of more than 2 to 1 from the mix alone, and UHD viewers are the most expensive per hour: 15 Mbps is 10 times SD for the same hour watched.
- The evening profile moves the peak, not the volume. The volume per month is identical whatever the clock-hour shape. The base mix averages 1.14 Tbps over the day, but the assumed profile puts about 11.0 percent of viewing in the busiest hour, 2.63 times an average hour, so the peak is 2.99 Tbps and about 548,780 viewers are watching during that hour (the concurrent viewers at peak, found as 5,000,000×9/82 because each viewer watches one hour). A flat day would peak at 1.14 Tbps; the profile alone raises the peak to 2.6 times that.
- Peak across mixes. 1.70 Tbps (mobile-heavy) up to 4.10 Tbps (premium). The busiest hour's average is used here, and the instantaneous peak inside that hour is somewhat higher.
What the egress figure implies for a CDN
- Origin cannot serve this directly. A peak of 2.99 Tbps is far beyond one site's network, so a CDN is needed.
- Hit ratio sets the origin load. At 95 percent, the origin supplies 150 Gbps at peak and 18.4 PB per month. At 90 percent it would be 0.10×2.99 Tbps≈299 Gbps, double. The long tail of rarely watched titles is where hit ratio is lost.
- Edge capacity is set by the peak. 2.99 Tbps = 2,990 Gbps, divided by 20 Gbps (40 Gbps at 50 percent utilisation) gives 150 edge servers across all locations, and the load is not spread evenly across the world.
- Cost follows volume. Delivery is usually priced per GB, and the price is a negotiated assumption, so state the formula: each 0.01 USD per GB is 367.9 million GB×0.01=3.68 million USD per month. A 10 percent cut in average bitrate (a more efficient codec, or a lower top rung) cuts that by 10 percent.
- Peak and volume are billed differently. A capacity commitment (a contract for a fixed amount of bandwidth you pay for whether or not you fill it) follows the peak, 2.99 Tbps here, while a usage bill follows the volume, 367.9 PB. Two services with the same monthly volume but a flat day and an evening-heavy day would need about 1.14 and 2.99 Tbps of committed capacity, so the flatter day is cheaper at the same volume.
The judgment
Plan on the base case of about 2.5 GB per viewer-hour, 368 PB per month and a peak near 3 Tbps, and serve it from a CDN with a 95 percent hit target. Measure the two drivers separately, because they set different things: the bitrate mix sets the volume and therefore the bill (209 to 505 PB a month across the three mixes, more than 2 to 1), and the evening shape sets the capacity (a peak 2.63 times the average hour).
What would change the plan: a hit ratio near 85 percent, which triples the origin load from 150 Gbps to 449 Gbps (0.15 times 2.99 Tbps) and calls for a much larger origin and network commitment; or a more concentrated evening, since the edge server count rises in proportion to the peak-to-average ratio (a profile with a ratio of 4 instead of 2.63 would need about 228 edge servers instead of 150).
Common mistakes
- Forgetting to divide bits by 8 (a 5 Mbps stream is 0.625 MB per second).
- Multiplying the average bandwidth by 24 hours and 30 days without converting to bytes, or mixing Tbps and TB.
- Using a single bitrate ("1080p") instead of a mix, or weighting the mix by viewers instead of by viewing time.
- Presenting the peak as the average, or the monthly volume as if it set the capacity needed.
- Ignoring the hit ratio, so the origin appears to need terabits per second.
Running the code
Python 3.12, standard library only.
python video_egress_sizing.py
Unlock Full Question Bank
Get access to all 15 Estimation and Capacity Sizing interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.