Magento Varnish-Cache Integration
What is Varnish?
Varnish is a … 
“…transparent, hard, protective finish or film 
primarily used in wood finishing but also for other 
materials…” 
Wikipedia: Varnish
So…what is Varnish?
Varnish is… 
=
Applause, please!
And Varnish-Cache?
Varnish-Cache is defined as… 
 Reverse proxy 
 Web Accelerator 
 HTTP Accelerator
So…Varnish-Cache is not…
What is a proxy? 
“In computer networks, a proxy server is a server (a 
computer system or an application) that acts as an 
intermediary for requests from clients seeking 
resources from other servers…” 
Wikipedia: Proxy server
Proxy concept
Types of proxy: Forward
Forward Proxy: Examples
Types of proxy: Reverse
Reverse Proxy: Examples
Varnish-Cache Features: Part 1 
• Designed for content-heavy dynamic web sites 
• Heavily threaded, with each client connection being handled by a separate worker thread 
• Varnish Configuration Language (VCL) 
• Load balancing and backend health polling
Varnish-Cache Features: Part 2 
• Support for Edge Side Includes 
• Graceful handling of dead and slow backends 
• The web management administration interface 
• The management port 
• Live statistics and logging
Example Infrastructure: Part 1
Example Infrastructure: Part 2
Example Infrastructure: Part 3
Does Magento support Varnish? 
WHY ? 
• Dynamic content/Personalization 
• Painstaking customization of VCL 
• No tagging/Partial flushing 
• Session Cookie 
NO
Diluting Varnish with Turpentine 
• Full Page Caching, with hole-punching via Varnish ESI and/or AJAX 
• Configurable via standard Magento methods 
• Able to generate and apply new Varnish VCLs on the fly 
• Blacklist requests from caching by URL or parameters (SID, store, etc) 
• Configure cache TTL by URL and individual block's TTL 
• Supports multiple Varnish instances for clustered usage 
• Automatic cache clearing on Magento actions 
• Supports non-root Magento installs and multi-store/multi-site setups 
• Support for site-crawlers for cache warming
Request flow with Varnish
What can we do with it ? 
• Cache static pages 
• Homepage 
• CMS 
• Contacts 
• Etc 
• Cache catalog pages 
• Category listings 
• Product search results 
• Product view pages
How fast is FAST ?
Lessons learned 
Triple check 
• Dynamic blocks in the project 
MiniCart 
Login 
Anything customer related 
• Currency & Store View switcher 
• 3rd Party modules in Admin ! 
• Checkout 
• Payment gateways redirects 
• Customer groups 
• Design Exceptions
Further optimizations 
The fastest HTTP request is the one not made 
– Use cookie or local storage (IE>7) when: 
- Adds a product to a cart 
- Logs in or logs out 
- Adds a product to a compare list 
- Recently viewed products, etc 
Increase Hit Ratio 
– Cache 404 pages 
– Redirects 
KEEP PUSHING
References 
http://en.wikipedia.org/wiki/Proxy_server 
https://www.youtube.com/watch?v=x7t2Sp174eI 
https://github.com/nexcess/magento-turpentine 
https://www.varnish-cache.org/trac/wiki/VarnishFeatures#Livestatisticsandlogging
Thank You ! 
Gustavo G. Moyano 
DevOps Engineer 
Ezequiel A. Kupelian 
Dev. Manager

Varnish & Magento TechTalk @Lyracons

Editor's Notes

  • #17 a http accelerator a load balancer a failover system and a caching reverse proxy
  • #18 a http accelerator a load balancer a failover system and a caching reverse proxy
  • #19 a http accelerator a load balancer a failover system and a caching reverse proxy
  • #20 a http accelerator a load balancer a failover system and a caching reverse proxy
  • #28 You can decrease amount of AJAX calls to the number of real user actions. – Customer adds product to cart, you make an ajax call to update session storage – Customer logs in, you make and ajax call to update the it again – Customer adds product to wishlist or compare products list, you update a session storage. So in the end it should be 1 action – 1 AJAX call, and NOT 1 page view – 3 or more AJAX calls!  The higher the ratio, the more effective the cache is at improving performance. Less operations in Magento and MySQL will mean reduced server footprint, which lower costs, and faster responses, which increase convertion => more sales.