Skip to main content

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:
  1. Job Producers: Services that create jobs (primarily the Payment Gateway)
  2. Job Queues: Redis-backed queues that store pending jobs
  3. 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:
Redis stores several types of data:
  • 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:
Each queue is independent and can be scaled separately according to workload requirements.

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:
  1. Job is retrieved from the queue
  2. Worker executes the job function
  3. On success, job is marked complete
  4. 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:
  1. Authentication: Redis connection with optional authentication
  2. Environment Isolation: Sensitive data in environment variables
  3. Input Validation: Validation of job data before processing
  4. Error Isolation: Failed jobs don’t affect other jobs

Deployment Architecture

In production, the recommended deployment architecture is:

Conclusion

The WhiskyPay Workers system provides a robust, scalable solution for handling asynchronous tasks related to payment processing. By separating these tasks from the main payment flow, it improves reliability and user experience while ensuring all notifications are delivered properly.