4

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?

alan
  • 69
  • 6
  • The cache should be just an optimisation, your users should see the same think regardless of the instance they hit. Rethink your app design or provide us more data. – Constantin Galbenu Apr 21 '17 at 03:50

3 Answers3

1

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.

Louis Jacomet
  • 13,661
  • 2
  • 34
  • 43
1

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

Anthony Dahanne
  • 4,823
  • 2
  • 40
  • 39
0

It is common to combine ehcache with terracotta to allow distributed caching among nodes.

Regards

Carlos Rafael Ramirez
  • 5,984
  • 1
  • 29
  • 36