⚙️ snerd-rust
A blazingly fast, brutally simple, zero-dependency async background job engine for Rust.
If you are tired of wrestling with heavy, bloated background job frameworks like Redis, Postgres tables, or RabbitMQ just to send a few emails in the background... well, you are in the right place.
snerd-rust is an embedded, polyglot-friendly background task queue that lives entirely in a single, perfectly OS-locked, append-only .log file on your file system. It was designed to bring the aggressive concurrency and lightweight footprint of Golang's snerd over to Rust's heavily optimized asynchronous ecosystem.
No databases. No external daemons. No nonsense.
🔥 Features
- Zero External Infrastructure: You don't need a Redis cluster. Your tasks are persisted directly to
.snerdata/tasks/tasks.logusing standard filesystem I/O. - Bulletproof File Locks: Safely scales across multiple processes! We utilize OS-level file-locking boundaries (
flock) to guarantee that your tasks are never corrupted, even if multiple instances of your app try to write simultaneously. - Asynchronous Tokio Core: Built natively on top of
tokio. Background workers process the queue without starving your main event loop. - Aggressive Compaction: Deleted tasks don't bloat your system.
snerd-rustruns background log compactions automatically once your queue hits safe threshold limits. - Dead-Letter Queue (DLQ): Built-in
maxRetrieslimits and hooks to elegantly catch and bury poison-pill tasks.
📦 Installation
Just add snerd-rust to your Cargo.toml:
[]
= "0.1.0"
Note: You will also need tokio (with full features) since snerd is entirely async.
🚀 Quickstart
It takes roughly 3 lines of code to spin up a queue and start firing background jobs.
use SnerdQueue;
use FileStore;
use RetryableTask;
use Duration;
async
🧠 Architecture Details
snerd-rust utilizes an Append-Only Log Model to achieve massive write speeds.
Instead of updating rows in a database, every time a task is enqueued, updated, or deleted, a brand new JSON line is instantly appended to the end of the log file.
When the SnerdQueue wakes up on its polling interval, it scans the log, maps out the absolute latest state of every task, and spawns parallel Tokio tasks for anything that is currently due (retry_after_time <= now).
If your file ever grows too large (default 20MB or >10k operations), snerd-rust atomically clones, shrinks, and replaces the file in the background (Log Compaction) to keep disk space minimal.
🤝 License
MIT License. Do whatever you want with it, just don't let your tasks die unhandled.