Back to Projects

Relay - Distributed Job Processing Platform

A production-grade backend job-processing platform designed for high-throughput, reliable asynchronous task execution, built to demonstrate advanced backend architecture and distributed systems patterns.

NestJSTypeScriptPostgreSQLBullMQRedisDocker

System Architecture & Scope

Relay is a production-grade backend job-processing platform designed for high-throughput, reliable asynchronous task execution. Built to demonstrate advanced backend architecture and distributed systems patterns, Relay processes jobs asynchronously with strong execution guarantees.

The core infrastructure relies on NestJS, PostgreSQL (with Prisma), Redis, and BullMQ, running fully containerized via Docker.

Key Engineering Achievements

Transactional Outbox Implementation

Engineered a robust outbox pattern to guarantee at-least-once job dispatch from the primary PostgreSQL database to the Redis message broker. This architectural decision completely eliminates dual-write inconsistencies and race conditions, ensuring no jobs are lost even if the message broker is temporarily down during job submission.

Idempotency & Concurrency Control

Enforced strict idempotency on job submission endpoints using a unique composite key constraint (`owner_id` + `idempotency_key`). This design prevents duplicate job executions even during concurrent requests, network retries, or dropped client connections.

Robust Background Processing

Integrated BullMQ for distributed job execution, featuring sophisticated error-handling strategies. Configured native exponential backoff for temporary network failures and built logic to immediately transition jobs to a Dead-Letter Queue (DLQ) state for unrecoverable errors, ensuring the main queue is not bottlenecked by failing jobs.

Reliability & Observability

Graceful Shutdown Mechanisms

Hooked into NestJS's lifecycle events to ensure running BullMQ workers correctly finish processing their active jobs and cleanly sever database connections before the container exits upon receiving a `SIGTERM` signal. This prevents zombie processes and corrupted job states during scaling or deployments.

End-to-End Observability

Designed a normalized database schema to track granular job attempts, latency metrics, and failure states persistently. This makes debugging and metric collection seamless via a RESTful API, providing full visibility into the lifecycle of every asynchronous task.