How would you approach caching within a microservices architecture, and what are the pitfalls of shared cache state?
Last updated
Cache at the gateway or client (HTTP
Cache-Control, CDNs) and per service (local orRedis) using cache-aside or read/write-through. Invalidate with TTLs plus event-driven eviction.Shared cache pitfalls: hidden coupling and schema lock-in, no clear invalidation owner (so stale data lingers), and a single point of failure or contention hotspot.
Prefer private per-service caches, or namespaced keys with one writer per key. Design for stale reads and stampedes (locks, request coalescing, jittered TTLs).