Keycloak works best in a high availability setup, and that means you need a load balancer configured with precision. Without it, session stickiness breaks, tokens fail, and logins stall under pressure. A proper Keycloak load balancer setup makes authentication resilient, scalable, and predictable even under sudden spikes.
Place the load balancer in front of all Keycloak nodes. Use TCP mode for HTTPS termination at the balancer, or pass TLS through if you need end-to-end encryption. Enable sticky sessions so that once a user hits a node, their session stays there. Keycloak stores session state in the database, but stickiness reduces database churn and improves response time.
For HAProxy, configure balance source or balance hdr(cookie) with persistence set to your session cookie. For Nginx, use ip_hash or sticky modules. In AWS, use Application Load Balancer with cookie stickiness enabled. In Kubernetes, consider Ingress with annotations for sticky sessions or an external load balancer service.