- Flag: represents the feature flag or experiment.
- Variant: Possible values of the flag.
- Segment: represents the segmentation of traffic.
- Constraint: represents the constraint for a segment. The segment will be picked only when this constraint passes. The service support dynamic constraints also where user provides the variables in the evaluate API.
- Distribution: represents the distribution of variants in a segment.
Note:
- Default variant is
control
. API will returncontrol
if no segment passes. - Variants are deterministically returned. The service should not return different variants on same id.
- Iterate over segments and check the constraints using the context provided in the API call.
- Take the CRC hash of the entity id provided in the request.
- Take the hash and mod by total numbers of bucket (10000).
- Check the distribution. e.g. 30/70 split for
on
andoff
means 0-2999 foron
and rest foroff
. - Consider the rollout percentage for the segment.
The service uses Spring Expression Language for evaluating constraints. It supports variables.
e.g. constraint #userId == 3
will match when userId=3
in the request.
- MySQL DB running on port 3306. DB with name
flagger
should be present.
mvn clean install && java -jar target/flagger-0.0.1-SNAPSHOT.jar
- Creating feature flag
curl --location --request POST 'localhost:8080/api/v1/flag' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "test",
"description": "FF for testing",
"enabled": true,
"variants": [
"on",
"off"
]
}'
- Create segments
"segments": [
{
"name": "segment1",
"priority": 1,
"rolloutPercentage": 100,
"constraint": "#userId == 123",
"distributions": [
{
"name": "d1",
"percent": 30,
"variant": "on"
},
{
"name": "d2",
"percent": 70,
"variant": "off"
}
]
},
{
"name": "segment2",
"priority": 2,
"rolloutPercentage": 50,
"constraint": "#userId == 456",
"distributions": [
{
"name": "d3",
"percent": 50,
"variant": "on"
},
{
"name": "d4",
"percent": 50,
"variant": "off"
}
]
}
]
}
- Evaluate feature flag
curl --location --request GET 'localhost:8080/api/v1/evaluate' \
--header 'Content-Type: application/json' \
--data-raw '{
"context": {
"userId": 123
},
"id": "random",
"flagName": "test"
}'