Description
Is this related to an existing feature request or issue?
aws-powertools/powertools-lambda#87
Which AWS Lambda Powertools utility does this relate to?
Feature flags
Summary
Add action to support modulo condition evaluations within feature flag utility.
Use case
Feature flags are instrumental in experimentation. An important aspect of product experimentation is to allow the feature to be visible to a subset of the users spectrum. This is done in most experiments using the modulo
operator on an identifier. To experiment with 20% of the users, the feature flag should be enabled for say - 0 <= user_id % 100 <= 19
. A parallel experiment could run for - 20 <= user_id % 100 <= 39
Proposal
The modulo operator is a standard mathematical operator easy to implement and has varied use-cases in experimentation.
Add a new action to support modulo evaluation in the feature flag utility.
{
...
"conditions": [
{
"action": "MODULO_RANGE",
"key": "user_id",
"value": {
"base": 100,
"start": 0,
"end": 19,
}
}
]
}
The action configuration will have the following value, where the expressions a is the key and b is the value above:
Action | Equivalent expression |
---|---|
MODULO_RANGE | lambda a, b: b.start <= a % b.base <= b.end |
Tasks
- Add new
RuleActionEnum
-MODULO_RANGE
in feature_flags/schema.py - Add validation for the new rule in feature_flags/schema.py
-
0 <= start <= end <= base - 1
-
- Add new entry to
_match_by_action
in feature_flags/feature_flags.py
Out of scope
Anything beyond design development and documentation of the modulo condition to be added as part of this proposal is beyond the scope.
Potential challenges
One potential challenge is the configuration of the condition.
When someone wants the feature for say, 40% of the users, the only number in their head is the number forty.
When configuring the rule, the user may simply add the number to the start of the range and this might lead to unexpected behaviour. We must communicate explicitly that the start and end range are inclusive to avoid this mistake.
A parallel thought is to introduce size
of as a parameter instead of end
. In that case - the condition would look like -
{
...
"conditions": [
{
"action": "MODULO_RANGE",
"key": "user_id",
"value": {
"base": 100,
"start": 0,
"size": 20
}
}
]
}
The condition implies that the modulo of user_id
base 100
should fall within a range starting from 0 with a size of 20 for this condition to evaluate to true.
Lambda expression
lambda a, b: b.start <= a % b.base <= b.start + b.size - 1
Validation
0 <= start <= start+size <= base
Dependencies and Integrations
No response
Alternative solutions
- Considered having a constant base of 100
- a variable base allows for more custom experimentation basis the user's spectrum size
- Considered a list of values for
[0, 19]
instead of two variables for start and end- a list could imply more values could be appended and comprehension of rules becomes difficult. With two variables, the readability improves considerably
- Still considering having a parameter size instead of end.
- deprioritized because it makes the lambda bulky but might improve user experience with the feature. Open for suggestions on this.
Acknowledgment
- This feature request meets Lambda Powertools Tenets
- Should this be considered in other Lambda Powertools languages? i.e. Java, TypeScript