Amazon CloudFront
medium 25 minCloudFront is the content delivery network of AWS.
See it run
Match a behavior, fall through three caches, run functions at the right event, invalidate, and lose an origin.
Operations
Three cache layers
Two continents ask for one object. S3 sends it once.
Step 1 of 6
Dublin misses
Edge miss
A viewer in Ireland asks. The edge has no copy.
Step 1: Dublin misses
edge: copy?regional edge cache: copy?Origin Shield: copy?fetch from S3, store everywhere- When
- First requests
- You leave with
- Three warm layers
Multiply the miss ratios of the layers. The product is what your origin must survive.
In the real world
The same amazon cloudfront doing real jobs. Pick one and step through it.
A 12 GB game patch is released at noon.
Step 1 of 3
11:50, warm up
Warm shield
The team requests the first parts in each region, so the shield already holds them.
Step 1: 11:50, warm up
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Broad pattern first
majorThe first match wins, so later narrow patterns never run.
Wrong0: /*1: /api/*Right0: /api/*1: /static/*last: *Everything in the cache key
majorCookies and User-Agent give each person a private copy of a public file.
Wrongkey: path + all cookies + all headersRightkey: path + the two query values usedAuth on origin request
criticalA hit skips origin events, so cached private content goes out unchecked.
Wrongorigin-request: verify(token)Rightviewer-request: verify(token)Default timeouts with failover
majorThree attempts of ten seconds mean a 30-second wait before the secondary is tried.
Wrongattempts = 3, timeout = 10Rightattempts = 2, timeout = 2then test it
Interview tips
How to explain it
- Behaviors choose, layers answer.
- Edge, region, shield, origin.
- Functions by event.
Calculate
- Product of miss ratios.
- Attempts times timeout.
- Paths invalidated a month.
Reach for it when
- Origins are in AWS.
- Buckets must be private.
- Site and API share a domain.
Watch
- Hit ratio per behavior.
- Minimum TTL on personal pages.
- us-east-1 for certificates and Lambda@Edge.
- Configuration deploy time.