April 27 2023

Varnish or NGINX FastCGI Cache as caching system?

Let's find out how using both in the same software stack can fill the gaps of both in the free version.

There has been a religious war going on for some time about which is the best cache for webservers. There are the everlasting purists who recommend a cache like Varnish Cache and the novices who recommend it NGINX FastCGI cache we are talking about in this article, as a faster, simpler, and less complex method of providing HTTP (and of course HTTPS) caching functionality.

There are those like us who argue that Varnish has more features and allows, thanks to its Vansh Configuration Language (VLC ed) to generate really complex and advanced caching setups and configurations, and there are those who argue that the same things can be done with a few more lines of configuration directly in NGINX, without adding cache layers like Varnish.

Varnish VCL Example

Normally in these comparisons, everyone brings grist to his mill, to what he usually uses, to what he knows how to use most or finds more comfortable. For example, you want to put the flexibility of Varnish Cache and the compatibility with WordPress thanks to market standard plugins such as W3 Total Cache, Proxy Cache Purge, WP Fastest Cache or the highly commercialized WP Rocket ?

WP Rocket Varnish
WP Rocket Varnish

 

WP Fastest Cache Varnish
WP Fastest Cache Varnish Option

Objectively, when we talk about WordPress and performance we are the first to point out how important it is for us to have a Varnish-based stack as a full page cache. However, are we really right when we assert that the NGINX Cache is a "toy" for inexperienced sysadmins? And when some of our colleagues criticize us for using a cache like Varnish that could in fact be saved using the NGINX Cache, criticizing us for weighing down a software stack that could be leaner, are they really right?

In short, between Varnish and NGINX which cache is better?

To answer this question, one must necessarily take a step back and distance oneself from one's convictions, seeking an open approach towards what we have not used or used badly until now and begin to understand the business models of Varnish and NGINX and how from an understanding of their respective limitations they can include and not exclude each other.

Business models of Varnish and NGINX

Varnish and NGINX are two popular proxy servers used to improve web application performance and ensure better user experience. What makes these software even more interesting is that both are developed under the open source philosophy, which means that they are freely available for anyone to use and modify.

However, there is also a commercial version of both software: NGINX Plus and Varnish Enterprise. These versions come with advanced features and additional functionality, which are not available in the free versions. Such features include official support from the company, software quality assurances, and even performance analysis tools.

What differentiates these commercial versions the most from the free versions is their price. Both commercial versions have licensing costs in the tens of thousands of dollars annually. This means that these licenses are aimed primarily at companies that need advanced features and are willing to pay for additional support and warranties.

Overcome the respective limitations by using both NGINX and Varnish

Aware that both NGINX and Varnish have limitations in their free versions, we can still overcome them by using both proxy servers in combination.

For example, NGINX can be used as a microcaching service. In this way, NGINX is used as the first level of caching, where data that is frequently requested by users is stored. When a request arrives at the server, NGINX checks its cache to see if the response is already there. If it is, NGINX immediately sends the response back to the client without having to go to the next stage of processing.

NGINX Microcaching

In combination with Varnish, NGINX can be used as a front-end for the Varnish caching server. In this scenario, client requests are initially handled by NGINX. If the requested data is not in NGINX's cache, the request is passed to the Varnish server, which has a larger and more robust cache. Varnish has the ability to store large amounts of data in RAM, making it much faster than classic caches like Memcached and Redis.

When a client requests information, NGINX looks it up in its cache. If the response is there, NGINX sends it directly to the client. Otherwise, the request is forwarded to Varnish, which in turn checks its cache to see if the response is there. If the response is present in the Varnish cache, it is returned to the client through NGINX.

This combination of caching can significantly improve web application performance. Furthermore, it is possible to customize the behavior of the cache using the configuration options offered by both proxy servers and with some precautions to ensure that the web server never returns a MISS as a response, thus guaranteeing excellent response times of less than 30ms.

 

 

 

Do you have doubts? Don't know where to start? Contact us!

We have all the answers to your questions to help you make the right choice.

Chat with us

Chat directly with our presales support.

0256569681

Contact us by phone during office hours 9:30 - 19:30

Contact us online

Open a request directly in the contact area.

INFORMATION

Managed Server Srl is a leading Italian player in providing advanced GNU/Linux system solutions oriented towards high performance. With a low-cost and predictable subscription model, we ensure that our customers have access to advanced technologies in hosting, dedicated servers and cloud services. In addition to this, we offer systems consultancy on Linux systems and specialized maintenance in DBMS, IT Security, Cloud and much more. We stand out for our expertise in hosting leading Open Source CMS such as WordPress, WooCommerce, Drupal, Prestashop, Joomla, OpenCart and Magento, supported by a high-level support and consultancy service suitable for Public Administration, SMEs and any size.

Red Hat, Inc. owns the rights to Red Hat®, RHEL®, RedHat Linux®, and CentOS®; AlmaLinux™ is a trademark of AlmaLinux OS Foundation; Rocky Linux® is a registered trademark of the Rocky Linux Foundation; SUSE® is a registered trademark of SUSE LLC; Canonical Ltd. owns the rights to Ubuntu®; Software in the Public Interest, Inc. holds the rights to Debian®; Linus Torvalds owns the rights to Linux®; FreeBSD® is a registered trademark of The FreeBSD Foundation; NetBSD® is a registered trademark of The NetBSD Foundation; OpenBSD® is a registered trademark of Theo de Raadt. Oracle Corporation owns the rights to Oracle®, MySQL®, and MyRocks®; Percona® is a registered trademark of Percona LLC; MariaDB® is a registered trademark of MariaDB Corporation Ab; REDIS® is a registered trademark of Redis Labs Ltd. F5 Networks, Inc. owns the rights to NGINX® and NGINX Plus®; Varnish® is a registered trademark of Varnish Software AB. Adobe Inc. holds the rights to Magento®; PrestaShop® is a registered trademark of PrestaShop SA; OpenCart® is a registered trademark of OpenCart Limited. Automattic Inc. owns the rights to WordPress®, WooCommerce®, and JetPack®; Open Source Matters, Inc. owns the rights to Joomla®; Dries Buytaert holds the rights to Drupal®. Amazon Web Services, Inc. holds the rights to AWS®; Google LLC holds the rights to Google Cloud™ and Chrome™; Facebook, Inc. owns the rights to Facebook®; Microsoft Corporation holds the rights to Microsoft®, Azure®, and Internet Explorer®; Mozilla Foundation owns the rights to Firefox®. Apache® is a registered trademark of The Apache Software Foundation; PHP® is a registered trademark of the PHP Group. CloudFlare® is a registered trademark of Cloudflare, Inc.; NETSCOUT® is a registered trademark of NETSCOUT Systems Inc.; ElasticSearch®, LogStash®, and Kibana® are registered trademarks of Elastic NV This site is not affiliated, sponsored, or otherwise associated with any of the entities mentioned above and does not represent any of these entities in any way. All rights to the brands and product names mentioned are the property of their respective copyright holders. Any other trademarks mentioned belong to their registrants. MANAGED SERVER® is a registered trademark at European level by MANAGED SERVER SRL Via Enzo Ferrari, 9 62012 Civitanova Marche (MC) Italy.

JUST A MOMENT !

Would you like to see how your WooCommerce runs on our systems without having to migrate anything? 

Enter the address of your WooCommerce site and you will get a navigable demonstration, without having to do absolutely anything and completely free.

No thanks, my customers prefer the slow site.
Back to top