Is Redis really suitable as a queue driver in Laravel
For years now, Redis is probably the quickest and easier queue driver to use with Laravel, outside of the Database driver, as it requires little to no setup compared to RabbitMQ or Apache Kafka.
But does this mean it should be used for this reason?
(I’ve used ChatGPT to help with some of the information mentioned below, along with person experience).
General Performance Comparison
Below shows a general performance comparision of a few different services that can be used for worker queue processing. This is generally what most people look for: How quickly can my jobs get processed?
You can see that Redis and Amazon Kinesis are the winners here.
Feature Comparison
Below shows feature comparisions of a few different services:
Best Use Cases
When we start to look at use cases, it gets more interesting. RabbitMQ comes out as the best for general message queuing and not Redis.
So Whats Wrong With Redis?
You are limited by RAM
Anyone that uses Redis, will know, its an in memory cache, so you are limited by what memory is available.
Once that memory is used, either new writes are rejected OR old data is evicted, depending on what eviction policy you have setup. This seems to be a key area missed when comparisions are done. They focus on speed and less on stability.
This means if your worker queue is under load due to a spike in traffic, you could be processing jobs slower than they are coming in, if Redis starts evicting keys and rejecting new inserts, that data is lost forever.
This is evident with managed solutions, such as AWS Elasticache.
Possible Workarounds
If you are using Redis Enterprise, you can make use of a feature called Redis on Flash.
Redis on Flash technology combines RAM and flash to store large datasets in Redis with much lower cost per GB. With Redis on Flash, you can extend RAM onto flash memory and keep larger datasets in Redis, all without losing Redis’ performance advantage. To provide the best data access performance, Redis on Flash uses smart data placement, storing frequently accessed data in RAM and less frequently accessed data in flash. The cost savings to store over 10 terabytes can often be more than 80%.
If you are using Laravel Horizon, you can take advantage of min/max processes, so when the queue gets large, more worker processes will start up to try and process the jobs quicker.
There are probably many other workarounds, that would require using Redis with another service.
Should I Worry?
It really depends on what you are processing and how big the product is you are working on.
If you run a small business, you can probably get away with using Redis, as you are unlikely to use all the RAM available.
For larger projects, you may need a more reliable service for large queues.
Conclusion
If you want to use Redis for queues, there is nothing stopping you, Laravel has very good support in this area, as long as you know your queues don’t run the risk of filling up.
There are ways around it by using Redis Enterprise, or by using Laravel Horizon, with min/max processes configuration.