JSPM

  • Created
  • Published
  • Downloads 23
  • Score
    100M100P100Q57900F
  • License MIT

Base classes for implementing custom queues in redis under high load conditions based on nestjs.

Package Exports

  • power-queues

Readme

power-queues

High-Performance Redis Streams Queue for Node.js

Ultra-fast, fault-tolerant, Lua-optimized distributed task queue built on Redis Streams.
Supports bulk XADD, idempotent jobs, retries, DLQ, stuck-task recovery, batching, and consumer groups.
Designed for large-scale microservices, telemetry pipelines, and high-load systems.


๐Ÿ“š Documentation

Full documentation is available here:
๐Ÿ‘‰ https://power-queues.docs.ihor.bielchenko.com


๐Ÿš€ Features

  • โšก Bulk XADD โ€” send thousands of tasks in a single Redis call
  • ๐Ÿ” Retries & attempt tracking
  • ๐Ÿง  Idempotent job execution (Lua locks, TTL, start/done keys)
  • ๐Ÿงน Stuck task recovery (XAUTOCLAIM + Lua-based recovery)
  • ๐ŸŒ€ Consumer groups + batching
  • ๐Ÿ“ฅ Dead Letter Queue (DLQ)
  • ๐Ÿ” Stream trimming, approx/exact maxlen, minid window
  • ๐Ÿงฑ Fully async, high-throughput, production-ready

๐Ÿ“ฆ Installation

npm install power-queues

๐Ÿงช Quick Start

import { QueueService } from './queue.service';

const queue = new QueueService();

// Add tasks
await queue.addTasks('my_queue', [
  { payload: { foo: 'bar' } },
  { payload: { a: 1, b: 2 } },
]);

// Run worker
queue.runQueue();

๐Ÿ”ง Add Tasks (Bulk)

await queue.addTasks('mass_polling', largeArray, {
  approx: true,
  minidWindowMs: 30000,
  maxlen: largeArray.length,
});

๐Ÿ—๏ธ Worker Hooks

You can override:

  • onExecute
  • onSuccess
  • onError
  • onRetry
  • onBatchError
  • onSelected
  • onReady

Example:

async onExecute(id, payload) {
  console.log('executing', id, payload);
}

๐Ÿงฑ Architecture Overview

Producer โ†’ Redis Stream โ†’ Consumer Group โ†’ Worker โ†’ DLQ (optional)
  • Redis Streams store tasks
  • Lua scripts handle trimming, idempotency, stuck recovery
  • Workers fetch tasks via XREADGROUP or Lua select
  • Tasks executed, ACKed, or sent to DLQ

๐Ÿ—„๏ธ Dead Letter Queue (DLQ)

Failed tasks after workerMaxRetries automatically go to:

<stream>:dlq

๐Ÿงฉ Idempotency

Guaranteed by 3 keys:

  • doneKey
  • lockKey
  • startKey

This prevents double-execution during retries, crashes, or concurrency.


๐Ÿš€ Performance

  • 10,000+ XADDs/sec
  • Bulk mode: 50,000 operations in one request
  • Extremely low CPU usage due to Lua trimming

๐Ÿท๏ธ SEO Keywords

redis streams, redis queue, task queue, job queue, nodejs queue, nestjs queue,
bulk xadd, distributed queue system, background jobs, retries, dlq,
idempotency, redis lua scripts, microservices, high-performance queue,
high-throughput, batching, concurrency control

๐Ÿ“œ License

MIT