Use amplitude experiment in a backend service - Fetch variations without passing a user

  • 10 November 2021
  • 4 replies


A backend service that I am working on needs to be able to perform action A vs action B. 

Is it possible to use amplitude flags to fetch the variant and based on the variant that I get back (A or B) I will perform action A vs action B.

From the developer document, I see that I have to pass in a user object to the `experiment.fetch()` method.

My actions are not tied to any user. I just want to use Amplitude to be able to control the variations. Is that possible ?


Best answer by Denis Holmes 16 November 2021, 11:20

View original

4 replies

Userlevel 5
Badge +2

Hi @A.B ,


Thanks for writing into Amplitude Community! Always great to see the community being used!

This is a good question. In order to answer your question, can you provide some more info of what you are trying to do exactly? You want to get a variant based on the variant you get back? This should be possible. Can you elaborate a little more on the scenario and what the flow of your current set up is and what you are expecting to happen? This will give me more context of what you are trying to achieve,


Thank you, @A.B !



In my backend service I am calling performing action where I am making a post request to an endpoint A.

Now, I want to be able to send 10% of my requests to endpoint B. This distribution of traffic to endpoint B has nothing to with a ‘user’ or for that matter any other criteria. I just want 10% of the requests to randomly go to endpoint B.


Can I use amplitude flags for implementing this ? If so, how do it do it ? I as “how” because the documentation says that I need to provide a “user” object to the `experiment.fetch()` method and I don’t have any user as such. I am randomly distributing requests to another endpoint. I wanna use amplitude, because it gives me the ability to change the distribution, without having to change my code or deploy/rollback my code for any changes. 



Userlevel 5
Badge +2

Hi @A.B !


Apologies, I was OOO Friday and I am back in today! Let me speak to my team internally about this and I will get back to you as soon as I can, thank you!



Userlevel 5
Badge +2

Hi @A.B ,


I have contacted the team internally about this question for an answer. Unfortunately, Amplitude was not built for this use case. If you want to randomly assign based on some percentage, you would need to implement this yourself with a Math.random() function or something similar to this yourself to do this!


I hope this helps!