Redis goes down
Requests keep moving
A circuit breaker skips the unhealthy L2 and getOrSet falls through to your loader. Your origin still has to be up.
Introducing LazyLayers 8.0. Faster reads, fewer Redis round trips, and more control over memory.
Explore what’s newLazyLayers Distributed cachingUpdated
As your application grows, every instance gets its own local cache. LazyLayers connects those instances through shared storage and an event bus.
Coordinate refreshes
With Redis L2, a per-key lease lets one instance run the loader while the others wait. They are woken over the event bus when the load finishes, and polling only covers a lost notification. The lease renews itself while a slow loader runs.
const cache = new LazyLayersCache({
l2: new RedisStore(redis),
eventBus: new RedisEventBus(redis, 'cache.invalidate'),
})
// 10,000 callers, one loader call
await cache.getOrSet(`user:${id}`, () => db.users.findById(id))
Share invalidations
Without a bus, other servers serve their old copy until it expires. With one, they hear about the write and drop or replace it. Delivery depends on the bus you choose.
delDrop one key on every server.patternDrop every key matching tenant:42:*.setSend the loaded value, so peers skip the database.Handle temporary failures
Dependencies fail. Here is what each failure does to a request, and the path LazyLayers takes instead.
Redis goes down
A circuit breaker skips the unhealthy L2 and getOrSet falls through to your loader. Your origin still has to be up.
The loader fails or stalls
With fail-safe on, a loader error or timeout returns the retained stale value, 30 seconds past expiry by default, instead of an error.
The bus disconnects
A bounded queue retries publishes through short event-bus interruptions. Long outages and restarts can still drop events.
Events arrive late or twice
Generation checks discard old invalidations and event IDs discard replays. This is per key, not a global ordering guarantee.
A cache stampede, or thundering herd, is many concurrent requests missing the same key at once, for example when a popular key expires or after a deploy, and all sending the same query to the database. The extra load slows the origin, which widens the window and lets more callers in.
Not on its own. It is per process, so four servers each make one loader call. With Redis L2, getOrSet also takes a per-key lease, so one instance loads the key and the others wait. With an event bus they are woken when the load finishes. Without one they poll every pollMs.
No. It is stampede protection. Redis failover, process pauses and loaders that ignore their abort signal can still allow overlapping origin work, so keep loaders read-only and pass the supplied AbortSignal to your database client.
After it commits. Invalidating first lets a concurrent loader read the old row and cache it again. Invalidation is separate from the database transaction, so an application that must retry a failed invalidation needs durable delivery of its own.
No. With MongoDB each instance keeps its own L1, and change streams carry invalidations between them. The Durable Object backend does provide a shared cache tier.