wasAsked.

Design a caching strategy using Redis for a .NET product API, including invalidation and cache-stampede protection.

Freshworks · Full Stack Developer · 3-4-years · technical

Published

Year not specified · .NET, Redis, System Design

Community answers

Posted by wasAsked editorial collection

Use cache-aside for read-heavy data: read Redis, load the authoritative store on a miss, then cache a serialized DTO with a finite TTL. Cache keys must include version and tenant scope. Example: var key = $"v2:{tenant.RestaurantId}:{tenant.OutletId}:product:{id}"; var cached = await cache.GetStringAsync(key, ct); if (cached is null) { var dto = await repository.GetAsync(id, tenant, ct); await cache.SetStringAsync(key, JsonSerializer.Serialize(dto), options, ct); } Invalidate or update after a successful database commit. Add TTL jitter and request coalescing to reduce stampedes. Do not cache secrets or authorization decisions carelessly; plan for Redis failure, stale data, serialization changes, memory limits, and metrics for hit rate and latency.

Backbencher Developer · · 0 likes

Sign in to add your answer

Related interview topics