Caching Bug in Next.js Badge App Triggered Duplicate GitHub API Calls Under Load
A developer discovered a 'thundering herd' bug in CommitPulse, a Next.js app that renders GitHub contribution data as SVG badges. Although the cache functioned correctly for sequential requests, multiple concurrent requests for the same username each independently checked the cache, all found a miss, and all fired separate calls to GitHub's API before any response had returned. This pattern becomes costly because GitHub's GraphQL API enforces a rate limit of 5,000 points per hour, and a traffic spike — such as a trending repository or Hacker News post — can trigger dozens of simultaneous identical upstream requests. The root cause is the absence of in-flight request deduplication: the cache only prevents redundant calls after a response is stored, not while the first fetch is still pending. The fix involves tracking in-progress Promises in a separate Map so that any concurrent request for the same key awaits the already-running fetch instead of launching a new one.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in