Cost-aware design
Read first: Back-of-the-envelope estimation, Caching
Bytes stored grow with replication factor and retention. Three replicas kept for 30 days is 90 times one day of ingest, and that identity is the storage bill before anyone mentions a price. Egress grows with bytes you send, a cache cuts the origin's share of those sends, and an idle spare is the capacity you keep so a failure does not become your latency.
The bill is three multipliers you can write down before you know a single price. How many copies, how long you keep them, and how many times you send the byte out. A design review that jumps to a vendor calculator without those multipliers is guessing with extra steps. Leave the currency out. If the design is wrong in units of “days of ingest,” a price will not rescue it.
Core concepts
Stored bytes grow with replication and retention. One day of ingest is D bytes, whatever you measured or assumed. A replication factor of R means you keep R copies for durability or for read scale. A retention of T days means you do not delete until then. The product is the storage:
stored = R × T × D
Three replicas kept for 30 days is 90 times one day of ingest. Ninety, not thirty. The extra sixty days-of-ingest are the second and third copies. Add a replica and the multiplier becomes 120. Cut retention to a week and three replicas become 21 days of ingest. You argue about R and T because they are linear in the bytes. You do not need a price to see that a casual “keep it just in case” at three replicas is a 90× decision.
Each copy should have a job. A replica that can take reads or can replace a failed disk is durability or latency, and you are paying the bytes on purpose. A copy with no reader and no failover role is the one to delete. Replication is where you decide whether a copy is synchronous, asynchronous, and what you lose on failover. This page only insists that you count it.
Egress grows with bytes you send, not with bytes you store. The same D sent to a hundred readers is on the order of 100 × D leaving the building, while the disk still holds R × T × D. Rereads are how egress overtakes storage. Cross-region reads are egress with a latency attached: the byte crosses the fiber, and you pay the transfer because you did not keep a copy, or a cache, near the reader.
A cache in front of the origin cuts origin bytes. It does not shrink the 90× on disk. Caching still has the old rules. A hit is a byte the origin does not send again. A miss, a bypass, or a key so specific that nothing ever hits, and the origin sends the object as if the cache were not there. Invalidation is how you get correctness. TTL bounds staleness when invalidation fails. A purge is eventual. If you put a cache on a path that cannot be stale, you have chosen a correctness bug to save egress. Sometimes the byte is immutable and the choice is easy. Sometimes it is a policy page and the choice is wrong.
Idle capacity is the cost of a low-latency spare. A second process, a second device, a hot replica that serves nothing on a quiet day: you keep it so a failure or a peak does not become a queue. Scale-to-zero removes that idle and puts a cold start on the next caller. If the latency budget is tighter than the cold start, the spare is the design, not waste. If the peak is a once-a-night batch, a queue and a smaller fleet may replace a fleet sized to the spike. The spare is optional only when the caller can wait.
Back-of-the-envelope estimation is the habit. Write the product, label every assumption, and stop before inventing a dollar figure. A price you do not have is not a more serious version of 90 × D. It is a fiction stapled to a real multiplier.
flowchart LR
day[One day of ingest] --> replicas[Three replicas]
replicas --> month[Thirty days stored]
reader[Repeated reader] --> cache[Cache]
cache --> origin[Origin bytes]
The top path is storage, and it multiplies even when nobody reads. The bottom path is egress, and it multiplies when the same byte leaves over and over. A cache sits only on the bottom path.
A worked example
You store request logs, including agent tool traces, and analysts re-read them. You will not price the design. You will show which multiplier dominates.
Assumptions:
- One day of ingest is
D. When a concrete size helps,Dis 200 GB. That size is an assumption about your logs, not a measurement of a public system. - You keep 3 replicas for 30 days, because you want to survive a disk loss and you want a month of eval history. Both reasons should be stated, or the 3 and the 30 are decoration.
- Fifteen analyst jobs re-read a full day of logs every day. Fifteen is an assumption about your eval fleet. The shape matters more than the 15: rereads, not a single pass.
- Peak request rate on the live path is 5 times the average. Peak factor is an assumption in the usual 2× to 5× planning range. You are at the top of that range on purpose, so the idle fraction is visible.
1 day = 86,400 s
30 × 86,400 = 2,592,000 s ≈ 2.6 × 10^6 s
a 30-day month and "about 2.6 million seconds" are the same planning band
stored = 3 replicas × 30 days × D = 90 × D
assumption: D = 200 GB
stored = 90 × 200 GB = 18,000 GB
Stop there on storage. Eighteen thousand gigabytes is still just ninety days of ingest under a 200 GB assumption. It is not a bill. If someone quotes you a price per gigabyte, multiply it outside this design, and do not bake it into the diagram. Change the design by changing 3, 30, or D. Cutting log fields cuts D. Dropping a replica you cannot justify cuts the 90 to 60. Shortening retention to 10 days at 3 replicas is 3 × 10 = 30 days of ingest, one third of the bytes, and you can no longer answer a question about day 11.
Egress is a different product. Fifteen jobs each pull the full day from the origin:
assumption: 15 full rereads of D per day, no cache
origin egress per day = 15 × D
over 30 days = 450 × D
stored over the same month = 90 × D
egress / stored = 450 / 90 = 5
You send five times as many bytes as you keep, under that assumption, because the month of rereads is 15 times 30, and the replicas are only 3. Storage is the 90. Egress is the 450. A conversation that only argues about disk will miss the larger term.
Put a cache in front of the origin, shared by those jobs. The first job of the day misses and pulls D. The other fourteen hit.
assumption: 14 of 15 rereads hit, 1 misses
origin egress per day = 1 × D
over 30 days = 30 × D
versus 450 × D with no cache
the origin sends one fifteenth of the reread bytes
the disks still hold 90 × D
The cache cut origin bytes. It did not cut the replicas. If the hit assumption is wrong, the egress number is wrong with it. Measure the hit rate. A cache key that includes a unique job id never hits, and you are back to 450 × D plus the cost of a cache that only stores misses. A TTL that serves yesterday’s log as today’s is the correctness side of the same machine. For immutable log objects named by date, a long TTL is honest. For “the latest policy,” it is not.
Idle spare, same logs, different resource. The live ingest path is sized for the peak.
assumption: peak is 5× the average arrival rate
capacity sized to the peak
average utilization = 1 / 5 = 0.2
the other 0.8 of that capacity is idle at the average
Little’s law still sits under this. If you provision only for the average, a peak of five times the arrival rate either queues or sheds. Queue time becomes latency. The idle 0.8 is what you bought so the peak fits without that queue. It is waste only if the peak is not real. If the 5× is a nightly batch that can finish later, do not buy a fleet for it. Put the batch on a queue and keep the live fleet near the interactive peak, which might be 2×. State the new assumption and recompute. Going from 5× to 2× is the difference between utilization 0.2 and utilization 0.5 on a fleet now sized to the smaller peak. You gave up “the nightly job finishes inside the minute” and you kept the interactive path.
A hot spare for failover is the extreme, utilization zero on that spare until something dies. One extra unit of whatever the busy one is, for as long as you keep it. No price required. The sentence is: we run two so one can die without the remaining one taking a cold start or a double load it cannot meet. If you cannot say what failure the spare absorbs, you are storing idle capacity with no job, the same mistake as a fourth replica nobody reads.
Agent traces make D grow in a way that is easy to miss. A tool that appends a full page of observation into the log, on every step, multiplies D by the steps and by the observation size. The 90× then applies to that larger day. Cap what you persist. The cap is a storage decision and an egress decision, because the eval jobs will reread whatever you kept.
Tradeoffs
| Choice | What you gain | What you spend |
|---|---|---|
| 3 replicas for 30 days | A lost disk is survivable, and a month of history remains | 90 times one day of ingest, before you add old versions |
| Shorter retention | A smaller multiple of D | You cannot answer a question older than the new window |
| Fewer replicas | Linear drop in stored bytes | Less durability, or less read scale, name which |
| Cache in front of the origin | Origin sends misses instead of every reread | Staleness, a purge that is eventual, a hit rate you must measure |
| Idle spare sized to the peak | The peak fits, failover can be warm | Capacity that sits quiet at the average |
| Queue the spike instead | A smaller steady fleet | The spike finishes later |
| Scale the spare to zero | Nothing idle between bursts | A cold start on the next caller, bad if the budget is tight |
| Log less per event | D itself shrinks, and every multiple shrinks with it | You cannot debug what you refused to keep |
Do not “save money” by dropping the replica that failover needs and then calling the outage a networking incident. Do not keep ninety days of ingest in a fourth copy because a dashboard was easier to point at the raw files than at a downsampled set. Downsampling is a retention policy: you keep full fidelity for a short T and a summary for a long one, and you write both multipliers down.
Pitfalls
- Quoting a dollar figure you do not have. It looks more serious than
90 × Dand it is less honest. Keep the multipliers. Apply a price later, outside the design, when you actually have one. - Counting one day of ingest as the storage footprint. Forgetting replicas and retention understates the bytes by the factor you most needed to see. Three for thirty days is ninety, not one.
- A cache that does not change the origin’s byte count. The key includes a unique id, nothing hits, and egress stays at the full reread multiple. You added a tier and kept the bill.
- Caching a byte that is not allowed to be stale, then acting surprised when a purge arrives late. Egress was the goal. Correctness was the constraint. The constraint wins on that path.
- An idle spare with no failure to absorb and no peak to cover. It is a replica with no job. Name the failover or delete it.
- Sizing the whole fleet to a nightly batch that could have queued. You buy 5× capacity so a job that nobody is waiting on finishes at the speed of the interactive peak.
- Cross-region rereads as a hidden multiplier. Each miss pulls
Dacross the long path. A cache or a closer copy removes both the latency and the repeated transfer. - Persisting every tool observation in full, then keeping three replicas for a month. You multiplied a sloppy
Dby 90, and the eval jobs will ship thatDout again on every reread.
In the interview
Write 3 × 30 = 90 before you name a store. Say “ninety times one day of ingest” and stop before a price. Then split storage from egress. Storage is replicas times retention times D. Egress is how many times those bytes leave, and a cache cuts the origin’s share if the hit rate is real. Then the spare: idle capacity is what you pay so the peak or the failover stays inside the latency you promised. Give one utilization number from a peak factor you state as an assumption.
Skip the price list, the vendor comparison, and any cost figure you did not derive from D. If the interviewer hands you a price, multiply it by the 90 and by the egress factor in your head, and still talk in those factors so the price can change without rewriting the design.
The question that usually follows is “what does the cache actually change” or “why not turn the spare off.” The cache changes origin sends, not replica bytes, and only when the key hits. The spare turns off only if the remaining capacity meets the peak you claimed, or if you moved that peak onto a queue and accepted the delay.
Check yourself
You keep 3 replicas for 30 days. In units of one day of ingest, how much do you store, and what is that number not?
Three times 30 is 90. You store 90 times one day of ingest. That number is not a price, and it is not 30. The second and third replicas are 60 of the 90. Dropping retention to 10 days at the same replication factor stores 30 times one day of ingest. A day of wall clock is 86,400 seconds, and 30 of those days are about 2.6 million seconds, which is why a 30-day retention and a calendar month are the same planning band.
Fifteen jobs reread the full day from the origin with no cache. Over 30 days, how does egress compare with 90 days of ingest stored? State the assumption.
Each day sends 15 times D, and 30 days send 450 times D, assuming every job pulls a full day from the origin and nothing hits a cache. Storage is 90 times D. Egress is five times the stored bytes over that month, 450 divided by 90, under those assumptions. A cache that serves 14 of the 15 rereads drops origin egress to 30 times D over the month and leaves the 90 on disk untouched.
Why does a cache in front of the origin not shrink the 90 times D on disk?
The 90 is replicas times retention of the bytes you chose to keep. Hits avoid sending those bytes again. They do not delete a replica. A design that needs less disk has to lower D, the replication factor, or the retention. A design that needs less origin egress has to raise the hit rate or stop rereading.
You size capacity to a peak that is 5 times the average. What fraction sits idle at the average, and when is that idle not waste?
Average utilization is 1 divided by 5, so 0.2, and 0.8 of the capacity is idle when traffic sits at the average. That idle is the spare that lets the peak arrive without a queue. It is not waste if the peak is real and the caller cannot wait. It is waste if the 5 times was a batch you could have queued, or a second copy that no failover plan uses. State the peak as an assumption before you defend the spare.
A popular object expires at 20 edge caches at the same moment, with no origin shield. What happens to origin egress for that object, and what did you assume?
Each edge miss pulls the object from the origin, so one expiry becomes 20 transfers, assuming all 20 miss and each fetches on its own. An origin shield is a tier those edges can miss into, and the origin sends the object once into the shield instead of once per edge. The disks that store replicas are unchanged. The fan-in of the miss is what you cut.
Based on: Replication factor and retention; CDN caches and origin shield; Little's law.