Course contentsShow
← System Design
Lesson 1621 of 1,91939. Real-World System: Image and Video HostingFree lesson

Compression and Format Optimization

Reduce storage and bandwidth costs through modern codecs, adaptive formats, and quality-based compression strategies.

Compression and Format Optimization

What you'll learn: How to drastically reduce storage and bandwidth costs by choosing modern codecs, serving adaptive formats, and applying quality-based compression.

Why Compression Matters

Imagine shipping a bookshelf: you could send it fully assembled (huge box, expensive shipping) or flat-packed (small box, cheap shipping, same final result). Compression does the same for images and videos—reducing file size without destroying quality.

For a media hosting system serving millions of files daily, compression directly impacts:

  • Storage costs (GBs stored × time)
  • Bandwidth costs (GBs transferred × price per GB)
  • User experience (faster load times, less buffering)

Core Strategies

Modern Codecs:
Replace outdated formats with efficient alternatives:

  • Images: Serve WebP or AVIF instead of JPEG (30–50% smaller)
  • Video: Use H.265 (HEVC) or AV1 instead of H.264 (up to 50% smaller at same quality)

Quality-Based Compression:
Apply different compression levels based on use case:

  • Thumbnails: aggressive compression (lower quality acceptable)
  • Full-resolution originals: light compression (preserve detail)
  • Video previews: heavier compression than main stream

Adaptive Format Serving:
Detect client capabilities and serve the best format:

If browser supports AVIF → serve .avif
Else if supports WebP → serve .webp
Else → serve .jpg (fallback)

Dimension Optimization:
Never serve a 4K image to a 400px thumbnail slot—resize during processing and store multiple variants.

The ROI

A system storing 10 PB of video could save 5 PB (millions of dollars) by switching from H.264 to AV1, while bandwidth costs drop proportionally.

Key Takeaway:
Modern codecs, quality-aware compression, and adaptive format delivery cut storage and bandwidth costs in half while maintaining perceived quality—a fundamental optimization for any media hosting system.