Design Development Startup Technology
Magento Development

Should I choose Redis or Varnish Cache?

Honestly, both Redis and Varnish benefit more from isolation than configuration on the same server that the webserver and database reside on. Redis and Varnish should be deployed as independent Droplets. You would need to configure Redis and Varnish Cache to use your Droplet’s Private Network IP and establish a connection to that IP from your WordPress plugin (for Redis).

Varnish, ideally, would sit in front of your web server Droplet(s), thus all requests for your domain.ext would hit the Varnish server first and Varnish, based on how it’s configured, would proxy the request to your actual web server.

Configuring Varnish as the primary entry point and the proxy would allow you to, for example, set up 10x web servers, define them in the Varnish configuration file and from that point, Varnish could be used to not only cache/accelerate requests, it would be able to manage load-balancing between the webserver cluster based on priority.

The firewall configuration for both Redis and Varnish would be restrictive. More specifically, you would set it to deny all except to the IP’s you specifically allow to connect. Likewise, you’d want to set up the firewall on your web/database server to do the same.

NOTE: UFW is an iptables wrapper that simplifies adding, removing and editing firewall rules – it’s disabled by default and can be enabled on Ubuntu using (you may need to use apt-get to install ufw on Debian):

ufw enable

BEFORE you enable UFW, to prevent lock-out, you’ll need to use the ufw command to add rules – specifically, a rule to allow SSH, HTTP, HTTPS, DNS (if you’re running BIND or an alternative), SMTP, IMAP, etc.

You can add basic rules using the format:

ufw allow|deny port/protocol

As an example, to allow the default SSH port through:

ufw allow 22/tcp

You can then proceed to add HTTP, HTTPS, DNS etc (commands shown in that order):

ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 53/tcp

The above commands will allow both IPv4 and IPv6 access to those ports by default.

That being said, the primary difference is that Redis is a key => value store that stores the value of X to a defined key, whereas Varnish is a web application accelerator / caching HTTP reverse proxy. While both provide caching, they both perform entirely different tasks.

You can definitely utilize both, though based on experience, using both can be a little tricky with WordPress simply due to how it’s designed and how the caching plugins work. It’s not to say that it’s impossible (it’s not), though it’ll likely take some time as well as trial and error to ensure the caches flush when you need them to.

Author

Pracoda

Pracoda Technologies is a Software, E-commerce Website, and ERP Development Company located in India. Pracoda Technologies Provides PWAs, hybrid mobile apps, and other e-commerce and ERP solutions at affordable prices. The top-of-mind service provider for small-to-medium-sized businesses.

Leave a comment

Your email address will not be published. Required fields are marked *