Mailing List Archive

Correct usage of the Shard director
Hi folks. I am transitioning to v5 VCL, and the shard directors look
useful. In our case, we have several products behind Varnish, so I create a
bunch of directors:

sub vcl_init {
new product_a_director = directors.shard();
product_a_director.add_backend(web01);
product_a_director.add_backend(web02);
product_a_director.reconfigure();

new product_b_director = directors.shard();
product_b_director.add_backend(web03);
product_b_director.add_backend(web04);
product_b_director.reconfigure();
}

Then, later on in my vcl_recv, I have to make a bunch of decisions based on
the host and URL to determine which set of backends to send the request to:


if (req.http.host == "product_a.mydomain.com") {
set req.backend_hint = product_a_director.backend();
}

if (req.url ~ "^/login.*") {
set req.backend_hint = product_b_director.backend();
}

In reality, there are thirteen directors for various products and product
areas, which direct traffic to various combinations of the 15 backends to
separate workloads or to route to servers with particular configuration.

It is important for us that traffic from a particular IP goes to the same
backend in each director whenever possible, so do I have to use the manual
"key" property of the shard director? That would change the above to:

if (req.http.host == "product_a.mydomain.com") {
set req.backend_hint = product_a_director.backend(KEY,
product_a_director.key(client.ip));
}

if (req.url ~ "^/login.*") {
set req.backend_hint = product_b_director.backend(KEY,
product_b_director.key(client_ip));
}

Is that the correct way to lock a client to a backend? I do not want to use
session cookies, this should transcend sessions, so all traffic from one IP
goes to the same backend (if healthy/available/possible).

Thanks,

Mark