Do we need to deploy varnish if our Web application is using memcached or do we need memcached if we are using varnish to cache web contents.
Can someone recommend some scenarios where should we use one or the other or may be both.
Do we need to deploy varnish if our Web application is using memcached or do we need memcached if we are using varnish to cache web contents.
Can someone recommend some scenarios where should we use one or the other or may be both.
An HTTP proxy server and memcached are different technologies that solve different problems and apply at different layers of your software stack. Both can be useful.
An HTTP proxy server sitting in front of your application can respond to requests from its cache, saving your application from having to handle some of the request load. This only works if your application outputs content that is cacheable and if end users request the content more than once. In order for the content to be cacheable, your application needs to set the appropriate HTTP headers to let proxy servers (and browsers) know what is cacheable and for how long.
In the case of requests that make it all the way to your application (they miss the HTTP proxy cache or there is no HTTP proxy), your application has to compute the content it needs to send back. If this computation is expensive but parts of the data can be cached from previous requests, memcached is a good way for your application to stash away the results of [parts of] those computations so they can be reused later. Your application needs to be written specifically to do this, and to connect to memcached instances to get and set this data.
Varnish is meant to serve webpage files, like html, js, css, images, etc. It intercepts the HTTP traffic between the internet clients and the backend application server. Varnish listens to http port 80 and speaks HTTP protocol. Neither browsers nor the backend applications need to know that Varnish exists, once it is properly configured it just works.
Memcached is an application usually used to cache data brought from a database server to an application, in order to decrease the number of queries to the DB. Furthermore, since the data is cached on memory, its retrieval is much faster. But is the application that controls the insertion and retrieval of data from Memcached, in other words, the application must be written to make proper use of Memcached. Memcached does not speak HTTP protocol.