A. NADEEM  /  KUALA LUMPUR
Back to portfolio
03Selected work

GreyQueue — Distributed Job Engine

v1.0 completePostgreSQLFastAPIPython

What it does

GreyQueue is a background-job engine. You submit a job through an API, Postgres stores it, a free worker claims it from the queue, and the result gets saved.

The point is what happens when things go wrong. If a worker dies halfway through, its lease runs out and another worker picks the job up. Fencing means the worker that died can’t come back later and overwrite the new result. Jobs that fail retry with backoff, and the ones that keep failing end up in a dead-letter list I can look through.

Delivery is at-least-once within a bounded retry budget: a job can run more than once after a crash, or use up its retries without ever succeeding, so anything with outside side effects needs its own idempotency key. I built it without Celery or a managed broker on purpose, so the queue mechanics are all in plain view.

In the recorded crash experiments, a worker killed mid-job and a coordinator killed and restarted both left the job’s lease to expire, and the retry succeeded. Two coordinators running at once produced no duplicate successes across 30 jobs, a job that kept timing out ended in the dead-letter list after 3 attempts, and a full queue turned extra work away with HTTP 429.

On one machine with three workers of two slots each, a 10,000-job run of small hashing jobs averaged about 38 jobs a second (29 September 2026) and a 1,000-job mixed CPU and I/O run about 44 a second (16 September 2026, the v1.0 recording), both with no failures or retries. These are single local runs of different workloads. Three repeat runs of the 10,000-job workload varied by up to about 25% (their medians were about 29 a second), so the figures can’t be compared with each other and aren’t capacity figures.

What it’s built with

Python 3.12 and FastAPI for the API, SQLAlchemy, psycopg and Alembic on PostgreSQL 18, Docker Compose for running several workers, Prometheus-style metrics, and a simple HTML and JavaScript dashboard for operations. There are 71 automated tests, 35 of them against a real Postgres, plus crash experiments and a benchmark suite you can rerun. It grew over seven milestones, from basic durable execution through scheduling, crash recovery, metrics and multiple coordinators.

Who it’s for

Engineers who want to see how a durable queue really behaves: leases, retries, crash recovery and the places where a job can still run twice, instead of trusting a black box. It’s a readable reference implementation, not something to drop into production.

This is a portfolio project, not a hardened service. TLS, database backups and replication, high availability and production alerting are out of scope: it exposes metrics and ships sample Prometheus and Grafana configs, but nothing is set up to watch them in production. The throughput numbers come from a single machine, so treat them as observations, not guarantees.

GreyQueue source, architecture and design docs

Interested? Get in touch or grab the CV.