Higher Performance Caching Options in Mautic

Starting with Mautic 3.3, Mautic fully supports the Memcached and Redis cache adapters — improving on a major bottleneck for larger Mautic installations. In prior Mautic versions, storing the Symfony cache on the filesystem was the only option. Now, Mautic can cache objects to an in-memory data store, providing improved performance.

Even though a Redis server could be configured with Mautic < 3.3, it was only used to persist PHP sessions to prevent arbitrary logouts across load-balanced, scalable deployments.

Symfony Cache for Mautic — Recommended: Redis

The /bin/cache/ (or in Mautic 2.x /app/cache/) Symfony cache directory for Mautic remained stored in the filesystem. The performance was still relatively slow compared to an in-memory cache — even with high performance, datacenter SSDs. It was also necessary to mount the Mautic cache directory to multiple containers or servers, using methods such as an NFS share, LXC storage volume, or Docker volume backed by Ceph or GlusterFS.

With Mautic 3.3 or newer, the filesystem cache can be completely replaced with a Memcached or Redis cache by reconfiguring cache_adapter from filesystem to memcached or redis — furthering the scalability of Mautic installations across multiple containers or servers. Memcached or Redis both store their data structures in volatile memory, which can be orders of magnitude faster than a storage device.

Where Memcached or Redis reside in the same operating system as the application, it can provide up to a 33% boost in speed to specify a Unix socket versus a TCP socket for the cache — due to the lower connection latency. Otherwise, it is absolutely crucial to ensure a robust internal network connection between the application servers and the cache, to fully realize the benefits of in-memory caching for Mautic.

Benefits of Memcached and Redis Clusters

The Memcached or Redis service, which may be a single instance, a Memcached cluster, or Redis cluster, can be easily scaled across high memory cloud computing instances, including ARM-based instance types with vastly superior price/performance characteristics (memory from $0.0015/GB-hr for Ampere A1 compute shapes on Oracle Cloud Infrastructure). The architecture & tuning of the Redis cluster for Mautic or other applications, is one of the ways that our professional team can help.

The cache_adapter supports the parameters provided by Symfony for configuration, with examples described in the Mautic documentation. For example, if you were using a single Redis service to support multiple Mautic instances (multi-tenant), you would need to specify a different database index for each Mautic instance. By default, Redis supports 16 databases numbered 0 to 15; This value can be increased in the Redis configuration.

It’s also worth bearing in mind that the PHP/PHP-FPM installation on your Mautic application servers must also have the php-redis and/or php-memcached packages installed, in order to have the required modules to use the cache drivers.

In most cases, we would prefer to use Redis over Memcached as a general-purpose cache for Mautic, given that Redis is a newer technology that better supports caching objects as opposed to purely key/value data with Memcached.

API Rate Limiter Cache — Recommended: Memcached

For customers using the Mautic API to integrate with other applications (e.g. through Integromat), it might also be suggested to change the api_rate_limiter_cache to a different cache adapter from the default, which is the filesystem. As discussed above, for a multi-node deployment of Mautic, each node does not have the same view of the cache directory unless its mounted to multiple servers using a network file system. This cumbersome setup can be eliminated by changing both the cache_adapter and api_rate_limiter_cache.

The api_rate_limit_limiter was set to 0 (unlimited) by default in Mautic 2.x, but changed to a default of 1200 starting in Mautic 3.x, so an incorrect configuration can completely hobble the usage of the API in newer versions.

Where the Mautic API is being called by multiple users or applications, it can be helpful to implement an API rate limit to ensure fair usage is available to each access token. Since the rate limiter stores relatively simple key/values, memcached would be sufficient for this particular cache.

Memory Caching for Mautic Reseller Clusters

The opportunity to use speedier caches for Mautic is another reason why agencies providing Mautic-as-a-service to their clients should consider upgrading to the latest version of our Mautic Reseller Program. The updated Mautic reseller infrastructure includes an optimized container image that supports Memcached or Redis as a cache adapter for Mautic. To simplify the setup, the Memcached or Redis containers can be deployed as part of the stack definition, when setting up Mautic using the reseller infrastructure.

Security of Memcached and Redis Services

Paying attention to the security of the Memcached and Redis services are especially important, since Memcached, by default accepts connections on port 11211 without authentication. Redis, accepts connections from the localhost on port 6379 without authentication. If Redis is configured to accept connections from other than the localhost, it can be advisable to specify a Redis password.

Improperly secured Memcached servers are frequently used as part of botnets to perform DDoS reflection attacks by generating enormous amounts of UDP traffic, and “reflecting” them towards the target. Using a combination of stateful network firewalls, software firewalls such as iptables, ufw/firewalld, and stack networks in Docker can help prevent your resources from being abused to attack others (and running up a big cloud bill!). Unfortunately, open Memcached instances are a common reason why hosting customers are suspended by their cloud provider’s abuse teams for Terms of Service violations.

Additionally, Memcached and Redis connections are in plain-text between the applications and the respective caching service — there is no encryption by default. It is therefore important to ensure that private networks within a VPC/VCN are used for Memcached or Redis traffic, to prevent sensitive data from being compromised. Some implementations of Memcached or Redis (as a service), such as AWS ElastiCache, can also support encryption out-of-the-box.

Custom Mautic Infrastructure on Any Cloud Provider

Do you need help with scaling your Mautic instance to handle a growing number of contacts and emails sent per month? Contact our team to request a proposal. We have worked with companies including in the media, e-commerce, and fintech verticals to build custom infrastructure for Mautic on a variety of cloud providers.