celers
Production-ready, Celery-compatible distributed task queue library for Rust. Binary-level protocol compatibility with Python Celery while delivering superior performance, type safety, and reliability.
Overview
CeleRS provides:
- ✅ Celery Compatibility: Binary protocol compatible with Python Celery 4.x/5.x
- ✅ Type Safety: Compile-time guarantees for task signatures
- ✅ High Performance: 10-100x throughput vs Python Celery
- ✅ Multiple Brokers: Redis, PostgreSQL, RabbitMQ, AWS SQS
- ✅ Workflow Primitives: Chain, Group, Chord, Map, Starmap
- ✅ Observability: Prometheus metrics, structured logging
- ✅ Production Ready: Graceful shutdown, retries, dead letter queues
- ✅ Memory Safe: No garbage collection, predictable performance
Quick Start
Installation
[]
= { = "0.1", = ["redis"] }
= { = "1", = ["full"] }
= { = "1", = ["derive"] }
Basic Example
use *;
// Define task with automatic serialization
// Define task function
async
async
Enqueue Tasks
use *;
async
Features
Core Features (Always Available)
- Task registry and execution
- Message serialization (JSON)
- Basic broker interface
- Type-safe task definitions
Optional Features
[]
= { = "0.1", = [
"redis", # Redis broker support
"postgres", # PostgreSQL broker support
"backend-redis", # Redis result backend
"metrics", # Prometheus metrics
"workflows", # Canvas workflow primitives
"beat", # Periodic task scheduler
] }
| Feature | Description | Enables |
|---|---|---|
redis |
Redis broker | celers-broker-redis |
postgres |
PostgreSQL broker | celers-broker-postgres |
amqp |
RabbitMQ broker | celers-broker-amqp |
sqs |
AWS SQS broker | celers-broker-sqs |
backend-redis |
Redis result backend | celers-backend-redis |
backend-db |
Database result backend | celers-backend-db |
metrics |
Prometheus metrics | celers-metrics |
workflows |
Canvas workflows | celers-canvas |
beat |
Periodic tasks | celers-beat |
Architecture
┌─────────────────────────────────────────────────────┐
│ Application Layer │
│ (Your Tasks & Workflows) │
└─────────────────────────────────────────────────────┘
│
┌─────────────────────────────────────────────────────┐
│ Runtime Layer │
│ Worker │ Canvas │ Beat │ Metrics │
└─────────────────────────────────────────────────────┘
│
┌─────────────────────────────────────────────────────┐
│ Messaging Layer (Kombu) │
│ Producer │ Consumer │ Transport │
└─────────────────────────────────────────────────────┘
│
┌─────────────────────────────────────────────────────┐
│ Broker Implementations │
│ Redis │ PostgreSQL │ RabbitMQ │ SQS │
└─────────────────────────────────────────────────────┘
│
┌─────────────────────────────────────────────────────┐
│ Protocol Layer │
│ (Celery v2/v5 Format) │
└─────────────────────────────────────────────────────┘
Workflow Primitives
Chain - Sequential Execution
use *;
let workflow = new
.then
.then
.then;
let task_id = workflow.apply.await?;
Group - Parallel Execution
let workflow = new
.add
.add
.add;
let group_id = workflow.apply.await?;
Chord - Map-Reduce
let header = new
.add
.add
.add;
let callback = new;
let chord = new;
let chord_id = chord.apply.await?;
Broker Support
Redis (Recommended)
use RedisBroker;
let broker = new?;
// With priority queue
let broker = with_mode?;
Pros:
- Fast (50K+ tasks/sec)
- Simple setup
- Priority queues
- Batch operations
Cons:
- In-memory (data loss on crash)
- Limited durability
PostgreSQL
use PostgresBroker;
let broker = new.await?;
Pros:
- Durable (ACID guarantees)
- Transactional
- Already using PostgreSQL
Cons:
- Slower than Redis
- Higher latency
Performance
Throughput Comparison
| Implementation | Throughput | Latency | Memory |
|---|---|---|---|
| Python Celery | 1K tasks/sec | 10ms | 50MB |
| CeleRS | 50K tasks/sec | 0.2ms | 10MB |
| CeleRS (batch) | 100K tasks/sec | 0.1ms | 10MB |
Performance Tips
-
Enable Batch Operations
let config = WorkerConfig ; -
Tune Concurrency
// CPU-bound: concurrency = cores // I/O-bound: concurrency = cores * 4 let config = WorkerConfig ; -
Use Redis for High Throughput
[] = { = "0.1", = ["redis"] }
Monitoring
Prometheus Metrics
use gather_metrics;
use TcpListener;
// Expose metrics endpoint
let listener = bind.await?;
loop
Available metrics:
celers_tasks_enqueued_totalcelers_tasks_completed_totalcelers_tasks_failed_totalcelers_task_execution_secondscelers_queue_size- 20+ more metrics
Structured Logging
use tracing_subscriber;
// Initialize logging
init;
// Worker automatically logs:
// - Task start/completion
// - Errors and retries
// - Queue operations
Python Celery Interoperability
Send from Rust, Execute in Python
// Rust: Enqueue task for Python worker
let task = new;
broker.enqueue.await?;
# Python: Execute task
=
return
Send from Python, Execute in Rust
# Python: Enqueue task for Rust worker
=
// Rust: Execute task
registry.register;
Error Handling
Automatic Retries
let config = WorkerConfig ;
Retry strategy:
- Retry 0: 1 second
- Retry 1: 2 seconds
- Retry 2: 4 seconds
- Retry 3: 8 seconds
- After max retries → Dead Letter Queue
Dead Letter Queue
// Tasks exceeding max_retries automatically moved to DLQ
// Inspect DLQ
let dlq_size = broker.dlq_size.await?;
// Replay failed tasks
broker.replay_dlq.await?;
// Clear DLQ
broker.clear_dlq.await?;
Graceful Shutdown
use wait_for_signal;
let worker = new;
let handle = worker.run_with_shutdown.await?;
// Wait for SIGTERM/SIGINT
wait_for_signal.await;
// Gracefully shutdown
handle.shutdown.await?;
Production Deployment
Recommended Configuration
let config = WorkerConfig ;
Docker Deployment
FROM rust:1.70 AS builder
WORKDIR /app
COPY . .
RUN cargo build --release --features redis,metrics
FROM debian:bullseye-slim
RUN apt-get update && apt-get install -y ca-certificates
COPY --from=builder /app/target/release/worker /usr/local/bin/
CMD ["worker"]
Kubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
name: celers-worker
spec:
replicas: 4
template:
spec:
containers:
- name: worker
image: myapp/celers-worker:latest
env:
- name: REDIS_URL
value: redis://redis:6379
resources:
limits:
memory: "512Mi"
cpu: "1000m"
Examples
See examples/ directory:
phase1_complete.rs- Complete worker setupgraceful_shutdown.rs- Graceful shutdownpriority_queue.rs- Priority queuesdead_letter_queue.rs- DLQ managementtask_cancellation.rs- Task cancellationprometheus_metrics.rs- Metrics exportcanvas_workflows.rs- Workflow primitives
Modules
| Module | Description |
|---|---|
prelude |
Common imports (use celers::prelude::*) |
error |
Error types |
protocol |
Protocol types (advanced) |
canvas |
Workflow primitives |
worker |
Worker runtime |
Comparison with Celery
| Feature | Python Celery | CeleRS |
|---|---|---|
| Language | Python | Rust |
| Performance | 1K tasks/sec | 50K+ tasks/sec |
| Memory | 50MB+ | 10MB |
| Type Safety | Runtime | Compile-time |
| Concurrency | Threading/multiprocessing | Async/await (Tokio) |
| Protocol | Celery v2/v5 | ✅ Compatible |
| Workflows | Chain/Group/Chord | ✅ Compatible |
| Brokers | Redis/RabbitMQ/SQS | ✅ Compatible |
Roadmap
- Core task execution
- Redis broker
- PostgreSQL broker
- Canvas workflows (Chain, Group, Chord)
- Prometheus metrics
- Batch operations
- Memory optimization
- RabbitMQ broker
- AWS SQS broker
- OpenTelemetry tracing
- Web UI dashboard
- Distributed tracing
Contributing
See CONTRIBUTING.md for contribution guidelines.
Community
- Issues: GitHub Issues
- Discussions: GitHub Discussions
License
MIT OR Apache-2.0
See Also
- Celery: https://docs.celeryproject.org/
- Tokio: https://tokio.rs/
- Redis: https://redis.io/