Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use ehcache for application deployed via docker against the stateless rule

I have an spring-boot application which I would like to deploy it into multiple docker instances and there is a load balance before the instances. However, the application uses ehcache to cache some data from a database. It makes the application stateful. So without session sticky, a same customer might hit different docker instances and see different results. My question is if I can't apply session sticky in load balance, what is the best practice to deploy an app with cache feature via docker style and still comply the rule of should-be-stateless?

like image 827
alan Avatar asked Oct 14 '25 15:10

alan


2 Answers

I explain here in this devoxx video how clustered caching can help each of you docker instance share the same cache

like image 62
Anthony Dahanne Avatar answered Oct 17 '25 06:10

Anthony Dahanne


First of all, if you really have a pure caching use case, there should be no correctness impact only a performance one. Which of course can in itself be a bad thing for your application.

But effectively, if you want to use caching to provide performance and at the same time have a multi-node ability without sticky sessions, you have to move into the realm of distributed caching. This will give you the ability to share the cache content amongst the different nodes and thus make it (more) transparent for a given request in a conversation to hit any node of your application.

In the Ehcache world, this means backing the cache with a Terracotta server, see the documentation for details.

like image 24
Louis Jacomet Avatar answered Oct 17 '25 06:10

Louis Jacomet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!