npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vectorflux

v1.0.0

Published

Production-grade TypeScript rate limiting library with Token Bucket, Fixed Window, Sliding Window algorithms and Redis Lua support.

Downloads

202

Readme

🚀 VectorFlux

Production-grade TypeScript rate limiting library with multiple algorithms, Redis Lua atomicity, and framework-agnostic middleware support.

VectorFlux provides high-performance, scalable, and distributed rate limiting with a clean, type-safe API.


✨ Features

  • ⚡ Multiple rate limiting algorithms:

    • Token Bucket
    • Fixed Window Counter
    • Sliding Window Log
  • 🧠 Multiple storage adapters:

    • In-memory storage
    • Redis storage
  • 🔒 Redis Lua scripts for atomic operations

  • 🚀 Distributed and concurrency-safe rate limiting

  • 🌐 Framework middleware support:

    • Express
    • Fastify
    • Hono
  • 📦 Fully written in TypeScript with complete type definitions

  • 🧪 Comprehensive testing:

    • 45+ automated tests
    • Unit tests
    • Redis integration tests
    • Concurrency tests
    • Middleware tests
  • 📊 Built-in benchmark suite

  • 🔄 GitHub Actions CI/CD pipeline


Installation

Core

npm install vectorflux

Optional integrations

Redis

npm install ioredis

Express

npm install express

Fastify

npm install fastify

Hono

npm install hono

Quick Start

Token Bucket

import {
  VectorFlux,
  MemoryAdapter
} from "vectorflux";


const limiter = new VectorFlux({
  algorithm: "token-bucket",

  adapter: new MemoryAdapter(),

  limit: 10,

  refillRate: 1
});


const result = await limiter.check(
  "user:123"
);

console.log(result);

Response Format

{
  allowed: true,
  limit: 10,
  remaining: 9,
  resetAt: 1712345678900,
  retryAfter: 0
}

Available Algorithms

Token Bucket

Best for smooth traffic handling.

Use cases:

  • Public APIs
  • Authentication endpoints
  • User request throttling

Fixed Window Counter

Simple and memory-efficient.

Use cases:

  • Login limits
  • Basic API throttling
  • Admin panels

Sliding Window Log

Provides more accurate limiting over a rolling time window.

Use cases:

  • Payment APIs
  • Critical services
  • High traffic endpoints

Redis Example

import Redis from "ioredis";

import {
  VectorFlux,
  RedisAdapter
} from "vectorflux";


const redis = new Redis();

const limiter = new VectorFlux({
  algorithm: "sliding-window",

  adapter: new RedisAdapter(redis),

  limit: 100,

  window: 60000
});

Middleware Examples

Express

app.use(
  rateLimit({
    limiter
  })
);

Fastify

app.addHook(
  "preHandler",
  fastifyRateLimit({
    limiter
  })
);

Hono

app.use(
  "*",
  honoRateLimit({
    limiter
  })
);

Why Redis Lua?

Traditional Redis operations can suffer from race conditions when multiple servers process requests simultaneously.

VectorFlux executes rate limiting operations using Redis Lua scripts, guaranteeing:

  • Atomic execution
  • Correct request counting
  • Consistent distributed behavior
  • Concurrency safety

Architecture

                    Application
                         |
                         v
                  VectorFlux Core
                         |
       ---------------------------------------
       |                                     |
       v                                     v
 Memory Adapter                       Redis Adapter
       |                                     |
 JavaScript Maps                    Redis Lua Scripts
       |                                     |
       ---------------------------------------
                         |
                         v
              Rate Limiting Algorithms

             • Token Bucket
             • Fixed Window
             • Sliding Window

Performance Benchmarks

Benchmarks were executed on an Apple Silicon MacBook Air using Node.js v25.

| Test | Result | | -------------------- | --------------------: | | Memory Fixed Window | ~4.9 million ops/sec | | Memory Token Bucket | ~4.0 million ops/sec | | Redis Token Bucket | ~10K ops/sec | | Redis Fixed Window | ~10K ops/sec | | Redis Sliding Window | ~9.8K ops/sec | | Redis Concurrency | 100K requests in 1.5s | | High Cardinality | 100K users in 49ms | | Burst Traffic | 10K requests in 107ms |

Detailed benchmark results are available in benchmarks/RESULTS.md.


Testing

Run the complete test suite:

npm test

Run type checks:

npm run typecheck

Build package:

npm run build

Roadmap

Future improvements:

  • [ ] Redis Cluster support
  • [ ] Additional adapters (MongoDB, PostgreSQL, etc.)
  • [ ] Custom metrics and monitoring hooks
  • [ ] Rate limit analytics dashboard
  • [ ] Further Sliding Window memory optimizations

Contributing

Contributions, bug reports, and feature requests are welcome.

Feel free to open an issue or submit a pull request.


License

MIT License.


Built with ❤️ using TypeScript, Redis, and Lua.