The "Thundering Herd" Problem
We've all been there. You have an expensive endpoint—maybe a complex database aggregation or a third-party API call. It takes 500ms to execute.
Suddenly, 100 users hit that endpoint at the exact same moment.
Without Hogo:
- ❌ Your database gets hammered with 100 simultaneous queries.
- ❌ Your event loop lags.
- ❌ Memory usage spikes as 100 response objects are buffered.
- ❌ Users wait 500ms + overhead.
Enter Hogo 🛡️
Hogo is a new zero-dependency Node.js framework that implements the SingleFlight pattern (made famous by Go) directly into its core.
It uses Atomic Coalescing to manage concurrent identical requests.
With Hogo:
- ✅ 1 database query executes.
- ✅ 99 requests "wait" for the result of the first one.
- ✅ All 100 users get the exact same response at the same time.
- ✅ CPU and memory usage remain flat.
How It Works
Hogo tracks "flights" based on the request method and URL. If a flight is already in the air (processing), subsequent identical requests attach themselves as passengers to that flight instead of launching their own.
import { Hogo } from 'hogo';
const app = new Hogo();
// This handler will run ONLY ONCE if 100 requests hit it simultaneously
app.get('/expensive-data', async (ship) => {
const data = await db.heavyAggregation();
return ship.json(data);
});
app.ignite(3000);
Benchmarks
In our tests simulating 1000 concurrent requests:
- Traditional Framework: 1000 DB queries, High CPU spike.
- Hogo: 1 DB query, Low CPU.
It's not just caching (which has TTLs and invalidation logic). It's live deduplication. If no one is asking, nothing is calculated. If 1000 people ask, it's calculated once.
Getting Started
Hogo is lightweight and has zero dependencies.
npm install hogo
Give it a try and let me know what you think!
🔗 NPM: https://www.npmjs.com/package/hogo
🔗 GitHub: https://github.com/hogo-js/hogo
Top comments (0)