Press "Enter" to skip to content

Welcome to Code Variation Management

Image: Nikolai Bogomolov

Variant is a robust, performant server for instrumentation and management of A/B tests and feature flags, which we call collectively code variations. Architected as client/server, Variant enables complete separation of implementation and instrumentation. The implementation of new application code paths remains within the host application’s domain, while their instrumentation for co-existence with the existing code-path in the form of an A/B test or a feature flag. Is handled entirely by the Variant server.

Example Example

To instrument a simple A/B test, you may simply take advantage of the example schema, shipped with the server in the file schemata/example.yaml, and reproduced below.

name: example
description: Basic sample variation schema. See User Guide for details.
states:
  - name: MyState
variations:
  - name: MyVariation
    experiences:
      - name: existing
        isControl: true
        weight: 3
      - name: treatment
        weight: 1
    onStates:
      - state: MyState

Start Variant server:

$ /path/to/variant/server/bin/variant start
2019-12-26 15:23:26,412 INFO - c.v.s.boot.ConfigLoader$ - Found  config resource [/variant.conf] as [/Users/Igor/soft/variant-server-0.10.3/conf/variant.conf]
2019-12-26 15:23:27,425 INFO - c.v.s.schema.SchemaDeployerFileSystem - Mounted schemata directory [/Users/Igor/soft/variant-server-0.10.3/schemata]
2019-12-26 15:23:27,428 INFO - c.v.s.schema.SchemaDeployerFileSystem - [421] Deploying schema from file [/Users/Igor/soft/variant-server-0.10.3/schemata/example.schema]
2019-12-26 15:23:27,689 INFO - c.v.s.schema.Schemata - [422] Deployed schema [exampleSchema] from file [example.schema]
2019-12-26 15:23:27,695 INFO - c.v.s.boot.VariantServerImpl - [433] Variant AIM Server release 0.10.3 started on port [5377] in 2.63s

In your JVM application, create a Variant client. You only need one per your application. Then connect to the above variation schema on the server. When user navigates to the state of interest MyState (may be an HTML page, or an Angular view, or an IVR menu, etc), target current session for that state and obtain the state request object, containing the experience targeting information you need to decide on the code path.

// Create Variant client.
VariantClient client = VariantClient.build(
   builder -> builder.withSessionIdTracker(MySessionIdTracker.class) // Footnote 1 below
)

// Connect to the Example schema on the server
Connection connection = client.connectTo("http://localhost:5377/example");

// Create Variant session
Session session = connection.getOrCreateSession(myParameters); // Footnote 2 below

// The schema we're connected to
Schema schema = session.getSchema();

// The variable state, e.g. an HTML page, we want to target the session for.
State state = schema.getState("MySate").get();

// Target the session for the state.
StateRequest request = session.targetForState(state);

// Find out what experience in the A/B test we got.
Variation variation = schema.getVariation("MyVariation").get();
Experience experience = request.getLiveExperience(variation).get();

// Bifurcate
if (experience.getName().equals("control")) {
  // the control code path.
{
else {
  // the treatment code path
}