Works with the AI Agents you already use

    Cache Stampede & TTL Drift Surgeon

    by Badung

    1

    Audits Redis, Memcached and framework caches for thundering-herd stampedes, synchronized TTL expiry, stale cache-aside overwrites and error storms, then hands back bounded patches and local load tests.

    $3.99

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Cache Stampede & TTL Drift Surgeon

    Cache Stampede & TTL Drift Surgeon

    Example session with this skill installed

    Our Redis product cache gets hammered every hour on the dot. Sometimes old prices stick in the cache after an update. Check src/services/productCache.ts and give me a safe patch.

    • Read your context and instructions
    • Compiled the cache stampede

    I have audited src/services/productCache.ts for stampede risks and stale-write race conditions. The audit identified fixed TTL expiry and a lack of request coalescing.

    Cache Reliability Audit

    1. Audit Summary & Verdict

    Verdict: STAMPEDE RISK + STALE-WRITE RISK
    Inspected src/services/productCache.ts. Verified fixed 3600s TTLs and un-guarded cache-aside logic.

    2. Findings Table

    IDClassLocationObserved BehaviorCandidate Fix
    F1CS-1src/services/productCache.ts:18Concurrent misses call db.product.findUnique simultaneouslyAdd in-process Map for promise deduplication
    F2CS-2src/services/productCache.ts:24Fixed EX: 3600 causes hourly origin spikesImplement ±15% TTL jitter
    F3CS-3src/services/productCache.ts:24Unconditional SET can overwrite newer DEL operationsAdd schema versioning to keys

    3. Candidate Patch

    const inFlight = new Map<string, Promise<Product | null>>();
    
    function getJitteredTtl(base: number = 3600): number {
      return Math.round(base * (0.85 + Math.random() * 0.3));
    }
    
    export async function getProductCached(id: string): Promise<Product | null> {
      const key = `v2:product:${id}`;
      const cached = await redis.get(key);
      if (cached) return JSON.parse(cached);
    
      const existing = inFlight.get(key);
      if (existing) return existing;
    
      const loadPromise = (async () => {
        const product = await db.product.findUnique({ where: { id } });
        if (product) {
          await redis.set(key, JSON.stringify(product), 'EX', getJitteredTtl());
        }
        return product;
      })().finally(() => inFlight.delete(key));
    
      inFlight.set(key, loadPromise);
      return loadPromise;
    }
    

    Next steps

    1. Run npm test -- tests/productCache.stampede.spec.ts to verify coalescing.
    2. Monitor Redis INFO stats to confirm jittered expiry distribution.
    3. Deploy to staging to verify the v2: key prefix behavior.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    High traffic spikes often hide behind inefficient caching logic. When keys expire or concurrent requests miss the cache, origin databases face thundering-herd stampedes that can lead to total system failure. This skill audits your application caching layer to identify these patterns and provide targeted reliability patches.

    What it does

    • Identify Stampede Risks finds missing request coalescing or singleflight patterns where concurrent misses hammer the origin.
    • Detect TTL Drift flags synchronized expiry windows that cause periodic CPU bursts on your database or API.
    • Audit Stale Overwrites spots race conditions where readers write old data back into the cache after a writer has updated the source.
    • Verify Negative Caching checks if missing records or errors are causing uncached traffic storms to hit your backend.
    • Review Key Versioning ensures cache keys include necessary dimensions like schema version, locale, and tenant ID to prevent deployment drift.

    How it works

    1. Source Inspection records every cache store and layer including Redis, Memcached, and in-memory providers.
    2. Failure Classification maps findings to specific reliability classes like Cold-Key Stampedes or Synchronized Expiry.
    3. Patch Generation produces minimal, reversible code diffs using patterns like TTL jitter and probabilistic refresh.
    4. Local Verification provides deterministic test commands to verify the fixes under simulated concurrency.

    Frameworks & tools

    Works across Node.js, Python, and Go stacks using Redis, Valkey, Memcached, or Next.js caching. Supports libraries like React Query, asyncio, and standard cache-aside implementations.

    Why this beats prompting it yourself

    Generic prompts often suggest complex architectural changes like introducing new middleware. This skill focuses on narrow, line-by-line code fixes that resolve race conditions and stampedes within your existing logic.

    Use cases

    • Debugging database CPU spikes that align with specific cache TTL intervals.
    • Preventing stale data from persisting after administrative updates.
    • Hardening endpoints against bot-driven 404 storms that bypass cache.
    • Ensuring rolling deployments do not crash due to cached schema mismatches.

    Known limitations

    Does not verify production-only settings like Redis maxmemory policies or real-world network latency. Requires manual verification of live concurrency limits.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Frequently Asked Questions

    This skill identifies and patches 'thundering-herd' scenarios where concurrent cache misses overwhelm your database, as well as race conditions that cause stale data to be written back into your cache.

    It supports major backend ecosystems including Node.js, Python, and Go, and is compatible with caching providers like Redis, Memcached, and Next.js.

    You receive the full auditing logic, a suite of reliability patch templates for various frameworks, and deterministic test commands to verify fixes in your local environment.

    Simply point the skill to your application's caching logic or repository; it will automatically map your providers and identify specific failure classes without requiring architectural changes.

    No, the skill focuses on 'line-by-line' code fixes like TTL jitter and request coalescing, allowing you to harden your system within your current infrastructure.

    The skill provides localized fixes for logic-based race conditions, but it does not manage infrastructure-level settings like Redis memory policies or network-level latency.

    New in APIs & Backend

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.