CDN¶
Latency between California and China can be 3-4 seconds.
Considerations of using CDN¶
- Cost. Caching infrequently used assets provides no significant benefits
- Setting an appropriate cache expiry
- CDN fallback
- Invalidating files
- Invalidate the CDN object using APIs provided by CDN vendors
- Use object versioning - image.png?v=2.
Approaches to implement CDN¶
- Push CDN
- Origin server must save content in CDN
- ⛔ more engineering work for the developers to make sure that CDN assets are up to date
- Pull CDN
- CDN caches content in demand when users request it.
- ✅ much easier to maintain
- ⛔ if the CDN already have your asset cached, CDN won’t know if you decide to update it or not, and to fetch this updated asset
- to minimise this problem CDN usually supports caching time using for example Cache Control headers. Origin server should return in response Cache Control .
- ⛔ the first request to a Pull CDN will always take a while since it has to make a trip to the origin server.
CDN solutions¶
- Cloudflare CDN
- AWS Cloudfront
- GCP Cloud CDN
- Azure CDN
- Oracle CDN
When you shouldn't use CDN¶
- when your service’s target users are in a specific region
- when the assets being served are dynamic and sensitive. For example financial/government services