Have an interesting task when I don't want to have a full rollout of a new feature. I'd like to route only the percentage of traffic (based on a path parameter) to the new endpoint.
I'd like to calculate the percentage based on a 'specialPathParam': ourservice.com/one/'specialPathParam'/something .
So, if we want to route 50% to the new endpoint:
if there're 2 requests ourservice.com/one/'specialPathParamOne'/something ourservice.com/one/'specialPathParamTwo'/something ,
one request with 'specialPathParamOne' should go to the new endpoint and another one with 'specialPathParamTwo' should go to the old one.
Trying to find a way to implement it in VCL somehow...
Any tips and tricks here? Thanks a lot!
Actually, I received an answer on Fastly support forum: https://support.fastly.com/hc/en-us/community/posts/360045757132-Route-n-of-traffic-based-on-a-path-param
Writing my solution here:
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:
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.