Skip to content

Commit 2f9ed24

Browse files
docs(bucketing): Adding documentation in how bucketing works (#4447)
Signed-off-by: Thomas Poignant <thomas.poignant@gofeatureflag.org>
1 parent d6b4a12 commit 2f9ed24

File tree

8 files changed

+67
-382
lines changed

8 files changed

+67
-382
lines changed

website/docs/configure_flag/rollout-strategies/percentage.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,73 @@ If the sum of your percentages is not equal to 100 this is not a problem, we are
2424
_**example**: if you have 2 variations and you set `variation1: 10` and `variation2: 50` it will be equivalent to `variation1: 10/60` and `variation2: 50/60`._
2525
:::
2626

27+
## How percentage rollout works?
28+
29+
GO Feature Flag uses a deterministic hashing algorithm to ensure consistent user assignment to variations. Here's how it works:
30+
31+
### Hash computation
32+
33+
For each evaluation, GO Feature Flag computes a hash based on the **targeting key** (also called bucketing key) and the **flag name**:
34+
35+
```
36+
hash = hash(targetingKey + flagName) % maxPercentage
37+
```
38+
39+
This hash produces a value between `0` and `maxPercentage` (which is the sum of all percentages). The hash function ensures that the same user (with the same targeting key) will always get the same hash value for a given flag, providing consistent assignment.
40+
41+
### Bucket assignment
42+
43+
All variations that are part of the percentage rollout are sorted by **reverse alphabetical**. This ensures consistent bucket assignment across evaluations.
44+
45+
For example, if you have the following percentages:
46+
```yaml
47+
percentage:
48+
- varC: 20
49+
- varB: 30
50+
- varA: 50
51+
```
52+
53+
After sorting by inverse alphabetical order, the buckets are assigned as follows:
54+
- **0 to 20**: assigned to `varC`
55+
- **20 to 50**: assigned to `varB`
56+
- **50 to 100**: assigned to `varA`
57+
58+
The hash value determines which bucket the user falls into, and thus which variation they receive.
59+
60+
Since it is pure hash based, GO Feature Flag will always assign the evaluation context to the same bucket even if your evaluation is done on a different server or if you restart your relay-proxy.
61+
62+
### Impact of changing percentages
63+
64+
When you have two variations, adjusting the percentages simply increases or decreases the number of users assigned to each variation.
65+
This allows you to gradually roll out a feature in a predictable and straightforward way.
66+
67+
![2 variations percentage bucket](/img/docs/rollout-strategies/percentage-2-buckets.png)
68+
69+
70+
But if you have **more than 2 variations**, this can have an impact on how your bucketing works.
71+
When you change the percentage configuration, **all buckets are recalculated**, which means users may be reassigned to different variations. This happens because the bucket boundaries shift based on the new percentages.
72+
73+
For example, if you change the configuration to:
74+
```yaml
75+
percentage:
76+
- varC: 30
77+
- varB: 30
78+
- varA: 40
79+
```
80+
81+
The new bucket assignments become:
82+
- **0 to 30**: assigned to `varC`
83+
- **30 to 60**: assigned to `varB`
84+
- **60 to 100**: assigned to `varA`
85+
86+
As you can see in the diagram below, changing percentages shifts the bucket boundaries, which can move users from one variation to another:
87+
88+
![Percentage Rollout Bucket Shifting](/img/docs/rollout-strategies/percentage-buckets.png)
89+
90+
:::info
91+
The deterministic hashing ensures that the same user will always get the same variation for a given configuration. However, when you change percentages, the bucket boundaries change, which may cause some users to be reassigned to different variations.
92+
:::
93+
2794

2895
## Examples
2996
### Define in the default rule
226 KB
Loading
316 KB
Loading

website/static/img/docusaurus.png

-5.02 KB
Binary file not shown.

website/static/img/logo.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)