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

@asad-ahmed-saiyed/flashguard

v1.0.1

Published

High-performance request coalescing and cache stampede protection for distributed systems.

Downloads

36

Readme

⚡ FlashGuard

Stop the "Thundering Herd". Protect your distributed systems from traffic spikes.

FlashGuard is a high-performance request coalescing library for Node.js. It prevents Cache Stampedes by ensuring that only one request hits your database during a traffic spike, while thousands of other users wait for the result.

NPM Version License: MIT TypeScript

✨ Features

  • Request Coalescing: Single-flight execution to save your database.
  • Stale-While-Revalidate: Background updates for non-blocking freshness.
  • Distributed Locking: Safe execution across multiple fleet instances.
  • TypeScript Support: First-class typing included.

📦 Installation

npm install @asad-ahmed-saiyed/flashguard ioredis

(Note: ioredis is a required peer dependency).


🚀 Quick Start

Here is how to wrap your expensive database calls (like SQL queries or API requests) with FlashGuard.

import { FlashGuard, RedisDriver } from "@asad-ahmed-saiyed/flashguard";
import Redis from "ioredis";

// 1. Setup Redis Connection
const redis = new Redis(process.env.REDIS_URL);
const driver = new RedisDriver(redis);

// 2. Initialize FlashGuard
const guard = new FlashGuard(driver);

// 3. The Function You Want to Protect
async function getProductProfile(productId) {
  const cacheKey = `product:${productId}`;

  return await guard.fetch(
    cacheKey,
    async () => {
      // 🟢 THE "LEADER" WORK
      // This code runs ONLY ONCE, even if 1,000 users hit it at the same time.
      console.log("Fetching from Database...");
      // Assume 'db' is your database client
      return await db.query("SELECT * FROM products WHERE id = ?", [productId]);
    },
    {
      ttl: 60, // Cache data for 60 seconds
    }
  );
}

📊 Performance Benchmarks

Tests conducted under high-concurrency load (100 concurrent users) on resource-constrained hardware.

| Metric | ❌ Standard Redis | ✅ FlashGuard | Impact | | --- | --- | --- | --- | | Response Time (p95) | 1.31 s | 1.06 s | 19% Faster ⚡ | | Throughput | 104 req/sec | 132 req/sec | 27% More Capacity 📈 | | Database Load | 100 Calls | 1 Call | 99% Load Reduction 🛡️ |


⚙️ Configuration Options

| Option | Type | Default | Description | | --- | --- | --- | --- | | ttl | number | 60 | Time-To-Live: How long (in seconds) the data stays fresh in Redis. | | swr | number | 300 | Stale-While-Revalidate: Extra time (in seconds) to serve old data while fetching new data in the background. | | timeout | number | 10000 | Lock Timeout: Max time (ms) a "follower" waits for the "leader" to finish. |


🛡️ "Fail-Open" Design

If Redis crashes, FlashGuard automatically bypasses the cache and executes your function directly. This ensures your application never goes down just because the cache is offline.


📄 License

MIT