A/B Testing with haproxy

A/B testing is a common requirement for all e-commerce sites to be able to roll out new features and test them to a small percentage of users so that it can eventually be rolled out for everyone. This method is also being increasingly used for switching to new UIs/platform as well.

Haproxy is the default load-balancer of choice for an increasing number of deployments and the A/B requirement can be setup as documented below:

We are doing a 90/10 split here and the same is accomplished using a use-server keyword which in turns forwards requests to another listen blocks depending on the value of the cookie (old_site_90 or old_site_10)

listen http-in
bind x.x.x.x:80
option httplog
balance source
use-server old if { req.cook(SITEID) -m beg old_site_90 }
use-server new if { req.cook(SITEID) -m beg new_site_10 }
server old 127.0.0.1:8080 weight 90
server new 127.0.0.1:8081 weight 10
default_backend old

listen old
bind 127.0.0.1:8080
mode http
option httplog
balance roundrobin
cookie SITEID insert indirect nocache maxlife 48h
server web01 x.x.x.x:80 check inter 1000 maxconn 125 cookie old_site_90
appsession SESS len 50 timeout 3h request-learn prefix
option http-server-close
option httpclose
option forwardfor

listen new
bind 127.0.0.1:8081
mode http
option httplog
balance roundrobin
cookie SITEID insert indirect nocache maxlife 48h
server web02 x.x.x.x:80 check inter 1000 maxconn 125 cookie new_site_10
appsession SESS len 50 timeout 3h request-learn prefix
option http-server-close
option httpclose
option forwardfor

Now this is all fine for cookies which are already set but the initial seeding needs to be done to take care of the 90:10 split. This can be done by having multiple servers on “old” backend and one of them sending out the “SITEID” as “new_site_10”. This will seed a small proportion of users  onto the new backend.

Setup Details
Centos 6.6
haproxy-1.5.5-1.el6.x86_64