Use a **User Profile Service** to persist information about your users and ensure variation assignments are sticky. Sticky implies that once a user gets a particular variation, their assignment won't change.
In the React SDK, there is no default implementation. Implementing a User Profile Service is optional and is only necessary if you want to keep variation assignments sticky even when experiment conditions are changed while it is running (for example, audiences, attributes, variation pausing, and traffic distribution). Otherwise, the React SDK is stateless and relies on deterministic bucketing to return consistent assignments.
If the User Profile Service doesn't bucket a user as you expect, then check whether other features are overriding the bucketing. For more information, see [How bucketing works](🔗).
## Implement a service
Refer to the code samples below to provide your own User Profile Service. It should expose two functions with the following signatures:
`
lookup
`: Takes a user ID string and returns a user profile matching the schema below.`
save
`: Takes a user profile and persists it.
If you want to use the User Profile Service purely for tracking purposes and not sticky bucketing, you can implement only the `save
` method (always return `nil
` from `lookup
`).
The code example below shows the JSON schema for the user profile object.
Use `experiment_bucket_map
` to override the default bucketing behavior and define an alternate experiment variation for a given user. For each experiment that you want to override, add an object to the map. Use the experiment ID as the key and include a `variation_id
` property that specifies the desired variation. If there isn't an entry for an experiment, then the default bucketing behavior persists.
In the example below, `^[a-zA-Z0-9]+$
` is the experiment ID.
The React SDK uses the User Profile Service you provide to override Optimizely's default bucketing behavior in cases when an experiment assignment has been saved.
When implementing your own User Profile Service, we recommend loading the user profiles into the User Profile Service on initialization and avoiding performing expensive, blocking lookups on the lookup function to minimize the performance impact of incorporating the service.
## Implement asynchronous user lookups with experiment bucket map attribute
You can implement `attributes.$opt_experiment_bucket_map
` to perform asynchronous lookups of users' previous variations. The SDK handles `attributes.$opt_experiment_bucket_map
` the same way it would `userProfileService.lookup
`, and this allows you to do an asynchronous lookup of the experiment bucket map before passing it to the [Activate](🔗) method.
Note
`
attributes.$opt_experiment_bucket_map
` will always take precedence over an implemented `userProfileService.lookup
`.
The example below shows how to implement consistent bucketing via attributes.
You can use the asynchronous service example below to try this functionality in a test environment. If you implement this example in a production environment, be sure to modify `UserProfileDB
` to a real database.