TQE — Distributed Task Queue Engine
High-throughput, fault-tolerant distributed task queue built from scratch with atomic Redis Lua scripts and PostgreSQL event sourcing.
30,149.5/min
Sustained Throughput
502.5 jobs/sec (3.0x over 10k target)
0.047%
Chaos Failure Rate
Under SIGKILL worker chaos testing
14.52 ms
Telemetry Latency (p99)
Pipelined Redis stats snapshot
2.10 s / 42.9 MB
Crash Recovery / RSS
100% (15/15) poison-job DLQ isolation
The Problem
Off-the-shelf task queues abstract away hard distributed-systems trade-offs: race conditions during lease expiry, duplicate retries, Redis memory loss, and bloated worker processes.
What I Built
Built an entire distributed task queue engine from first principles—no Celery, RQ, or Dramatiq. Implemented 10 atomic Redis Lua state transitions, cryptographic lease-fencing tokens, dual-write PostgreSQL event sourcing, leader-elected recovery, a FastAPI control plane, and a sub-second Streamlit telemetry UI.
Technical Architecture
Clients submit jobs via FastAPI (dual-writing Postgres + atomic Redis enqueue). Lean asyncio workers (42.94 MB RSS) claim tasks via Lua scripts using IEEE 754 exact float64 priority scores (P*10^14 + T) and lease tokens, while a Redis Streams Persister batches lifecycle events to Postgres and a leader-elected Scheduler reaps expired leases and reconciles cold restarts.
Dual-Write API Gateway
FastAPI validates idempotency keys, writes Postgres audit truth, and calls atomic enqueue Lua.
10 Atomic Redis Lua Scripts
Single-roundtrip ZSET transitions using server TIME and float64 priority+FIFO scoring.
Lease-Fenced Worker Fleet
42.94 MB RSS asyncio workers; graceful SIGTERM release preserves retry budgets.
Persister & Leader Reconciler
XREADGROUP consumer batches events to Postgres; Reconciler recovers from Redis FLUSHALL.
Verification & Key Takeaways
- 50+ worker containers run comfortably on a single laptop thanks to strict worker import isolation.
- 48 passing unit, integration, and chaos tests verifying lease fencing, redelivery, and DLQ isolation.
- Zero burned retries on graceful shutdown by decrementing attempt counts when releasing in-flight jobs.