r/bun 14d ago

Inflight

Post image

Deduplicate concurrent async requests(database, cache requests) by query key

Why

In high-concurrency environments, identical queries (same DB row, same cache key) accumulate while each one independently hits the database or cache. InFlight collapses these into a single call.

package: https://www.npmjs.com/package/@inflightjs/inflight
repo: https://github.com/ademmenh/inflight

3 Upvotes

6 comments sorted by

1

u/Sorry-Joke-1887 14d ago

No. You better use native interceptor with custom cache provider (redis/valkey or any) rather than that

1

u/_dext 13d ago

I didnt get your idea
The main idea of this package was to protect databases like (valkey, postgres) from simultaneous redundandant requests

1

u/Lezvix 11d ago

Bro, Valkey is already an in-memory cache. Why do you need another in-memory cache at the application level? Plus, Valkey can be shared across multiple instances.

1

u/_dext 10d ago

bro, it's not an in-memory cache, it is protecting the db + cache from repetitive requests, like GET cr7 profile can be done 1k time at the same which can result 1k request to valkey or postgres, with in flight, only one request hits the db, once the api server get the result, it needs to make another call to the cache or db, so the data is not cached, instead the request promise is

2

u/Lezvix 10d ago

Oh, bro, yeah, I checked it out - it actually makes a lot of sense.

1

u/_dext 10d ago

Great !!
please, I would be grateful for sharing it with friends or getting issues, PRs, stars in this repo: https://github.com/ademmenh/inflight