Is there a way to make Celery/RabbitMQ persistent?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
When building applications that require task queues, Celery with RabbitMQ is a popular choice due to its robustness and flexibility. However, one common concern when deploying these technologies is ensuring data persistence — making sure that no tasks are lost in the event of a crash or other interruptions. Fortunately, RabbitMQ provides mechanisms to achieve persistence, ensuring that messages can survive broker restarts.
Understanding Persistence in RabbitMQ
RabbitMQ, which acts as a message broker in a Celery setup, by default does not store messages on disk; it keeps them in memory. To make sure that messages persist across RabbitMQ restarts, you need to do two main things:
- Declare queues as durable.
- Send messages with the delivery mode set to persistent.
1. Durable Queues
A durable queue is a queue that will be recreated upon a broker restart, preserving its state. When you declare a queue as durable, RabbitMQ writes the queue definition to disk, so it can reconstruct it when it restarts.
2. Persistent Messages
For a message to survive a broker restart, it needs to be marked as persistent. This means that RabbitMQ will store these messages to disk to ensure they are not lost in the event of a failure.
How to Implement Persistence in Celery with RabbitMQ
Here’s a step-by-step guide on how you can configure your Celery and RabbitMQ setup for persistence:
- Configure RabbitMQ Queue as Durable:When declaring a queue in RabbitMQ through Celery, you can set it as durable. In Celery, you do this by setting the
durableparameter toTruein the task queue settings.
- Ensure Messages are Persistent:In Celery, you can ensure that all messages sent to the broker are persistent by setting the
delivery_modeto 2 (which indicates persistence).
- Handling Producer and Consumer Settings:Ensure that both the producer (the Celery task publisher) and the consumer (the worker) acknowledge the configurations. It’s important that all parts of the system respect these settings for persistence to be effective.
Considerations for Using Persistent Messages
While persisting messages provides higher reliability, it does come with trade-offs:
- Performance Impact: Writing messages to disk increases the time it takes to enqueue and dequeue messages.
- Disk Space Usage: Persistent messages will use disk space, which might require monitoring and management.
Summary Table
| Feature | Description | Impact |
| Durable Queues | Queues are saved on disk and reloaded on broker restart. | Ensures queue configuration persistence. |
| Persistent Messages | Messages are stored on disk to survive broker restarts. | Guarantees message persistence but may slow down operations. |
| Delivery Mode | Set to 2 for persistent messages. | Ensures messages are written to disk. |
In conclusion, while Celery with RabbitMQ does not guarantee persistence by default, with proper configuration, you can achieve a robust setup that ensures no task is lost even in the event of system failures. Applications that require high reliability should implement these persistence features, keeping in mind the possible impacts on performance and disk space.
Related reading
- Is there a way to manually set an ElasticSearch document id when inserting via AWS Kinesis Firehose?
- Is there a way to prioritize messages in Apache Kafka 2.0?
- Is there a way to produce Kafka messages with headers using Kafka Confluent REST API?
- Is there a way to set a delay for a message sent by a kafka producer?
- Is there a way to stop Kafka consumer at a specific offset?
- Is there a way to use confluent Kafka Dotnet JSON serializer WITHOUT schema registry,
- Is there an equivalent of ping for RabbitMQ? How can I diagnose whether an exchange or queue is broadcasting?
- Is there an OpenAPI type specification for Kafka or similar technology?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.