How is distributed cache better than in-process cache

In-process cache like ehcache, jcs can be a bit faster than distributed cache engines like redis, memcached but they can never scale up.

Here is the brief comparison betweent the two

ConsiderationsIn-process CacheDistributed Cache
ConsistencyYour cache elements are local to your application. Large application will be load balanced across multiple instances each having a different state of cache resulting in inconsistencyIt offers a single logical view of the cache. In most cases, an object is stored in a single node by means of hashing algorithm. No data inconsistency
OverheadsIt can negatively effect performance of application due to garbage collection overheads. It depends on size of cache and how quickly are objects evictedIt will have no such overheads. But if will be slightly slower due to network latency and object serialization
ReliabilityIt makes use of same heap memory so you need to be careful for determining upper limit for cache memory. If your program runs out of memory, there is no easy way to recoverIt runs as independent process across multiple nodes. So even failure of single node does not result in complete failure of the cache. Failover’s worst case is degraded performance as opposed to complete failure

Leave a Reply

Your email address will not be published. Required fields are marked *