Share cache between microservices with Kubernetes and sping boot

9/3/2020

How can I share the Spring cache between replicated microservices in kubernetes? Which technology should I use? The solution should be able to support an high available configuration (e.g.: master/slave; active-active DR and so on).

Please provide the spring boot configuration as well if possible.

-- Fabry
java
kubernetes
spring
spring-boot

1 Answer

9/3/2020

Spring cache has a concept of cache providers - technologies standing behind the caching implementation.

By default the cache is implemented in-memory, so its not replicated in any manner. However you can configure it to run, say, with Redis. See this tutorial for technical implementation aspects

In this case the same redis instance should be accessible from all kubernetes nodes running the pod of your application and you will have distributed cache.

Depending on your actual needs you can also check the integration with EHcache or Hazelcast. I'm sure other options also exist but this should give a direction.

-- Mark Bramnik
Source: StackOverflow