On this page
What this issue is
A load balancer spreads visitors across two or more web servers. A session is the small record a server keeps about a visitor: what is in the cart, whether they are logged in, a form token. By default many apps (PHP, for example) save that record as a file on the server that handled the first request.
If the next request lands on a different server, that server has no record. The visitor looks like a stranger. Sticky sessions tell the load balancer to send the same visitor to the same server each time, usually with a cookie. When stickiness is off and sessions are not shared, you get this problem.
- Add to cartLoad balancer sends the request to Server A, which stores the cart
- View cartRequest goes to Server B, which has no session
- Cart is emptyVisitor sees an empty basket or a login page
- CheckoutVisitor gives up
Request 2 reaches a server that never saw the session.
Why it costs you leads or sales
The failure is random, so it is easy to miss. A visitor adds a product, clicks to the cart and finds it empty. Another submits a form and gets an invalid token or security error. Logged-in users are sent back to the login page mid-checkout.
With two servers, roughly half of multi-step journeys can hit a mismatch. The more servers you add, the worse it gets. Your own testing often looks fine because a quick click-through may stay on one server.
Example: with two servers and no stickiness, about half of visitors switch server between steps. Numbers are illustrative.
How to check if your site has it
Confirm you have more than one server
Ask your host or check your infrastructure. Look for a load balancer, several web nodes, or a CDN with multiple origins.
Look at the session cookie
In your browser developer tools, open Application > Cookies. Note the session cookie (for example PHPSESSID) and any balancer cookie such as AWSALB or a host-specific one. No balancer cookie suggests stickiness is off.
Find where sessions are stored
In PHP, check session.save_handler and session.save_path with phpinfo(). Values of files and a local path like /tmp mean each server keeps its own sessions.
Reproduce with repeated requests
Add an item to the cart, then reload the cart page 10 times. If it empties sometimes, requests are hitting different servers.
Expose the server name
Add a temporary response header with the hostname, then watch it change between requests while your session cookie stays the same.
curl -s -c jar.txt -o /dev/null https://example.com/
for i in 1 2 3 4 5 6; do
curl -s -b jar.txt -I https://example.com/cart | grep -i -E 'x-served-by|server|set-cookie'
doneHow to fix it
There are two fixes. Shared session storage is the more robust one: any server can read any session. Sticky sessions are quicker but fail if a server drops out, because those visitors lose their sessions. Use shared storage where you can, and stickiness as a stopgap.
Use a shared object cache or database sessions
WooCommerce stores carts in the database by default, so logged-out cart loss often comes from a per-server object cache or plugin that uses PHP files for sessions. Point any object cache plugin to one shared Redis or Memcached server.
Check plugins that use PHP sessions
Some form and membership plugins call session_start(). Switch PHP to shared session storage (see Custom code) or enable stickiness at the load balancer.
Keep salts and keys identical
Make sure wp-config.php has the same AUTH_KEY and related salts on every server, or logins will fail between nodes.
Store PHP sessions in Redis
Install the phpredis extension and set session.save_handler = redis and session.save_path to your shared Redis server in php.ini on every node. Restart PHP-FPM.
Or enable stickiness on the load balancer
On AWS Application Load Balancer, edit the target group > Attributes > Stickiness and choose load balancer generated cookie. On Nginx use ip_hash or a sticky cookie module in the upstream block. Use your own balancer's documentation for other products.
Keep other state shared
Uploaded files, CSRF tokens and caches must also live in shared storage or the database, not on one server's disk.
Nothing to configure
Shopify runs the hosting and sessions for you. If carts empty on a Shopify store, look at themes, apps or a proxy in front of the store instead.
Nothing to configure
Wix manages servers and sessions. Contact Wix support if you see random session loss, and check any custom domain proxy you added.
session.save_handler = redis
session.save_path = "tcp://10.0.0.5:6379"upstream app {
ip_hash;
server 10.0.0.11:80;
server 10.0.0.12:80;
}How to confirm it's fixed
- Add to cart and reload the cart page 20 times: the cart never empties.
- Log in, then browse several pages: you stay logged in.
- Submit a form several times in a row: no token or security errors.
- Stop one web server briefly: sessions still work if you use shared storage.
- Repeat the tests from a private window and another network.
Sessions on each server
- Cart empties at random
- Logins drop mid-checkout
- Hard to reproduce
Shared sessions or stickiness
- Same cart on every request
- Logins last
- Adding servers is safe
How to prevent it happening again
- Keep session storage in the deployment checklist for every new node.
- Use identical PHP and app configuration on all servers.
- Never store uploads, carts or tokens on one server's local disk.
- Test the full cart and login journey after adding or replacing a server.
- Run a scheduled journey test so a bad rollout is noticed quickly.
How FunnelGuard handles this
FunnelGuard detects this issue only partly. It does not inspect your load balancer or session settings. What it does is run your real journeys (such as add to cart, checkout or a lead form) on a schedule from the EU or the US, and check each step. If a run hits the wrong server and the cart is empty or a form step fails, the step fails, FunnelGuard re-checks from a second region, and you get one alert with a screenshot and a likely cause.
Because the problem is random, one passing run does not prove it is fixed, and a single failure may be the only sign. FunnelGuard cannot tell you that stickiness is missing, which server answered, or where sessions are stored. Cover that by hand: check the balancer settings, the session save handler and the cookies, and run the repeated-request test above. The free plan includes 1 site and 2 journeys with daily checks, and every paid plan has a 3-day free trial.
Frequently asked questions
Questions people ask
Why does my cart empty randomly on my website?
If your site runs on more than one server, the load balancer may send a visitor to a server that does not hold their session. That server sees an empty cart. Store sessions in shared storage such as Redis or turn on sticky sessions.
What are sticky sessions in a load balancer?
Sticky sessions, or session affinity, make a load balancer send the same visitor to the same server for each request, usually using a cookie. This keeps server-side session data available. It is a quick fix but fails if that server goes down.
Are sticky sessions better than shared session storage?
Shared storage is usually more reliable, because any server can serve any visitor and a server failure does not lose sessions. Sticky sessions are easier to switch on but spread load unevenly and break when a node drops out.
How do I enable sticky sessions on AWS?
For an Application Load Balancer, open the target group, go to Attributes, edit Stickiness, turn it on and choose a load balancer generated cookie with a duration. Test afterwards to be sure the cookie is set.
Why do users get logged out when I add a second server?
Each server may store login sessions locally, so a request that reaches the other server finds nothing. Move sessions to shared storage and make sure keys and salts are identical on every server.
How can I tell if sessions are stored on the server?
In PHP, run phpinfo() and check session.save_handler. A value of files with a local path means each server holds its own sessions. Redis, Memcached or a database handler means they can be shared.
Can FunnelGuard detect missing sticky sessions?
Only partly. FunnelGuard runs your real journeys and flags steps that fail, such as an empty cart, but it does not inspect your load balancer or session storage. You still need to check those settings yourself.
Related issues
- OPS-088Session storage broken (cart empties between pages)Fix guide
- OPS-090One bad node behind load balancer (random failures)Fix guide
- OPS-092Hosting migration left old server serving some trafficFix guide
- OPS-091Auto-scaling failure during traffic peakFix guide
- OPS-072Server out of disk space (uploads, sessions fail)Fix guide
- OPS-073Memory / PHP memory_limit exhausted (white screen)Fix guide