Route n% of traffic based on a path param

Comments

3 comments

  • Steve

    Hi Zefr, 

    Before we go too deep on this, I'd like to recommend you check out A/B Testing at the Edge, as it demonstrates how you could implement this with Fastly without having to modify URLs or have your origins manage routing. 

    For what you're doing, however, all you really need is a Request Condition attached to each origin to test for those strings in the URLs. Something like:

    req.url ~ "specialPathParamOne"

    The resulting VCL would be like: 

    if (req.url ~ "specialPathParamOne") {
    set req.backend = F_origin_0;
    } else {
    set req.backend = F_origin_1;
    }
    1
    Comment actions Permalink
  • Zefr

    Thank you, Steve! Feels like I need a combination of both. Let me see...

    0
    Comment actions Permalink
  • Zefr

    I just need to calculate the percentage of '${specialPathParam}', this '${specialPathParam}' can be anything... 
    So I have to randomize the requests around my '${specialPathParams}' which actually looks like randombool with seeded param:

    Another function, randombool_seeded(), takes an additional seed argument. 
    Results for a given seed will always be the same.

    https://docs.fastly.com/vcl/randomness/

    So looks like I need something like:

    if (randombool_seeded(X, 100, std.atoi('${specialPathParam}')) ) {
      set req.backend = F_origin_0;
    } else {
      set req.backend = F_origin_1;
    }

    and no need for headers.

    So X percent of traffic will go to the backend 1 and requests with the same '${specialPathParam}' value would go to the same backend.

    Love you, Fastly!

    Hope I didn't make mistakes on the way...

     

    0
    Comment actions Permalink

Please sign in to leave a comment.