Symfony Cache across load balanced servers and blue-green deployment (for cache)

Symfony Cache across load balanced servers and blue-green deployment (for cache)

I’m currently using Symfony (4.4) across some load balanced, auto-scaling, servers to provide a stateless API authenticated by JSON Web Tokens. These servers are deployed by a Jenkins server, which uses Packer with Ansible provisioning.

For both development and production I’m stripping the deploy down to the bare minimum (no console, no other environment files, dumping the env-file config with Composer, etc). Much of the usual Symfony deployment procedures are being run from Jenkins (because it wouldn’t be feasible to run them from within Packer).

I’m also using Redis to store a few things that need to be accessible from any of the load balanced instances.

I had the bright idea of using Redis for the Symfony caches and Doctrine caches to help speed things up. The Redis server is on the same network and has a fast connection. Latency isn’t really an issue and I figured that these servers should probably all share the same cache as they are entirely stateless.

However I think that during the deployment, between the cache being cleared and Packer finishing the image (and the image being put into the scaling group) that the servers may well be rebuilding their caches.

The end result, I think, is a new version of code using old caches and this is causing problems in deployment. I don’t want to keep the console on the server, for security, and I don’t want to hack the cloud-init script to clear the cache when an instance is booted, either, as this would happen whenever a new instance is added to a scaling group.

Is there a way of creating a prefix for the Redis caches so that the new version of the cache can be created, alongside the old, without them interfering?

Source: Symfony Questions

Leave a Reply

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