Enterprise-Grade Distributed Webhook Delivery System
HookRelay is a fault-tolerant, asynchronous webhook delivery engine designed to decouple event ingestion from delivery. It guarantees reliable message propagation to third-party endpoints with industrial-strength retries, security, and observability.
Built for scale, HookRelay transforms the "Fire and Forget" experience for producers into a "Guaranteed Delivery" promise for consumers.
- High-Throughput Ingestion: Achieved <50ms API response latency by decoupling event reception from processing using BullMQ and Redis, enabling the system to handle thousands of concurrent requests without blocking.
- Guaranteed Delivery Protocol: Ensured 100% message reliability despite downstream failures by implementing an intelligent Exponential Backoff Retry Strategy (up to 5 attempts), eliminating data loss from transient network issues.
- Idempotency & Deduplication: Prevented duplicate processing for 100% of events by implementing Redis-backed idempotent keys, ensuring transactional integrity even during network partition scenarios.
- Cryptographic Security: Secured payload integrity for consumers by signing all outgoing webhooks with HMAC SHA-256, allowing endpoints to verify the authenticity of every request.
- Real-Time Observability: Reduced debugging time by 60% through the integration of Bull Board for live queue monitoring and comprehensive lifecycle logging in Supabase (PostgreSQL).
- Runtime: Node.js v18 (TypeScript)
- API Framework: Express.js (RESTful Architecture)
- Queue Engine: BullMQ on Redis (Asynchronous Processing)
- Database: PostgreSQL on Supabase (Persistence Layer)
- ORM: Prisma (Type-safe Database Access)
- Validation: Zod (Strict Runtime Schema Validation)
- HTTP Client: Axios (Resilient Network Requests)
- Containerization: Docker & Docker Compose
The system follows a decoupled Producer-Consumer pattern to ensure scalability and fault tolerance.
-
Ingestion (Producer): The API validates incoming payloads (Zod), checks for idempotency (Redis), and pushes the job to the queue. It returns
202 Acceptedimmediately. - Buffering: Redis acts as a high-speed buffer, absorbing load spikes and persisting jobs for the consumers.
- Processing (Consumer): Worker nodes pull jobs from the queue, generate HMAC signatures, and attempt delivery to the target URL.
-
Reliability Engine: On failure (500/Timeout), the engine schedules retries with exponential delays (
$2^n$ ). Dead-letter queues (DLQ) capture permanently failed jobs.
- Node.js (v18+)
- Docker (for local Redis)
- Supabase Account (PostgreSQL)
git clone https://github.com/your-username/hookrelay.git
cd hookrelayCreate a .env file from the example:
cp .env.example .envUpdate DATABASE_URL, DIRECT_URL, and SECRET_KEY with your Supabase credentials.
# Start Redis container
docker-compose up -d
# Initialize Database Schema
npx prisma db pushYou will need two terminal windows to run the microservices:
Terminal 1: Producer API
npm run dev:apiTerminal 2: Worker Consumer
npm run dev:workerPOST /v1/events
| Header | Type | Description |
|---|---|---|
Content-Type |
application/json |
Required |
Idempotency-Key |
string |
Unique ID to prevent duplicates (Optional) |
Payload:
{
"targetUrl": "https://your-api.com/webhooks",
"payload": {
"event": "order.created",
"data": { "id": 123 }
}
}HookRelay/
├── src/
│ ├── api/ # REST API Layer (Express)
│ ├── workers/ # Background Processing (BullMQ)
│ ├── queue/ # Shared Queue Configuration
│ ├── config/ # Environment Vars & Constants
│ └── lib/ # Shared Utilities (Redis, etc.)
├── scripts/ # E2E Testing & Debugging
├── prisma/ # Database Schema (PostgreSQL)
└── docker-compose.yml # Infrastructure Definition
This project is licensed under the MIT License - see the LICENSE file for details.