Hi, I'm looking at using haproxy 1.4 for load-balancing and routing for our API:s. The API:s use a path-based versioning scheme and there is often both a latest stable and a more specific version path that leads to the same backend.
In the sample config below i've configure haproxy to work as follows: a request to "/[email protected]/foo/bar" or "/[email protected]/foo/bar" goes to backend app_1_0_0 and the path is rewritten to "/foo/bar", the header "x-tv2-service-prefix" is set to "/[email protected]" or "/[email protected]" based what path was used. The same goes for the @2.0.[0x] rules and backend. The configuration below works, but as I'm new to haproxy I'm not sure if I've chosen a good solution. The number of API:s we'll be deploying is obviously not set in stone, but something like 20 backends with 2 routes each wouldn't surprise me as we'll have multiple versions of the same applications running for transition periods. So the question is: is this approach sane, and would it scale well when similarly configured for 20 api backends instead of just these two? Cheers & thanks Hugo ------ frontend api bind *:80 acl is_app_1_0_0 path_beg /[email protected] acl is_app_1_0_x path_beg /[email protected] reqadd x-tv2-service-prefix:\ /[email protected] if is_app_1_0_0 reqadd x-tv2-service-prefix:\ /[email protected] if is_app_1_0_x acl is_app_2_0_0 path_beg /[email protected] acl is_app_2_0_x path_beg /[email protected] reqadd x-tv2-service-prefix:\ /[email protected] if is_app_2_0_0 reqadd x-tv2-service-prefix:\ /[email protected] if is_app_2_0_x use_backend app_1_0_0 if is_app_1_0_0 or is_app_1_0_x use_backend app_2_0_0 if is_app_2_0_0 or is_app_2_0_x backend app_1_0_0 cookie SERVERID insert nocache indirect option httpchk HEAD /healthy HTTP/1.0 # Strip out the first directory reqrep ^([A-Z]+)\ /[^\/\ ]+/?(.*) \1\ /\2 server Server1 127.0.0.1:10000 cookie Server1 check inter 5000 server Server2 127.0.0.1:10001 cookie Server2 check inter 5000 server Server3 127.0.0.1:10002 cookie Server3 check inter 5000 server Server4 127.0.0.1:10003 cookie Server4 check inter 5000 backend app_2_0_0 cookie SERVERID insert nocache indirect option httpchk HEAD /healthy HTTP/1.0 # Strip out the first directory reqrep ^([A-Z]+)\ /[^\/\ ]+/?(.*) \1\ /\2 server Server5 127.0.0.1:10004 cookie Server5 check inter 5000 server Server6 127.0.0.1:10005 cookie Server6 check inter 5000 server Server7 127.0.0.1:10006 cookie Server7 check inter 5000 server Server8 127.0.0.1:10007 cookie Server8 check inter 5000

