Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CDN: Caching and edge computing on AWS

CDN: Caching and edge computing on AWS

Explaining the basis of CDNs and Cloudfront on AWS

Pierre GOUDJO

December 30, 2021
Tweet

More Decks by Pierre GOUDJO

Other Decks in Technology

Transcript

  1. • public: the response may be stored by any cache.

    • private: the response may be stored only by a browser's cache • no-cache: the stored response MUST always go through validation with the origin server fi rst before using it • no-store: the response may not be stored in any cache. • no-transform: an intermediate cache or proxy cannot edit the response body • must-revalidate: indicates that once a resource becomes stale, caches must not use their stale copy without successful validation on the origin server. Cache-Control
  2. • max-age=<seconds>: the maximum amount of time a resource is

    considered fresh • max-stale[=<seconds>]: indicates the client will accept a stale response. • min-fresh=<seconds>: indicates the client wants a response that will still be fresh for at least the speci fi ed number of seconds. • stale-while- revalidate=<seconds>: indicates the client will accept a stale response, while asynchronously checking in the background for a fresh one • stale-if-error=<seconds>: indicates the client will accept a stale response if the check for a fresh one fails. Cache-Control
  3. Common CDN Offerings • Nearest cache node “routing”: DNS or

    Anycast • DDoS protection • HTTPS/SSL/TLS encryption and termination • Access Control, geo-restriction • IPv6
  4. Drawbacks • No control over cache eviction • Additional point

    of failure • Privacy and security challenges
  5. GET /content/stories/example-story.html?ref=xyz987&split-pages=true HTTP/1.1 Host: d111111abcdef8.cloudfront.net User-Agent: Mozilla/5.0 AppleWebKit/537.36 Chrome/83.0.4103.116 Accept:

    text/html,*/* Accept-Language: fr-FR,en Cookie: session_id=wxyz9876 Referer: https://news.example.com/ A cache hit again 🙂
  6. Cache policy • Query String • Cookies • Request headers

    You can choose as m uch as 10 for each type
  7. GET /content/stories/example-story.html?ref=xyz1234&split-pages=true HTTP/1.1 Host: d111111abcdef8.cloudfront.net User-Agent: Mozilla/5.0 AppleWebKit/537.36 Chrome/83.0.4103.116 Accept:

    text/html,*/* Accept-Language: fr-FR,en Cookie: session_id=wxyz9876; yummy_cookie=choco; tasty_cookie=strawberry Referer: https://news.example.com/
  8. GET /content/stories/example-story.html?ref=xyz1234&split-pages=true HTTP/1.1 Host: d111111abcdef8.cloudfront.net User-Agent: Mozilla/5.0 AppleWebKit/537.36 Chrome/83.0.4103.116 Accept:

    text/html,*/* Accept-Language: fr-FR,en Cookie: session_id=wxyz1234; yummy_cookie=choco; tasty_cookie=strawberry Referer: https://news.example.com/
  9. GET /content/stories/example-story.html?ref=xyz1234&split-pages=true HTTP/1.1 Host: d111111abcdef8.cloudfront.net User-Agent: Mozilla/5.0 AppleWebKit/537.36 Chrome/83.0.4103.116 Accept:

    text/html,*/* Accept-Language: fr-FR,en Cookie: session_id=wxyz1234; yummy_cookie=choco; tasty_cookie=strawberry Referer: https://news.example.com/ A cache miss ☹
  10. GET /content/stories/example-story.html?ref=xyz1234&split-pages=true HTTP/1.1 Host: d111111abcdef8.cloudfront.net User-Agent: Mozilla/5.0 AppleWebKit/537.36 Chrome/83.0.4103.116 Accept:

    text/html,*/* Accept-Language: fr-FR,en Cookie: session_id=wxyz9876; yummy_cookie=vanilla; tasty_cookie=strawberry Referer: https://news.example.com/
  11. GET /content/stories/example-story.html?ref=xyz1234&split-pages=true HTTP/1.1 Host: d111111abcdef8.cloudfront.net User-Agent: Mozilla/5.0 AppleWebKit/537.36 Chrome/83.0.4103.116 Accept:

    text/html,*/* Accept-Language: fr-FR,en Cookie: session_id=wxyz9876; yummy_cookie=vanilla; tasty_cookie=strawberry Referer: https://news.example.com/ A cache hit 🎉
  12. GET /content/stories/example-story.html?ref=xyz1234&split-pages=true HTTP/1.1 Host: d111111abcdef8.cloudfront.net User-Agent: Mozilla/5.0 AppleWebKit/537.36 Chrome/83.0.4103.116 Accept:

    text/html,*/* Accept-Language: fr-FR,en Cookie: session_id=wxyz9876; yummy_cookie=choco; tasty_cookie=strawberry Referer: https://news.example.com/
  13. GET /content/stories/example-story.html?ref=xyz1234&split-pages=true HTTP/1.1 Host: d111111abcdef8.cloudfront.net User-Agent: Mozilla/5.0 AppleWebKit/537.36 Chrome/83.0.4103.116 Accept:

    text/html,*/* Accept-Language: fr-FR,en Cookie: session_id=wxyz9876; yummy_cookie=choco; tasty_cookie=strawberry Referer: https://site2.example.com/
  14. GET /content/stories/example-story.html?ref=xyz1234&split-pages=true HTTP/1.1 Host: d111111abcdef8.cloudfront.net User-Agent: Mozilla/5.0 AppleWebKit/537.36 Chrome/83.0.4103.116 Accept:

    text/html,*/* Accept-Language: fr-FR,en Cookie: session_id=wxyz9876; yummy_cookie=choco; tasty_cookie=strawberry Referer: https://site2.example.com/ A cache miss ☹
  15. GET /content/stories/example-story.html?ref=xyz1234&split-pages=true HTTP/1.1 Host: d111111abcdef8.cloudfront.net User-Agent: Mozilla/5.0 AppleWebKit/537.36 Chrome/83.0.4103.116 Accept:

    text/html,*/* Accept-Language: fr-FR,en Cookie: session_id=wxyz9876; yummy_cookie=choco; tasty_cookie=strawberry referer: https://news.example.com/
  16. GET /content/stories/example-story.html?ref=xyz1234&split-pages=true HTTP/1.1 Host: d111111abcdef8.cloudfront.net User-Agent: Mozilla/5.0 AppleWebKit/537.36 Chrome/83.0.4103.116 Accept:

    text/html,*/* Accept-Language: fr-FR,en Cookie: session_id=wxyz9876; yummy_cookie=choco; tasty_cookie=strawberry referer: https://news.example.com/ A cache hit 🎉 because Cloudfront doesn’t consider the case of the header name
  17. GET /content/stories/example-story.html?ref=xyz1234&split-pages=true HTTP/1.1 Host: d111111abcdef8.cloudfront.net User-Agent: Mozilla/5.0 AppleWebKit/537.36 Chrome/83.0.4103.116 Accept:

    text/html,*/* Accept-Language: fr-FR,en Cookie: session_id=wxyz9876; yummy_cookie=choco; tasty_cookie=strawberry referer: HTTPS://NEWS.EXAMPLE.COM/
  18. GET /content/stories/example-story.html?ref=xyz1234&split-pages=true HTTP/1.1 Host: d111111abcdef8.cloudfront.net User-Agent: Mozilla/5.0 AppleWebKit/537.36 Chrome/83.0.4103.116 Accept:

    text/html,*/* Accept-Language: fr-FR,en Cookie: session_id=wxyz9876; yummy_cookie=choco; tasty_cookie=strawberry referer: HTTPS://NEWS.EXAMPLE.COM/ A cache miss ☹ because Cloudfront does consider the case of the header value
  19. GET /content/stories/example-story.html?ref=xyz987&split-pages=true HTTP/1.1 Host: d111111abcdef8.cloudfront.net User-Agent: Mozilla/5.0 AppleWebKit/537.36 Chrome/83.0.4103.116 Accept:

    text/html,*/* Accept-Language: fr,en Cookie: session_id=wxyz9876 Referer: https://news.example.com/ A cache miss ☹ because fr-FR and fr are not the same thing even though they both mean the user language is French
  20. GET /content/fr/stories/example-story.html?ref=xyz987&split-pages=true HTTP/1.1 Host: d111111abcdef8.cloudfront.net User-Agent: Mozilla/5.0 AppleWebKit/537.36 Chrome/83.0.4103.116 Accept:

    text/html,*/* Accept-Language: fr,en Cookie: session_id=wxyz9876 Referer: https://news.example.com/ One of many possible solutions
  21. Examples • Real-time image manipulation • Website security and checking

    • Bot mitigation at the edge • User prioritisation • …