When you enable session affinity, your load balancer directs all requests from a particular end user to a specific origin server. This continuity preserves information about the user session — such as items in their shopping cart — that might otherwise be lost if requests were spread out among multiple servers.
Session affinity can also help reduce network requests, leading to savings for customers with usage-based billing.
Session Affinity automatically directs requests from the same client to the same origin web server:
- When a client makes its first request, Cloudflare sets a
CFLibcookie on the client that tracks the associated origin web server.
- Subsequent requests by the same client are forwarded to that origin for the duration of the cookie and as long as the origin server remains healthy.
- If the cookie expires or the origin server is unhealthy, Cloudflare sets a new cookie tracking the new failover origin.
All sessions default to 23 hours unless you set a custom session Time to live (TTL).
Enabling Session Affinity from the Cloudflare dashboard
If you enable Session Affinity, choose one of the following options:
- By Cloudflare cookie only: Sets a
CFLibcookie to track the associated origin web server
- By Cloudflare cookie and Client IP fallback: Sets a
CFLibcookie, but also uses the client IP address when no session affinity cookie is provided
Enabling Session Affinity via the Cloudflare API
Session affinity is a property of load balancers, which you can set with the following endpoints:
Customize the behavior of session affinity by using the