caching the uncacheable: leveraging your cdn to cache dynamic content

68
Caching The Uncacheable: Leveraging Your CDN to Cache Dynamic Content Hooman Behesh+, VP Technology

Upload: fastly

Post on 30-May-2015

440 views

Category:

Technology


1 download

DESCRIPTION

June 25, 2014. Hooman Beheshti, VP Technology at Fastly, discusses how using a real-time, modern CDN that provides instant cache invalidation and real-time analytics allows for instantaneous control over dynamic content caching. In this session, he looks at the challenges CDNs face with dynamic content and how you can use programmatic means to fully integrate your applications with your CDN.

TRANSCRIPT

Page 1: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Caching  The  Uncacheable:  

 Leveraging  Your  CDN  to  Cache  Dynamic  

Content  

Hooman  Behesh+,  VP  Technology  

Page 2: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Dynamic  Content  Is  Really  Interes=ng!  

Page 3: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

What  Is  Dynamic  Content?  •  Stuff  that’s  not  sta+c!  •  With  web  traffic,  generally  the  base  HTML  –  Big  deal  because  it’s  blocking  –  And  some+mes  the  largest  object  à  longer  download  

•  Could  be  other  things  too  –  AJAX  calls  –  API  calls  

•  More…  

Page 4: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content
Page 5: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Blocking  

Page 6: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content
Page 7: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content
Page 8: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Classically,  with  dynamic  content…  

Caching  

Page 9: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Dynamic  Content  Caching  Problems  

•  Serving  stale  pages  – Lack  of  good  invalida+on  framework  

 

Page 10: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Caching    vs.    

Invalida=on  

Page 11: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content
Page 12: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content
Page 13: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content
Page 14: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

We  tried…  

Page 15: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Dynamic  Content  Caching  Problems  

•  Serving  stale  pages  – Lack  of  good  invalida+on  framework  

 

Page 16: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Dynamic  Content  Caching  Problems  

•  Serving  stale  pages  – Lack  of  good  invalida+on  framework  

•  Real-­‐+me  visibility  – Real-­‐+me  analy+cs/stats  – Real-­‐+me  logging  

 

Page 17: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

CDNs  and  Dynamic  Content  

•  Generally,  handling  dynamic  content  has  been  a  maRer  of  transport  – Op+mize  from-­‐origin  delivery  – “DSA”  (Dynamic  Site  Accelera+on)  – Middle  mile  op+miza+ons  – TCP  tweaks  

 

Page 18: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Dynamic  Content,  Tradi=onally  

CDN  Node  

Client  

Origin  

Some  TCP  Tweaks  

Page 19: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Dynamic  Content,  Tradi=onally  

CDN  Node   CDN  Node  

Client  

Origin  

Lots  of  TCP  Tweaks  

Page 20: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Dynamic  Content,  Tradi=onally  

•  We  some+mes  do  micro  caching  of  HTML  –  Short  TTL  for  HTML  content  – Not  full  proof  

•  Ex:  news  stories  faux-­‐pas!  

•  ESI  (Edge  Side  Includes)  –  Par+al  caching  – Hard  and  onerous  

 

Page 21: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Actually…  

•  Dynamic  content  is  more  cacheable  than  we  think  

•  Sta+c  for  short  periods  of  +me  

•  Unpredictable  invalida+on  –  Standard  HTTP  caching  rules  aren’t  good  enough  

Page 22: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

A  Lot  BeMer!  

CDN  Node   CDN  Node  

Client  

Origin  

Page 23: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content
Page 24: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Blocking  

Page 25: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content
Page 26: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content
Page 27: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

So  Many  Benefits!  

•  Performance  –  Faster  +me  to  first  byte  –  Faster  start  render  – Happy  users!  

•  Offload  –  Less  work  for  our  servers  –  Less  bandwidth  at  origin  

Page 28: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

What  would  make  it  beMer?  

Page 29: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Programma=c  Invalida=on  

•  Invalida+on  API  •  Granular  •  Instantaneous  – Big  problem  with  classic  CDNs  (mul+-­‐minute  purges)  

 

Page 30: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Power  of  the  Purge!  

•  Instant  purging:  – As  a  page  gets  published,  a  purge  command  also  gets  published  

–  Instant  means:  predictable  and  determinis+c  behavior  

 

Page 31: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Power  of  the  Purge!  

•  Purge  dependencies  – Surrogate  Keys  – Using  tags  to  purge  en+re  chunks  of  content  at  once  

 

Page 32: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

More  than  just  Invalida=on…  

Page 33: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

The  Influence  of  Clouds  

•  The  CDN  is  an  extension  of  the  app  •  No  longer  a  black  box  •  Real-­‐+me  integra+on  with  the  app  •  Infrastructure  as  code  – Your  content  =>  You  need  control  

Page 34: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Control  

•  Programmability  – Configura+on  API  –  Invalida+on  API  –  Instantaneous  and  real  +me  – Granular  caching  

•  Ex:  Geo-­‐based  caching  

Page 35: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Control  at  the  Edge  

•  Moving  app  logic  to  the  edge  •  VCL  – Varnish  Configura+on  Language  – Script-­‐like  configura+on  for  func+onality  at  the  edge  

Page 36: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Visibility  

•  Real  +me  analy+cs  – Network  stats  – HTTP  stats  (status  codes  ,  etc)  –  Caching  stats  (hits,  misses,  etc)  –  Stats  API  

•  Logging  –  Real  +me  logs  –  Streaming  to  various  log  des+na+ons  

Page 37: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Example:  CMS  +  Purge  

Page 38: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

WordPress:  Before  

CDN  Node  

Page 39: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

WordPress:  Before  

CDN  Node  

Page 40: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

WordPress:  Before  

CDN  Node  

Page 41: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

WordPress:  Before  

CDN  Node  

Page 42: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

WordPress:  Before  

CDN  Node  

Cache  

Page 43: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content
Page 44: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

WordPress:  AWer  

CDN  Node  

Page 45: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

WordPress:  AWer  

CDN  Node  

HTTP/1.1 200 OKContent-Type: text/htmlContent-Length: 55,666Cache-Control: Long Time, totally!

Page 46: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

WordPress:  AWer  

CDN  Node  

Page 47: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

WordPress:  AWer  

CDN  Node  

Page 48: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

WordPress:  AWer  

CDN  Node  PURGE  

Page 49: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

WordPress:  AWer  

CDN  Node  PURGE  

Page 50: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

WordPress:  AWer  

CDN  Node  PURGE  

(Has  to  be  instantaneous!)  

Page 51: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

WordPress:  AWer  

CDN  Node  

HTTP/1.1 200 OKContent-Type: text/htmlContent-Length: 55,666Cache-Control: Long Time, totally!

Page 52: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Example:  Beacon  Termina=on  at  the  Edge  

Page 53: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Before  

CDN  Node  

Origin  

Log  Analysis  

http://collector.site.com/beacon.img?a=1&b=2&c=3

Page 54: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Before  

CDN  Node  

Origin  

Log  Analysis  

http://collector.site.com/beacon.img?a=1&b=2&c=3

Page 55: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Before  

CDN  Node  

Origin  

Log  Analysis  

HTTP/1.1 200 OKPragma: no-cacheExpires: Wed, 19 Apr 2000 11:43:00 GMTCache-Control: no-cache, no-storeLast-Modified: Wed, 21 Jan 2004 19:51:30 GMTContent-Type: image/gifDate: Fri, 20 Jun 2014 12:22:20 GMTServer: ApacheContent-Length: 35

http://collector.site.com/beacon.img?a=1&b=2&c=3

Page 56: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Before  

CDN  Node  

Origin  

Log  Analysis  

HTTP/1.1 200 OKPragma: no-cacheExpires: Wed, 19 Apr 2000 11:43:00 GMTCache-Control: no-cache, no-storeLast-Modified: Wed, 21 Jan 2004 19:51:30 GMTContent-Type: image/gifDate: Fri, 20 Jun 2014 12:22:20 GMTServer: ApacheContent-Length: 35

http://collector.site.com/beacon.img?a=1&b=2&c=3

Page 57: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

AWer  

CDN  Node  

Origin  http://collector.site.com/beacon.img?a=1&b=2&c=3

Page 58: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

AWer  

CDN  Node  

Origin  

HTTP/1.1 200 OKPragma: no-cacheExpires: Wed, 19 Apr 2000 11:43:00 GMTCache-Control: no-cache, no-storeLast-Modified: Wed, 21 Jan 2004 19:51:30 GMTContent-Type: image/gifDate: Fri, 20 Jun 2014 12:22:20 GMTServer: ApacheContent-Length: 35

http://collector.site.com/beacon.img?a=1&b=2&c=3

Page 59: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

AWer  

CDN  Node  

Origin  

HTTP/1.1 204 No ContentDate: Sat, 21 Jun 2014 23:21:12 GMTServer: Awesome ServerContent-Length: 0

http://collector.site.com/beacon.img?a=1&b=2&c=3

Page 60: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

AWer  

CDN  Node  

Origin  

Syslog  /  S3  /  FTP/etc  

http://collector.site.com/beacon.img?a=1&b=2&c=3

Page 61: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Example:  Edge-­‐generated  Content  

Page 62: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

JSON  Data  Center  ID  

CDN  Node  

Origin  http://www.site.com/which_datacenter.js

Page 63: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

JSON  Data  Center  ID  

CDN  Node  

Origin  

{ ‘datacenter’ : ‘SJC’ }

http://www.site.com/which_datacenter.js

Page 64: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

VCL  Snippet  

Page 65: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

More  Examples  

•  Caching  with  tracking  cookies:  –  hRp://www.fastly.com/blog/how-­‐to-­‐cache-­‐with-­‐tracking-­‐cookies  

•  API  Caching:  –  hRp://www.fastly.com/blog/api-­‐caching-­‐part-­‐iii  (part  3,  with  links  to  previous  two  parts)  

•  Log  Streaming:  –  hRp://www.fastly.com/blog/+ps-­‐for-­‐streaming-­‐logs    

Page 66: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Let’s  Sum  Up!  

Page 67: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Summary  

•  Dynamic  content  can  be  cached  – We  need  instant  purging  – We  need  real-­‐+me  logs  and  stats  

•  Real-­‐+me  integra+on  of  our  CDN  with  our  app  is  cool!  –  Extensive/granular  API  to  control  the  CDN  –  Control  and  visibility  at  the  edge  lets  us  be  really  crea+ve  

•  Never  use  “Long Time, totally!” in  a  Cache-Control header!    

Page 68: Caching the Uncacheable: Leveraging Your CDN to Cache Dynamic Content

Thank  you!  

[email protected]