Context aware MySQL pools via HAProxy
Aug 17, 2016Shlomi Noach
Summary
This post details the implementation of HAProxy for load balancing MySQL read replicas, making the pools context-aware. It introduces a mechanism where backend MySQL servers signal their inclusion status via an HTTP check (responding with 200 for healthy, 503 for lagging/broken). This allows for dynamic exclusion of lagging replicas and servers in maintenance. A graceful failover strategy is implemented using two HAProxy backend pools (main and backup) and ACLs to switch to the backup pool when the main pool has insufficient capacity, ensuring service availability even with stale data. The HTTP check service is implemented using xinetd and shell scripts.