Open
Description
I have some questions about what data consistency guarantees spring boot session jdbc provides.
Suppose we have this scenario:
- A stateful session in a spring boot application with spring session jdbc. Every request updates the session.
- 2 containers running with the same application
- 1 database with jdbc driver
- A reverse proxy with round robin (No sticky session) A client making parallel requests to the server
Questions:
- When the first request hits Container A in order to reads a session from DB, is there a lock on the object?
- If there is no lock on read, but only on write operation, what happens if a second request hits container B before request on container A has saved the session?
- Do we have to assume a last-write-wins semantics? Probably yes based on this answer
- Can we have stale data read?
- If we look at this example (https://docs.spring.io/spring-session/reference/api.html) can I state that in order to reduce data inconsistency I have to reduce as much as possible the time between session read (session.getAttribute(...)) and session save (4)?
I suggest to improve the documentation to better explain what data consistency guarantee spring boot session has for the different back-ends. For example wildfly use infinispan to manage distributed cache and has a good documentation on this.
A possible workaround is to use sticky sessions (optional, can be enabled only when required) to have stronger data consistency. With sticky session some optimization are possible: reads come from jvm memory objects, writes to persistent storage can be async. See issue 6
Thank you for your help and feedback.