- Home
- Skills
- APIs & Backend
- Cache Stampede & TTL Drift Surgeon
Works with the AI Agents you already use
Cache Stampede & TTL Drift Surgeon
by Badung
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
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
| ID | Class | Location | Observed Behavior | Candidate Fix |
|---|---|---|---|---|
| F1 | CS-1 | src/services/productCache.ts:18 | Concurrent misses call db.product.findUnique simultaneously | Add in-process Map for promise deduplication |
| F2 | CS-2 | src/services/productCache.ts:24 | Fixed EX: 3600 causes hourly origin spikes | Implement ±15% TTL jitter |
| F3 | CS-3 | src/services/productCache.ts:24 | Unconditional SET can overwrite newer DEL operations | Add 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
- Run
npm test -- tests/productCache.stampede.spec.tsto verify coalescing. - Monitor Redis
INFO statsto confirm jittered expiry distribution. - 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
- Source Inspection records every cache store and layer including Redis, Memcached, and in-memory providers.
- Failure Classification maps findings to specific reliability classes like Cold-Key Stampedes or Synchronized Expiry.
- Patch Generation produces minimal, reversible code diffs using patterns like TTL jitter and probabilistic refresh.
- 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
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
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 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.
Trust & safety
Security scan
Security scan passed 11 days ago
Requires
Nothing to install.
Permissions
What's inside
Frequently Asked Questions
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.