Sub topic 16
Cost and design trade-offs
This chapter assumes you have read the earlier chapters on capacity estimation, the bitrate ladder, segmentation and CDN delivery. It also assumes you can read short Python. You will build a small cost model, see which parts of a streaming platform cost the most, and learn how each design choice trades quality, latency, reliability and money against each other.
Where the money goes
An on-demand platform has four main costs:
- Delivery. Bytes sent to viewers through a CDN (content delivery network), plus bytes the CDN pulls from your origin on cache misses.
- Storage. The source files and every rendition (one encoded version of the video at a given resolution and bitrate) of every title.
- Compute. Transcoding each upload into the ladder, usually the largest one-time cost per title.
- Everything else. Metadata databases, search, recommendations, DRM licenses and monitoring.
Delivery grows with every minute watched. Storage and transcoding grow with the catalog. For a popular library, delivery usually dominates. For a large library that few people watch, storage and transcoding can dominate instead. You can only tell which case you are in by running numbers.
A small cost model
The model below turns the usage assumptions from the capacity chapter into a monthly bill. The prices are illustrative, not quotes. Replace them with your provider's rates.
def egress_gb(hours_watched, avg_bitrate_bps):
"""Gigabytes delivered for a number of hours watched."""
return hours_watched * 3600 * avg_bitrate_bps / 8 / 1e9
def monthly_cost(
hours_per_day,
avg_bitrate_bps,
hit_ratio,
library_hours,
new_hours_per_day,
ladder_bps,
cdn_per_gb=0.02,
origin_per_gb=0.01,
storage_per_gb_month=0.023,
transcode_per_rendition_hour=0.30,
days=30,
):
delivered = egress_gb(hours_per_day, avg_bitrate_bps) * days
origin_fetched = delivered * (1 - hit_ratio)
# Storage for one hour of content across all renditions.
gb_per_content_hour = egress_gb(1, sum(ladder_bps))
stored = library_hours * gb_per_content_hour
transcoded_hours = new_hours_per_day * days * len(ladder_bps)
costs = {
"cdn": delivered * cdn_per_gb,
"origin": origin_fetched * origin_per_gb,
"storage": stored * storage_per_gb_month,
"transcode": transcoded_hours * transcode_per_rendition_hour,
}
costs["total"] = sum(costs.values())
return costs
ladder = [800_000, 3_000_000, 6_000_000]
result = monthly_cost(
hours_per_day=100_000,
avg_bitrate_bps=2_500_000,
hit_ratio=0.95,
library_hours=200_000,
new_hours_per_day=1_000,
ladder_bps=ladder,
)
for name, value in result.items():
print(f"{name}: {value:,.2f}")Running it prints:
cdn: 67,500.00
origin: 1,687.50
storage: 20,286.00
transcode: 27,000.00
total: 116,473.50The model uses the average delivered bitrate (2.5 Mbps), not the top rung of the ladder. Most viewers do not sit on the 1080p rendition all the time, and using the top bitrate would overstate delivery cost.
Reading the model
Delivery takes about 58% of the total in this example. Two inputs move it most:
- Average bitrate. Cutting the average from 2.5 to 2.25 Mbps cuts delivery cost by 10%, because egress is proportional to bitrate.
- Hit ratio. This is the fraction of requests the CDN answers from cache. It affects origin cost, but it also affects latency and origin load, which the bill does not show.
Storage grows with the sum of the ladder, not with its top rung. Each extra rendition adds its full size to every title. Transcoding cost grows with the number of renditions too. A rung that few viewers use still costs storage and compute for every title.
Quality, latency, reliability and cost
Every major decision moves at least two of these four. The table lists the common ones.
| Decision | Improves | Costs |
|---|---|---|
| Add more ladder rungs | Smoother quality switching, better fit to each network | Storage and transcoding grow with every rung |
| Use a newer codec (HEVC, AV1) | Same quality at lower bitrate, so less egress | Much slower encoding, uneven device support, possible licensing |
| Longer segments (6 to 10 s) | Fewer requests, better compression, less manifest overhead | Slower quality switches, longer startup, higher live latency |
| Shorter segments (2 to 4 s) | Faster adaptation, lower live latency | More requests, more cache entries, slightly worse compression |
| Higher cache hit ratio | Lower origin cost, faster starts | Needs a longer TTL, a tiered cache or pre-warming |
| Multiple CDNs | Resilience and price leverage | Operational complexity, split cache that can lower hit ratio |
| Encode everything up front | Instant playback for any title | Pays to encode titles nobody watches |
Encode up front or on demand
Most catalogs follow a long-tail pattern. A small share of titles gets most of the views, and the rest are rarely played. You have two options:
- Full ladder for every title. Simple and fast to play. You pay for renditions that may never be requested.
- A short ladder first, more rungs when a title becomes popular. Cheaper for the tail. The pipeline needs a trigger, such as a view-count threshold, and a way to update the manifest safely.
A common compromise encodes the lower rungs for every title and adds the top rungs only for titles that cross a view threshold. Storage and compute shrink for the tail, but viewers on fast networks get lower quality on unpopular titles until the extra rungs exist.
Per-title encoding
A fixed ladder uses the same bitrates for every video. A cartoon looks fine at a lower bitrate than a football match. Per-title encoding analyzes each video and picks bitrates to match its complexity. It spends extra compute at encode time to save egress on every later view. It pays off when a title is watched often. For a title watched twice, the analysis costs more than it saves.
Delivery trade-offs
Cache hit ratio and tiering
A single-tier CDN sends every edge miss to your origin. Adding a mid-tier (regional) cache means that a segment requested from ten edges is fetched from the origin once, not ten times. That raises the effective hit ratio and lowers origin egress. The price is one more network hop on a miss, and a small extra fee at some providers.
Long TTLs help here. Segments are immutable once published, so they can carry a long Cache-Control max-age. Playlists for on-demand content can also be cached for a long time. Playlists for live streams change every few seconds and need short TTLs.
Multi-CDN
Using two or more CDNs protects you from a single provider's outage and lets you steer traffic to the cheaper or faster one per region. The costs are real:
- Each CDN has its own cache, so the same segment is stored and fetched more than once.
- You need steering logic, often DNS-based or in the player, and you need quality data to drive it.
- Signed URL and token schemes differ between providers.
Reliability costs money
Each reliability measure has a price:
- Replicating source and renditions across regions doubles storage for those objects, but protects against a regional outage.
- Keeping spare transcoding capacity shortens upload-to-publish time during spikes, but idle workers cost money. Queue-based workers on interruptible (spot) instances are cheaper. Transcoding jobs can be retried safely if you make each job idempotent, so losing an instance only wastes a few minutes.
- Origin shielding and failover protects the origin from a miss storm, for example when a new popular episode is released and every edge asks at once.
Decide per component what failure you can tolerate. A delay of ten minutes before a new upload is playable is usually acceptable. A playback failure for a popular title is not. Spend reliability budget on the delivery path before the ingest path.
How to decide
Work through the choices in this order:
- Write down the dominant cost from your model. Usually it is delivery.
- List the inputs that drive it: average bitrate, hours watched, hit ratio.
- Pick the changes that move those inputs, such as a better codec, per-title encoding or a tiered cache.
- Check what each change costs in quality, latency or complexity.
- Re-run the model with the new numbers, then measure real playback quality (rebuffering, startup time) to confirm viewers do not notice.
A cost cut that raises rebuffering is not a saving. It trades a visible bill for invisible churn.
Exercise
Using the example model (100,000 hours watched per day, 30 days, $0.02 per GB at the CDN, $0.01 per GB at the origin, 95% hit ratio), the average delivered bitrate drops from 2.5 Mbps to 2.25 Mbps. How much does the monthly bill fall, ignoring storage and transcoding?
Show answer
Egress falls by 10%, from 3,375,000 GB to 3,037,500 GB. CDN cost falls by 10% of $67,500, which is $6,750. Origin fetches (5% of delivered bytes) fall by 10% of $1,687.50, which is $168.75. The total saving is about $6,918.75 per month.
Exercise
Your platform adds a second CDN and splits traffic evenly. Total delivery rises slightly instead of falling. Give one likely cause visible in origin cost.
Show answer
Each CDN has its own cache, so the same segment is fetched from the origin by both. The effective hit ratio drops and origin egress rises. A mid-tier cache or an origin shield in front of the origin reduces the duplicate fetches.