when dispatcher caching is not enough
TRANSCRIPT
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 1
When dispatcher caching is not enough…
Jakub WądołowskiSenior Systems Engineer @ Cognifide
twitter.com/jwadolowski
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 2
Agenda
The What What was the problem about?
The Why Why we decided to go for Content Delivery Network (CDN)?
The How How it was implemented?
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 3
THE WHAT
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 4
It all started in 2012…
www.flickr.com/photos/nasahqphoto/16327416694
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 5
To be perfectly honest, initially it was rather like that…
www.flickr.com/photos/garryknight/5703519506
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 6
The client
EU pharmaceutical company75 offices across the globeOver 40 000 employeesMedical products available worldwide (180+ countries)
www.flickr.com/photos/worak/2258271659
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 7
Requirements
Country specific brochureware websites for medical productsiPad app for sales representativesSingle point for content entryMultiple integration points (SSO, user/device authentication, etc.)CQ 5.5, upgrade to AEM 6.1 in progress
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 8
Main components
Brochureware website
iPad app AEM Authoring
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 9
Logical Architecture
Single datacenter in LondonREST-like API for iPad appIntegrations with local and remote services
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 10
Initially it was just Spain, Argentina and Sweden
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 11
6 months later the number of countries was tripled
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 12
To finally reach 21 and it is still not over
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 13
THE WHY
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 14
“Our team in Argentina complains that the app feels slow. They can’t download presentations sometimes. Could you please
investigate that?”
Mr B.
www.flickr.com/photos/r4vi/8640618489
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 15
Problems
Latency, latency, latency…Way too high round trip times (RTT)TimeoutsBroken streamsConnection resetsPoor Internet connections in some areas
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 16
Solutions
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 17
When initial excitement was gone…
How we’re going to sync the content (both ways)?What about deployments?Do we have enough licenses to set up the new stack in a proper way?What’s the best way to implement content sharding?How long it will take to implement all of these things?
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 18
PoC conclusion
www.flickr.com/photos/geishaboy500/2496995573
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 19
The road to CDN
We can’t just cache more on dispatcherThis is a very well known problemLet’s use the right tool to solve the problem the right wayContent Delivery Network (CDN) is the way to go!
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 20
CDN definition
“(…) CDN is a large distributed system of servers deployed in multiple data centers across the Internet. The goal of a CDN is to serve content to end-users with high availability and high performance. CDNs serve a large fraction of the Internet content today (..).”, Wikipedia
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 21
AEM + CDN
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 22
CDN, right?
www.flickr.com/photos/pictures-of-money/16678590844
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 23
That's not necessarily true nowadays…
www.flickr.com/photos/halfrain/14410890555
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 24
Why Fastly?
Pay-as-you-go modelPowered by VarnishHighly customizable (ability to upload your own VCL)150 ms to purge – globally~5 sec to change a config through the web APISSD powered servers connected to T1 networksReal-time insight what’s happening (graphs, logs, etc)Great support
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 25
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 26
Still not convinced?
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 27
THE HOW
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 28
Uhh… ok, how should I start?
www.flickr.com/photos/kleuske/8004416109
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 29
The logs!
www.flickr.com/photos/martinbamford/5638834940
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 30
Logs and content structure
grep, awk, sed - all of these are your friendsCount your requestsLeverage the power of log monitoring tools (ELK, Splunk, etc.)Plan your content structure carefully
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 31
Look for patterns
www.flickr.com/photos/wwarby/4915777722
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 32
Request patterns
If it is a GET request and starts with /bin/myapp/v[1-2]/a_string.json then it is X
All requests to /content/something/*/_jcr_content.zip end with 302 to /some/path/to/file.zip
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 33
Assign these patterns to multiple buckets
www.flickr.com/photos/ddebold/15991919514
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 34
Content groups/buckets
Public contentPrivate contentContent available for authorized users only
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 35
Varnish in 1 slide!
Reverse HTTP proxyIn-memory time based cacheBlazing-fastBig “state” machineVarnish Configuration Language (VCL)Full control of HTTP flow
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 36
General caching rules
Cacheable methods: GET, HEADCacheable response codes: 200, 203, 300, 301, 302, 410, 404“Cache-Control: private” if not defined otherwise
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 37
Let’s start with the iPad app
www.flickr.com/photos/pestoverde/15048774061
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 38
iPad content
2 content groups8 request patternsTTL varies from 10 minutes to 7 days35/65 dynamic/static content (frequently changing JSON files vs PDFs/PNGs)
All REST API responses are private
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 39
Private content
Private content is cacheableWhat makes HTTP response private? It is tied up with user session – in other words HTTP request carried
unique authorization cookie
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 40
Is it really safe to cache that type of content?
www.flickr.com/photos/hyku/368912557
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 41
Private cache
Varnish cache is a key-value storeDefault key: req.url + req.http.hostreq.url + req.http.host + sessionId = private cache space - voila!
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 44
Dynamic means uncacheable?
www.flickr.com/photos/gsfc/7402445224
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 45
Dynamic content
Cache usually brings some trade-off Updates won’t be instantaneous TTL has to expire, or a purge request has to be triggered
CDN is the way to go if you accept this delay
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 46
Content purging
www.flickr.com/photos/librariesrock/13522859053
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 47
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 48
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 49
Content purging
Fastly exposes purge REST APIPurge URL Purge Key Purge AllPurge vs Soft Purge
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 50
Results
www.flickr.com/photos/89228431@N06/11322953266
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 51
iPad app statistics
Hit ratio: 48,4%
Cache coverage: 65,3%
Requests: 83K
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 52
What about the speed?
www.flickr.com/photos/129341635@N02/16609174727
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 53
Speed boost
Presentation download Europe: up to 21% faster South America: up to 50% faster APAC: up to 83% faster
API responses Europe: up to 60% faster South America: up to 40% faster APAC: up to 55% faster
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 54
Issues?
www.flickr.com/photos/giuseppemilo/15414290956
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 55
Crimes against cacheability
www.flickr.com/photos/alancleaver/4121423119
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 56
Crimes against cacheability
Adding Set-Cookie to every response Auth cookie is not revoked in the browser after logout TBD
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 57
“iPad app performance is much better now! But we still have some issues with authoring. It is really slow in some countries.”
Mr B.
www.flickr.com/photos/r4vi/8640618489
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 58
CDN in front of authoring?
I was rather skepticalWay too dynamic to be considered cacheable?What kind of improvement we might get? 5-10%? Is it worth it?Don’t know how, but it has been decided to roll things out
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 59
CDN + AEM Author
3 content groups36 request patternsTTL up to 14 daysMostly dynamic + static web GUI resourcesA lot of assets common for every logged in user
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 60
Authorized only!
www.flickr.com/photos/rudyjuanito/5170435542
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 61
Authorize at the edge
CDN knows nothing about user sessionThe goal is to cache common content for successfully authorized usersAuthorize them at the edge!
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 62
Auth tokens
www.flickr.com/photos/cfortier/426610972
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 63
Auth tokens
2nd auth cookie (token), readable by CDNHMAC function2 auth cookies are tied togetherReference implementation: https://github.com/fastly/token-functionsPrivate key shared between AEM and CDNCDN can evaluate user session without request to AEM
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 65
www.flickr.com/photos/spacexphotos/16169087563
96,4%
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 66
Author statistics
Hit ratio: 96,4%
Cache coverage: 45,1%
Requests: 97K
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 67
Crimes against cacheability
Adding Set-Cookie to every response Auth cookie is not revoked in the browser after logout “Vary: Cookie” usage
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 68
Summary
www.flickr.com/photos/andrewhurley/6254409229
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 69
Summary
Traffic growth is no longer an issue Over 2 TB monthly reaches CDN servers ~5,5 million HTTP requests per month just ~570 GB was passed through to AEM
License, budget and time savingsMore than satisfying resultsVery small changes in the AEM app itselfHappy client
The future of digital marketing. London, Poland, Copenhagen. © 22/06/2015 Page 70
[email protected]/jwadolowski
twitter.com/jwadolowski
linkedin.com/in/kubawadolowski/en
www.flickr.com/photos/jeffdjevdet/18027482924