A fast, reliable Redis-backed per-group FIFO queue for Node + TypeScript with guaranteed job ordering and parallel processing across groups.
A fast, reliable Redis-backed per-group FIFO queue for Node + TypeScript with guaranteed job ordering and parallel processing across groups.
GroupMQ, Redis Group Queue
A fast, reliable Redis-backed per-group FIFO queue for Node + TypeScript with guaranteed job ordering and parallel processing across groups.
Website
·
Created by OpenPanel.devnpm i groupmq ioredis…'none', 'scheduler', or 'in-memory' methodsGroupMQ is heavily inspired by BullMQ, a fantastic library and one of the most popular Redis-based job queue libraries for Node.js. We've taken many core concepts and design patterns from BullMQ while adapting them for our specific use case of per-group FIFO processing.
orderMs timestamp-based ordering{ type: 'paint', data: { ... } } | { type: 'repair', data: { ... } }We're grateful to the BullMQ team for their excellent work and the foundation they've provided for the Redis job queue ecosystem.
While GroupMQ is inspired by BullMQ's design and concepts, we have also directly copied some code from BullMQ:
src/async-fifo-queue.ts - This file contains code copied from BullMQ's AsyncFifoQueue implementation. BullMQ's implementation is well-designed and fits our needs perfectly, so we've used it directly rather than reimplementing it.This code is used under the MIT License. The original copyright notice and license can be found at:
Original copyright: Copyright (c) Taskforce.sh and contributors
…Ordering Methods:
'none' - No ordering guarantees (fastest, zero overhead, no extra latency)'scheduler' - Redis buffering for large windows (≥1000ms, requires scheduler, adds latency)'in-memory' - Worker collection for small windows (50-500ms, no scheduler, adds latency per batch)See Ordering Methods for detailed comparison.
…When adding a job to the queue:
…Example with delay:
await queue.add({
groupId: 'user:123',
data: { action: 'send-reminder' },
delay: 3600000, // Run in 1 hour
});Example with specific time:
await queue.add({
groupId: 'user:123',
data: { action: 'scheduled-report' },
runAt: new Date('2025-12-31T23:59:59Z'),
});Workers support configurable concurrency to process multiple jobs in parallel from different groups:
const worker = new Worker({
queue,
concurrency: 8, // Process up to 8 jobs simultaneously
handler: async (job) => {
// Jobs from different groups can run in parallel
// Jobs from the same group still run sequentially
},
});Benefits:
Considerations:
Both Queue and Worker support optional logging for debugging and monitoring:
// Enable default logger
const queue = new Queue({
redis,
namespace: 'orders',
logger: true, // Logs to console with queue name prefix
});
const worker = new Worker({
queue,
logger: true, // Logs to console with worker name prefix
handler: async (job) => { /* ... */ },
});Custom logger:
Works out of the box with both pino and winston
import type { LoggerInterface } from 'groupmq';
const customLogger: LoggerInterface = {
debug: (msg: string, ...args: any[]) => { /* custom logging */ },
info: (msg: string, ...args: any[]) => { /* custom logging */ },
warn: (msg: string, ...args: any[]) => { /* custom logging */ },
error: (msg: string, ...args: any[]) => { /* custom logging */ },
};
const queue = new Queue({
redis,
namespace: 'orders',
logger: customLogger,
});What gets logged:
GroupMQ supports simple repeatable jobs using either a fixed interval (every) or a basic cron pattern (pattern). Repeats are materialized by a lightweight scheduler that runs as part of the worker's periodic cleanup cycle.
await queue.add({
groupId: 'reports',
data: { type: 'daily-summary' },
repeat: { every: 5000 }, // run every 5 seconds
});
const worker = new Worker({
queue,
handler: async (job) => {
// process...
},
// IMPORTANT: For timely repeats, run the scheduler frequently
cleanupIntervalMs: 1000, // { /* ... */ },
});⚠️ Fast repeats ( 1 const currentJobs = worker.getCurrentJobs(); // [{ job: ReservedJob, processingTimeMs: 1500 }, ...]
// Get worker metrics const metrics = worker.getWorkerMetrics(); // { jobsInProgress: 2, lastJobPickupTime: 1234567890, ... }
// Graceful shutdown await worker.close(gracefulTimeoutMs);
### Worker Events
Workers emit events that you can listen to:
```ts
worker.on('ready', () => {
console.log('Worker is ready');
});
worker.on('completed', (job: Job) => {
console.log('Job completed:', job.id);
});
worker.on('failed', (job: Job) => {
console.log('Job failed:', job.id, job.failedReason);
});
worker.on('error', (error: Error) => {
console.error('Worker error:', error);
});
worker.on('closed', () => {
console.log('Worker closed');
});
worker.on('graceful-timeout', (job: Job) => {
console.log('Job exceeded graceful timeout:', job.id);
});
// Remove event listeners
worker.off('completed', handler);
worker.removeAllListeners();GroupMQ provides a BullBoard adapter for visual monitoring and management:
import { createBullBoard } from '@bull-board/api';
import { ExpressAdapter } from '@bull-board/express';
import { BullBoardGroupMQAdapter } from 'groupmq';
import express from 'express';
const serverAdapter = new ExpressAdapter();
serverAdapter.setBasePath('/admin/queues');
createBullBoard({
queues: [
new BullBoardGroupMQAdapter(queue, {
displayName: 'Order Processing',
description: 'Processes customer orders',
readOnlyMode: false, // Allow job manipulation through UI
}),
],
serverAdapter,
});
const app = express();
app.use('/admin/queues', serverAdapter.getRouter());
app.listen(3000, () => {
console.log('BullBoard running at http://localhost:3000/admin/queues');
});
…
typescript
while (!stopping) {
// 1. Blocking reserve (waits for job, efficient)
const job = await queue.reserveBlocking(timeoutSec);
// 2. Process job synchronously
if (job) {
await processOne(job);
}
// 3. Periodic scheduler run (every schedulerIntervalMs)
await queue.runSchedulerOnce(); // Promotes delayed jobs, processes repeats
}For concurrency > 1 (parallel):
while (!stopping) {
// 1. Run lightweight scheduler periodically
await queue.runSchedulerOnce();
// 2. Try batch reservation if we have capacity
const capacity = concurrency - jobsInProgress.size;
if (capacity > 0) {
const jobs = await queue.reserveBatch(capacity);
// Process all jobs concurrently (fire and forget)
for (const job of jobs) {
void processOne(job);
}
}
// 3. Blocking reserve for remaining capacity
const job = await queue.reserveBlocking(blockingTimeoutSec);
if (job) {
void processOne(job); // Process async
}
}
…
typescript
score = (orderMs - baseEpoch) * 1000 + seq
…
bash
npm i
npm run build
npm testOptionally:
docker run --rm -p 6379:6379 redis:7No open issues yet, or sync has not completed.