Session clustering in Spring Boot is configured with Spring Session, which stores HTTP session data in a shared, distributed store instead of a single server's memory.
Key Points: • Add spring-session-data-redis (or the Hazelcast/JDBC equivalent) plus the corresponding data-store starter dependency. • Configure the store's connection details in application.yml (e.g. Redis host/port). • Spring Session auto-replaces the default HttpSession implementation with one backed by the store, transparently. • All instances behind a load balancer can then read/write the same session, so users aren't tied to a single server. • Session timeout and serialization format are configurable via spring.session.* properties.
Example: With Redis-backed sessions, a user logged into server A can be routed to server B on the next request after a deployment or failover, and still stay logged in because the session lives in Redis, not in server A's memory.
Code Example:
# application.yml
spring:
session:
store-type: redis
timeout: 30m
data:
redis:
host: redis-cluster.internal
port: 6379Interview Tip: A concise interview answer is:
"I'd add Spring Session with a Redis starter, point it at the shared Redis instance in application.yml, and Spring Session transparently swaps in a Redis-backed HttpSession. That way every instance behind the load balancer reads and writes the same session data, so failover or scaling out doesn't log users out."