Back to KB
Difficulty
Intermediate
Read Time
38 min

How We Built a 3-Tier Node.js Cache That Hits 2.8M ops/sec (And Never Drops a Key on Eviction)

By Codcompass Team··38 min read

Caching in Node.js usually forces a frustrating compromise. You either stick with a basic in-memory Map (or LRU-cache) that risks running your process out of memory (OOM) under heavy loads, or you accept the network latency floor and serialization overhead of a standalone Redis/Valkey instance.

When building high-throughput systems, neither option feels entirely right. A localhost Redis round-trip is fast, but it’s still bounded by networking stacks.

We built tricache to eliminate this compromise completely. It’s an open-source, three-tier caching engine for Node.js designed to maximize raw single-threaded throughput while implementing protective guardrails like automated disk spilling, thundering-herd prevention, and an integrated WebAssembly Bloom filter.

The result? 2.81 million read operations per second from a single thread—over 100× faster than a local Redis round-trip—without the risk of unbounded RAM growth.

Here is a look under the hood at how it works and the architectural decisions that made it happen.


The 3-Tier Architecture

To achieve high hit rates without risking OOM crashes, tricache splits data management into three distinct layers:

  1. L1 (Smart Memory Cache): A blazing-fast, process-level memory layer built on top of a highly optimized V8 Map.
  2. L1.5 (Local Disk Spill): When the L1 memory cap (l1MaxBytes) or entry cap is reached, evicted entries aren't simply deleted. They spill over to a local, high-speed NVMe disk directory using optimized msgpackr binary serialization.
  3. L2 (Distributed Backplane): The shared remote tier (Redis or Valkey) used for multi-instance distributed sync.

Core Technical Features & Innovations

1. Advanced Hybrid Eviction

🎉 Mid-Year Sale — Unlock Full Article

Base plan from just $4.99/mo or $49/yr

Sign in to read the full article and unlock all 635+ tutorials.

Sign In / Register — Start Free Trial

7-day free trial · Cancel anytime · 30-day money-back