Skip to main content
Back to Portfolio ProjectsBhavya Gupta · Case Study
SystemsProduct / Tools

TQE — Distributed Task Queue Engine

High-throughput, fault-tolerant distributed task queue built from scratch with Python 3.12, Redis atomic Lua scripts, PostgreSQL event sourcing, and FastAPI.

Role
TODO: Confirm exact role (e.g., Solo Author / Systems Engineer)
Timeline
TODO: Add project timeline
Stack
Python 3.12 · Redis Lua (10 scripts) · PostgreSQL · FastAPI
Context
Distributed Systems · Custom Engine (No Celery/RQ/Dramatiq)

In plain English

Background job runners can silently drop tasks or double-execute work when workers crash or Redis restarts. TQE implements atomic Redis Lua transitions, cryptographic lease fencing, and PostgreSQL durable event sourcing from scratch so every task recovers cleanly under chaos.

30,149.5 jobs/min

Sustained Throughput

502.5 jobs/sec (3.0x the >=10,000 target)

0.047%

Chaos Failure Rate

Final failures under SIGKILL chaos (vs <0.5% target)

42.94 MB / 2.10 s

Worker RSS & Recovery

Per-worker footprint & redelivery after SIGKILL

100% / 14.52 ms

DLQ & Telemetry p99

15/15 poison jobs in DLQ · dashboard snapshot latency

The Problem

Production background job infrastructure requires strict priority scheduling, at-least-once delivery guarantees, crash recovery without lost state, and dead-letter isolation—yet heavyweight wrappers hide queue semantics and lease fencing bugs when workers fail mid-task.

What I Built

Engineered a complete distributed task queue engine and CLI without external queue frameworks: 10 single-roundtrip Redis Lua state transitions, asyncio workers isolated from database drivers (42.94 MB RSS), a FastAPI dual-write control plane, PostgreSQL WAL-style audit tables, leader-elected reaper/reconciler loops, and a real-time Streamlit telemetry dashboard.

Technical Architecture

API submissions dual-write jobs into PostgreSQL (with unique idempotency keys) before atomically enqueuing exact float64 priority scores (P×10¹⁴ + T) in Redis ZSETs; fenced workers claim via lease_token Lua scripts and emit lifecycle streams batched back to Postgres by a dedicated Persister while a leader Scheduler reaps expired leases and reconciles Redis state after restarts.

01

FastAPI Dual-Write Gate

Commits durable job records and idempotency keys in PostgreSQL before atomic Redis enqueue.

02

Redis Atomic Lua Hot Path

Executes 10 transitions (claim, ack, nack, lease extension, DLQ, promote, reap) atomically in server TIME.

03

Fenced Async Worker Fleet

Isolated 42.94 MB RSS asyncio workers heartbeat lease_tokens and release unburned attempts on SIGTERM.

04

Scheduler, Persister & Live UI

Leader reaper recovers crashes in 2.10 s, reconciles FLUSHALL state, and streams telemetry at 14.52 ms p99.

Evaluation & Key Takeaways

  • Built 10 single-roundtrip atomic Lua state scripts with exact IEEE 754 float64 priority+FIFO scoring (P×10¹⁴ + T) and cryptographic lease fencing.
  • Passed 48 unit & integration tests plus SIGKILL chaos benchmarks with zero DB dependencies inside worker containers (50+ workers fit in 2.1 GB).

Evaluation protocol

Validated with 48 unit/integration pytest tests, a chaos suite injecting SIGKILL crashes and poison tasks (tests/chaos/test_chaos.py), a sustained 15,000-job throughput benchmark (benchmarks/run_benchmark.py), and dashboard telemetry latency profiling (benchmarks/measure_dashboard_latency.py).

Limitations & next steps

Verified benchmarks run against single-host Docker Compose scaling (50 workers) with local Redis and PostgreSQL rather than multi-region network partitions or clustered Redis shards. TODO: Add Redis Sentinel / multi-node failover benchmarks.

Python 3.12Redis Lua (10 scripts)PostgreSQLFastAPIasyncioSQLAlchemy & AlembicStreamlitPytest

Want to walk through Distributed Task Queue?

Happy to discuss methodology, ablations, or engineering trade-offs over a quick call or email.