TSTier SlateAll templates
  1. Home
  2. Templates
  3. Image CDN

Video & media

Image CDN - resize on the fly, or store every size

Why the cache key is the design, and why egress and the long tail of misses set the bill, not CPU.

  • System design
  • starter
  • 11 step walkthrough
  • 5 tables
Own this board 200 creditsPractise as an interview

The first act plays here. Owned once with credits, never a subscription.

Share

  • Facebook
  • X

What this board gets wrong on purpose

The tension

Transforms are computed on demand, so the variant a designer invents on Tuesday exists on Tuesday with no backfill - and every distinct URL is a new cache key, a new AVIF encode at 250 ms of CPU, and a new object to store. The signing service is therefore the only thing between this design and an unbounded bill, which means an availability problem in a tiny stateless service becomes a cost problem in the largest one. Pre-generating instead bounds the spend at 36 variants per master, and buys that bound with storage for the 80 percent of variants nobody ever requests and a re-generation campaign every time the design system changes a breakpoint. The board also admits a third cost neither strategy fixes: 70 percent of distinct URLs are requested once a week, so they miss on arrival, pay full transform price, get cached, and are evicted before a second request ever comes.

Practise this as an interview

Take Image CDN - resize on the fly, or store every size as a timed system design interview on a blank board - on your own, with the requirements to check yourself against, or with a candidate you invite.

Practise this as an interview

Start here

Why this design

An image service is the cleanest test of whether you understand caching economics rather than caching mechanics. Interviewers use it to probe who is allowed to mint a cache key, what happens to the 4% of requests that miss, and whether you notice that egress - not CPU - is the bill. Every team serving user content at scale, from a CDN’s image product to an e-commerce catalogue, lives inside the trade between resizing on the fly and storing every size.

What you will learn

  • Why the cache key is the design: 6 widths x 3 formats x 2 DPRs bounds a master at 36 variants, and free-form parameters turn 3.6 billion keys into 60 trillion.
  • How a 96% edge hit ratio and a coalescing shield leave 830 transforms/s - about 208 busy cores for 1.2% of the traffic - and why a slip to 92% doubles that fleet.
  • Why egress (~$2.0M/year) dwarfs transform CPU (~$73k/year), which makes the 250 ms AVIF encode a bandwidth argument, not a quality one.
  • Why Vary: Accept must be normalised to three values before it touches a key.
  • Why signed, named presets fail closed, and why you version the key instead of purging.
  • Why the long tail - 70% of URLs asked once a week, 64% of transforms - is a cost no cache tuning removes.

How to read this board

  1. Press play once: the walkthrough follows one upload and one request, hop by hop, then the bill.
  2. PUBLISH - ONE MASTER, WRITTEN ONCE (top left): hashed, deduplicated, immutable - and the srcset the app writes.
  3. PRE-GENERATE - THE EAGER HALF (top right): the strategy that is drawn but mostly unused.
  4. REQUEST - EACH HOP IS A SMALLER NUMBER AND A BIGGER PRICE: left to right, negotiation, edge, shield, transform, encoder.
  5. THE BILL - KEYS, PURGES AND THE TAIL: signing, versioning and the telemetry that exposes the tail.
  6. DATA MODEL - WHAT GENERATE SQL READS: variant_specs.pregenerate and variants.last_hit_at settle the eager/lazy argument.
  7. Then pages 1 to 6 in order: requirements, capacity, storage, availability, how it works, deployment.

1 · Requirements

One master image in, the right bytes out for a phone, a laptop and a retina display, in the best format each of them can decode - without the people writing the HTML having to think about any of it.

Functional

  • Store one immutable master per image and serve derived sizes from it.
  • Serve a width-appropriate variant to any device, driven by the srcset the publishing app emits.
  • Negotiate format: AVIF where supported, WebP where not, JPEG as the floor.
  • Support a named set of transforms - crop, fit, quality - and reject anything outside it.
  • Invalidate an edited image everywhere within seconds.
  • Report, per publisher, how much egress and how much transform CPU their images cost.

Non-functional

  • Edge cache hit ratio above 95 percent. This is the top-line metric: everything else on the board is what happens in the 4 percent.
  • p95 latency 30 ms on a hit, 400 ms on a cold transform. A cold AVIF encode is 250 ms of CPU and there is no way around that.
  • Availability 99.99 percent - an image service that is down makes every page on every customer site look broken, which is a worse perception than an outage of the site itself.
  • The number of distinct cache keys must be BOUNDED and countable. An unbounded key space is an unbounded bill.
  • A variant must never be served for the wrong image. Cache-key collisions here are a content-correctness bug that looks like a security incident.

Questions to ask before designing this

  • Who controls the URLs - us, or the customer? If a customer can write any parameter combination they like, the transform fleet is sized by their imagination and not by our traffic.
  • How many distinct widths does the design system ACTUALLY use? Six named breakpoints is a bounded problem; continuous width parameters is an unbounded one, and everybody says six until you measure.
  • What is the edit rate on published images? If images are effectively immutable, version the key and never purge. If they change hourly, the purge path is the hard part of the system.
  • Is there a long tail, and how long? 70 percent of URLs requested once a week means most transforms never amortise and the cache hit ratio flatters you.
  • Do we serve user-uploaded images to the public? Then a decode bomb - a 40,000 by 40,000 pixel PNG that expands to gigabytes in memory - is a denial of service, and limits belong in the requirements rather than in an incident review.
  • Is animation in scope? An animated AVIF is two orders of magnitude more expensive to encode than a still, and it will arrive through the same URL shape.

The rest of this board

Preview of the Image CDN system design board: 16 components joined by 19 connections. The labelled board opens in Tierslate.
Board preview

Available on Tier Slate

This page publishes the question. The answer — 5 more written pages, an 11-step narrated walkthrough and a 5-table schema — is the board itself, and it opens in Tierslate.

  • 5written pages
  • 11walkthrough steps
  • 5tables34 columns

5 pages behind this one

  • Capacity estimation
  • Storage estimation
  • Availability
  • How it works
  • Deployment plan
Open this board in TierslateBrowse every board

Related system design templates

Upload, transcode, deliver - and pay for the bandwidth. 8 more video & media templates:

  • Live streaming system design - Why segment length sets latency, resilience and cost at once, and what each second removed costs.
  • Streaming playback system design - Why streaming is a bandwidth problem, solved by placing the bytes inside the network before anyone asks.
  • Transcoding pipeline system design - Why one number, the size of a segment, sets the cost, latency and failure behaviour of the whole pipeline.
  • Video upload system design - Why a durable receipt for a 500 MB upload and a video that plays everywhere are two separate promises.
  • File upload system design - How presigned URLs send uploads straight to object storage, and what the server still has to check afterwards.
  • Music streaming system design - Why audio is small enough to prefetch, and why play counts and royalties are the hard ledger underneath.
  • Short video feed system design - Why a short-video feed is ranking plus prefetch, and why the first second of video decides retention and cost.
  • Video calls system design - Why a group call forwards streams through an SFU, and how bandwidth estimation keeps a bad link from ruining the call.
Open the Image CDN board in TierslateAll video & media templatesAll 100 system design templates
Tierslate

tierslate.com

HomeTemplatesGuidesCompareAboutUI mockupsPrivacyTerms