WhiskyPay Workers Architecture
This page provides a detailed technical explanation of how the WhiskyPay Workers system is designed and operates.System Overview
The WhiskyPay Workers system implements a distributed job processing architecture using a producer-consumer pattern. It consists of three main components:- Job Producers: Services that create jobs (primarily the Payment Gateway)
- Job Queues: Redis-backed queues that store pending jobs
- Job Consumers: Worker processes that execute the jobs
Technology Stack
The Workers system is built with:- Node.js: Runtime environment for JavaScript
- TypeScript: Type-safe development
- BullMQ: Modern Redis-based queue for Node.js
- IORedis: Redis client for Node.js with robust features
- Nodemailer: Email sending library for Node.js
Architectural Components
1. Redis Queue Storage
Redis serves as the central job storage mechanism:- Pending jobs waiting to be processed
- Active jobs currently being processed
- Completed jobs (temporarily, for tracking)
- Failed jobs and their error information
- Job progress and metadata
2. Queue Structure
The system uses two separate queues:3. Worker Implementation
The worker implementation follows this pattern:4. Connection Management
The workers establish a persistent connection to Redis with resilient error handling:Job Processing Flow
1. Job Creation
When a payment is successfully verified, the Payment Gateway creates jobs:2. Job Execution
Workers process jobs from their queues:- Job is retrieved from the queue
- Worker executes the job function
- On success, job is marked complete
- On failure, job is retried according to the configured retry strategy
3. Error Handling
The system implements sophisticated error handling:Scaling Strategies
The Workers system can be scaled in several ways:1. Vertical Scaling
Increase resources (CPU/memory) for the worker processes.2. Horizontal Scaling
Run multiple worker instances processing from the same queues:3. Concurrency Control
Control how many jobs each worker processes concurrently:Monitoring and Observability
The system provides several monitoring options:1. Basic Logging
2. Job Status Tracking
The BullMQ API offers methods to track job status:Security Considerations
The Workers system implements several security measures:- Authentication: Redis connection with optional authentication
- Environment Isolation: Sensitive data in environment variables
- Input Validation: Validation of job data before processing
- Error Isolation: Failed jobs don’t affect other jobs