.NET Architecture & System Design Interview Question #28
What is the difference between in-memory cache and distributed cache?
Caching, CDN, Queues & Asynchronous Processing Junior Beginner
Quick Interview Answer
An in-memory cache stores data inside one application process. It is extremely fast but each application instance has its own cache and the data disappears when that process stops.
Detailed Explanation
An in-memory cache stores data inside one application process. It is extremely fast but each application instance has its own cache and the data disappears when that process stops.
A distributed cache is shared by multiple application instances through an external system such as Redis. It supports horizontal scaling and shared cached state, but adds network latency and another operational dependency.
Code Example
In-memory:
App A -> Memory A
App B -> Memory B
Distributed:
App A -- -> Redis
App B --/