Sub topic 16
Cost and design trade-offs
This chapter assumes you know the pipeline from earlier chapters: transcoding, a bitrate ladder, HLS packaging, object storage and CDN delivery. Here we ask where the money goes and which design choices move it.
Where the cost comes from
For an on-demand platform, three line items dominate.
- Egress (data sent to viewers). This is usually the largest cost. It scales with hours watched times bitrate, not with catalog size.
- Transcoding compute. It is paid once per upload per rendition, so it scales with new content. It grows with the number of ladder rungs and with codec complexity.
- Storage. Every rendition is stored, plus the source file. It grows with catalog size and never shrinks unless you delete.
A quick check shows why egress wins. A 3 Mbps stream uses about 1.35 GB per hour. At 1 million viewing hours per day, that is about 1.35 PB per day delivered. Even at a low CDN rate, this exceeds the storage and compute bills combined.
def daily_egress_tb(viewing_hours, avg_bitrate_mbps):
"""Terabytes delivered per day at a given average bitrate."""
gb_per_hour = avg_bitrate_mbps * 3600 / 8 / 1000
return viewing_hours * gb_per_hour / 1000
print(round(daily_egress_tb(1_000_000, 3.0))) # 1350The main levers
Each lever trades cost against quality, latency or reliability.
| Lever | Saves | Costs you |
|---|---|---|
| Fewer ladder rungs | Transcode time and storage | Coarser quality steps, more rebuffering risk |
| Lower top bitrate | Egress | Visible quality loss on large screens |
| Newer codec (HEVC, AV1) | Egress, often 30% or more at equal quality | Slower encodes, patent or licensing issues, devices that cannot decode it |
| Higher CDN cache hit ratio | Origin load and origin egress | Longer cache lifetimes, more careful cache keys |
| Longer segments | Fewer requests and playlist updates | Slower quality switching, higher live latency |
| Storage tiering | Storage | Slower first access to cold titles |
Spend effort where views are
Viewing follows a long tail. A small share of titles gets most of the views. Use that.
- Encode popular titles with an expensive preset and extra codecs. Each saved bit is multiplied by many views.
- Encode rarely watched titles with a cheap preset and a short ladder. Add richer renditions later if views grow.
- Move titles with no recent views to a colder storage tier. Keep the playlists and first segments warm if start time matters.
This is called per-title or popularity-aware encoding. It adds a decision step to the pipeline, but it targets the most expensive resource.
Design trade-offs beyond cost
Some pairs conflict directly.
- Latency against efficiency. Short segments cut live delay and speed up switching, but they add requests, and fixed keyframe spacing gets harder on compression.
- Reliability against cost. A second CDN protects you from one provider's outage and gives pricing leverage. It also adds routing logic and splits your cache, which lowers hit ratio.
- Quality against compatibility. AV1 saves bandwidth, but you still need an H.264 fallback for older devices. Two codec ladders double storage and encode work.
A decision order
- Estimate egress from expected viewing hours and average bitrate.
- Pick the ladder and codec that meet your quality target at the lowest egress.
- Add popularity-aware encoding and storage tiers.
- Tune CDN caching and consider a second provider only if your reliability target needs it.
Exercise
A platform streams 200,000 hours per day at an average of 4 Mbps. A new codec cuts the average bitrate by 30% at equal quality, but only 60% of viewers have devices that can play it. Roughly how many terabytes per day does this save? (Use 1 Mbps = 0.45 GB per hour.)
Show answer
Current egress is 200,000 × 4 × 0.45 = 360,000 GB, or 360 TB per day. Viewers on the new codec are 60% of traffic, which is 216 TB. A 30% cut on that saves about 64.8 TB per day. The remaining 40% stay on the old codec, so the platform still stores and serves both ladders.