Implement a User Storage Service

User Storage Service (USS) is a caching layer to persist data about your users. This is helpful in ensuring that variation assignments are always sticky even if you update the campaign settings.
For example, you can create an implementation that reads and saves user-campaign data mapping from backend services such as Redis, Memcache, MongoDB, or any other storage service.

How to Implement User Storage Service

User Storage Service is optional while instantiating the VWO SDK. However, to ensure sticky variation assignments, we recommend implementing one.

User Storage Service should expose two methods: get and set.

Method Name





userId, campaignKey

Retrieve stored data

Returns a matching user-campaign data mapping corresponding to User ID passed



Store user-campaign data mapping. It has information like user with User ID become part of a campaign having campaign-key as <Campaign_Key> and got the assigned variation <Variation_Name>.


Check the following example to know more about how to implement your own User Storage Service.

import com.vwo.VWO;

String settingsFile = VWO.getSettingsFile(accountId, sdkKey);

Storage.User userStorage = return new Storage.User() {
     public Map<String, String> get(String userId, String campaignKey) {
        for (Map<String, String> savedCampaign: campaignStorageArray) {
            if (savedCampaign.get("userId").equals(userId) && savedCampaign.get("campaignKey").equals(campaignKey)) {
               return savedCampaign;
        return null;
     public void set(Map<String, String> map){

VWO vwo = VWO.launch(settingsFile).withUserStorage(userStorage).build();

Format for the userStorageData

userStorageData is a map where data is being stored with respect to a unique user ID and a unique campaign key.

Following keys are expected in the map:



Unique User ID which was provided at the time of calling the SDK API.



Unique campaign key, provided at the time of campaign creation, and passed when calling the SDK API.



Variation Name that was assigned to the user having the User ID



List of goals that has already been triggered for the campaign having campaignKey and for User ID, separated by a delimiter vwo.
Example: Campaign having three goals but only two have been triggered since now i.e. buy-now-clicked and product-bought goals.

Note: This is required in case of track API only. If you aren't calling track API, you can skip this parameter.



VWO SDK validates the variationName and checks whether the variation exists in the campaign having the campaignkey or not. If the variation is found, SDK will use without looking into the User Storage service. If the variation of not found, SDK will jump onto the process of checking whether the user is eligible for the campaign or not and returns accordingly from the SDK API.

Below is an example:

  userId: 'User ID',
  campaignKey: 'unique-campaign-key',
  variationName: 'Variation-1'


User Storage Service Asynchronous Behaviour

get method needs to be synchronous as all SDK APIs are synchronous except getSettingsFile API.
Using asynchronous DB/Storage operations inside get method are not useful as, in any way, SDK needs to wait for the response so that the stored results could be used synchronously.

set method could be asynchronous as VWO SDK need not wait for any response from it.

Also, asynchronous behavior is limited to languages like Node.js, JavaScript, and Java as other languages do not natively support them in all the SDK supported versions.

Please check the FAQ Is User Storage Service synchronous or asynchronous?
- to know more about how to implement the asynchronous User Storage Service.

Did this page help you?