You front WooCommerce with two PHP-FPM nodes behind a load balancer. Black Friday morning, MySQL CPU climbs to 92% and stays there. SHOW PROCESSLIST is full of SELECT ... FROM wp_woocommerce_sessions WHERE session_key = ... and the slow log is being written faster than logrotate can compress it. The load balancer has sticky sessions on, so a node failure forces 8,000 active carts to log back in. The store is still up, but every page transition takes four seconds.
What’s happening
WooCommerce keeps the customer cart, applied coupons, and notice queue in a per-visitor session blob. By default that blob lives in the wp_woocommerce_sessions table, keyed by a hash stored in a cookie. Every front-end request that hits a logged-out visitor — every product page, every add-to-cart, every cart-fragments poll — does at least one read against that table and, on mutating routes, a write back.
The default schema is fine for a few hundred concurrent visitors. Past that, two things break together:
- Lock contention on
wp_woocommerce_sessions. The table uses MyISAM-style write patterns on InnoDB (UPDATE … WHERE session_key = …). With thousands of concurrent writes per second, the page latches and InnoDB adaptive-hash mutex pile up. Every other query — product reads, order writes — gets queued behind. wp_optionsautoload bloat. WooCommerce, several extensions, and the session cleanup task leave breadcrumbs inwp_optionswithautoload='yes'. Every page load serializes the entire autoload payload back to PHP. At 4 MB of autoload, PHP-FPM workers spend more time deserializing options than rendering templates.
Sticky sessions at the load balancer (source-IP hash, cookie pinning, etc.) were the historical workaround. They keep a visitor on the same PHP node so an in-process object cache stays warm. They also make the load balancer brittle: a node drain during a sale forces every pinned cart to re-authenticate, and autoscaling cannot rebalance traffic away from a hot node.
Moving sessions to Redis fixes both problems. Sessions become a single GET/SET/EXPIRE per request against an in-memory store. Sticky sessions stop being load-bearing — any PHP node can serve any visitor because the session is in shared state. The load balancer reverts to round-robin or least-connection and node drains become non-events.
How to verify
Confirm sessions are still hitting MySQL:
wp db query "SELECT COUNT(*) FROM wp_woocommerce_sessions" --skip-column-names
wp db query "SHOW TABLE STATUS LIKE 'wp_woocommerce_sessions'" --format=table
A row count above 50,000 with Data_length over 200 MB means the session table is being used and never garbage-collected. Combined with a busy slow log on this table, that is the smoking gun.
Check whether an object cache drop-in is installed:
wp eval 'var_export(wp_using_ext_object_cache());'
ls -la wp-content/object-cache.php 2>/dev/null
If wp_using_ext_object_cache() returns false, the site is doing every option lookup against MySQL. That alone explains the wp_options pressure.
Check the load balancer for sticky sessions. On HAProxy:
grep -E "(cookie|stick)" /etc/haproxy/haproxy.cfg
If you see cookie SERVERID insert indirect nocache or a stick-table for the storefront backend, sticky sessions are active. On nginx upstreams it is ip_hash or hash $cookie_xyz consistent.
On the Redis side, confirm there is capacity:
redis-cli INFO memory | grep -E "used_memory_human|maxmemory"
redis-cli CONFIG GET maxmemory-policy
maxmemory-policy must be allkeys-lru or volatile-lru for a session store — never noeviction, which will return OOM errors mid-checkout.
The fix
The migration runs in three phases: deploy Redis with a sane policy, switch WooCommerce sessions over, remove sticky sessions. Stage in pre-prod, cut over on a low-traffic window.
Phase 1 — Redis ready for sessions
# AlmaLinux 9 / Rocky 9
sudo dnf install -y redis
sudo systemctl enable --now redis
# /etc/redis/redis.conf — minimum for session use
maxmemory 2gb
maxmemory-policy allkeys-lru
save ""
appendonly no
tcp-keepalive 60
timeout 300
Sessions are ephemeral, so persistence (save, appendonly) is off — a Redis restart wipes carts, which the site already tolerates because every cart has an expiry. If you need cart durability across Redis restarts, run a second Redis instance with AOF specifically for sessions, but the operational cost rarely justifies it.
Add a requirepass and bind to the private network only:
# /etc/redis/redis.conf
bind 10.10.0.5
requirepass <generated-strong-secret>
protected-mode yes
Open the firewall only from the PHP nodes:
sudo firewall-cmd --permanent --add-rich-rule="rule family=ipv4 source address=10.10.0.11/32 port port=6379 protocol=tcp accept"
sudo firewall-cmd --permanent --add-rich-rule="rule family=ipv4 source address=10.10.0.12/32 port port=6379 protocol=tcp accept"
sudo firewall-cmd --reload
Phase 2 — Object cache + session bridge in WordPress
Install an object cache drop-in. Redis Object Cache by Till Krüss is the de facto choice — well-maintained, supports Sentinel, exposes per-group prefixes.
wp plugin install redis-cache --activate
wp redis enable
Then configure connection in wp-config.php:
define( 'WP_REDIS_HOST', '10.10.0.5' );
define( 'WP_REDIS_PORT', 6379 );
define( 'WP_REDIS_PASSWORD', '<generated-strong-secret>' );
define( 'WP_REDIS_DATABASE', 0 );
define( 'WP_REDIS_TIMEOUT', 1 );
define( 'WP_REDIS_READ_TIMEOUT', 1 );
// Isolate per-environment so staging and prod don't collide on a shared Redis
define( 'WP_CACHE_KEY_SALT', 'shop.example.com:' );
// WooCommerce sessions: write through to Redis instead of wp_woocommerce_sessions
define( 'WC_SESSION_HANDLER', 'WC_Session_Handler_Redis' );
The WC_SESSION_HANDLER constant is honored by WooCommerce 8+ but requires a session handler class on the PHP side. The wp-woocommerce-redis-sessions plugin (or a small mu-plugin) registers it:
// wp-content/mu-plugins/wc-redis-sessions.php
add_filter( 'woocommerce_session_handler', function() {
return 'WC_Session_Handler_Redis';
} );
class WC_Session_Handler_Redis extends WC_Session_Handler {
private $redis;
public function __construct() {
parent::__construct();
$this->redis = new Redis();
$this->redis->connect( WP_REDIS_HOST, WP_REDIS_PORT, 1 );
$this->redis->auth( WP_REDIS_PASSWORD );
$this->redis->select( 1 ); // separate DB from object cache
}
public function get_session( $customer_id, $default = false ) {
$key = WP_CACHE_KEY_SALT . 'wcsess:' . $customer_id;
$value = $this->redis->get( $key );
return $value === false ? $default : maybe_unserialize( $value );
}
public function save_data( $old_session_key = 0 ) {
if ( $this->_dirty && $this->has_session() ) {
$key = WP_CACHE_KEY_SALT . 'wcsess:' . $this->_customer_id;
$this->redis->setex( $key, $this->_session_expiration - time(), maybe_serialize( $this->_data ) );
$this->_dirty = false;
}
}
public function delete_session( $customer_id ) {
$this->redis->del( WP_CACHE_KEY_SALT . 'wcsess:' . $customer_id );
}
}
Stage this in a non-prod environment first — there are edge cases with WooCommerce blocks and the new cart/checkout endpoints that the upstream session handler smooths over.
Phase 3 — Session cleanup + sticky-session removal
The legacy wp_woocommerce_sessions table will keep growing if the cleanup cron is stale. Schedule a chunked cleanup via Action Scheduler:
wp wc tool run db_update_routine --user=1
wp action-scheduler run --hooks=woocommerce_cleanup_sessions --batch-size=200
For ongoing maintenance, a small WP-CLI cron deletes expired session rows in 5,000-row chunks:
#!/bin/bash
# /opt/woo/cleanup-sessions.sh — run every 15 minutes via system cron
cd /var/www/shop && \
wp db query "DELETE FROM wp_woocommerce_sessions WHERE session_expiry < UNIX_TIMESTAMP() LIMIT 5000"
Once Redis sessions have been in production for 48 hours and wp_woocommerce_sessions row count is flat, remove sticky sessions from the load balancer. On HAProxy:
# Before
backend wp_storefront
balance roundrobin
cookie SERVERID insert indirect nocache
server php01 10.10.0.11:9000 cookie php01 check
server php02 10.10.0.12:9000 cookie php02 check
# After — round-robin, no sticky cookie
backend wp_storefront
balance roundrobin
option httpchk GET /wp-admin/admin-ajax.php?action=heartbeat
server php01 10.10.0.11:9000 check inter 5s
server php02 10.10.0.12:9000 check inter 5s
Reload the load balancer, then drain a node during a quiet hour and confirm active carts survive the drain — they should, because their session is in Redis, not pinned to a PHP host.
Stack Harbor runs WooCommerce at high concurrency under enterprise WordPress hosting, including Redis deployment, session-handler audits, and load-balancer tuning. If your store is hitting MySQL ceiling under load, let’s plan the move.