Member-only story
Serve API Responses in Under 5ms: HybridCache in .NET
HybridCache is latest .NET ’s two-level caching API — L1 in-process memory for speed and Redis for scale.Here’s how to wire it up.
Paul Thomas10 min read·Just now--
Welcome back, dear readers! I’m thrilled to have you join me for another exciting post. Today, I have something special in store for you.
Upon one instance, I was profiling a .NET API that was hemorrhaging latency. The team had IMemoryCache everywhere = fast, reliable, battle-tested. Requests that hit the cache completed in under 2ms. But when we deployed a second instance behind a load balancer, things fell apart.
Instance A had the cache warm. Instance B didn’t. Depending on which box you landed on, the same endpoint took either 2ms or 400ms. Worse, after a deployment, both instances cold-started simultaneously, and every request hammered the database at once. The kind of traffic spike that makes a DBA send you a message at 7am.
We talked about switching to Redis. Pure distributed cache — consistent across all instances, survives restarts. But Redis adds 8–15ms of network overhead to every cache read. For a high-frequency endpoint, we’d traded one problem for another.