Correct usage of the Shard director

Mark Hanford mark at
Thu Mar 30 12:11:07 CEST 2017

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();

        new product_b_director = directors.shard();

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 ( == "") {
        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 ( == "") {
        set req.backend_hint = product_a_director.backend(KEY,

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

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).


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the varnish-misc mailing list