aws-powertools / powertools-lambda

MIT No Attribution
73 stars 4 forks source link

RFC: Add modulo conditions to Feature Flags #87

Closed ajwad-shaikh closed 1 year ago

ajwad-shaikh commented 1 year ago

Key information

Summary

One paragraph explanation of the feature.

Add action to support modulo condition evaluations within feature flag utility.

Motivation

Why are we doing this? What use cases does it support? What is the expected outcome?

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

This is the bulk of the RFC.

Explain the design in enough detail for somebody familiar with Powertools to understand it, and for somebody familiar with the implementation to implement it.

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

If this feature should be available in other runtimes (e.g. Java), how would this look like to ensure consistency? Feature utility is only available in Python. If we wish to extend this functionality to other runtimes, there should be no problem as there is no language dependency for this feature.

User Experience

How would customers use it? Users will be able to customise their experiments to user spectrums and have visibility over running parallel and orthogonal experiments within their product.

Any configuration or corner cases you'd expect? None

Demonstration of before and after on how the experience will be better This is a new feature, it will expand the applicability of this utility to support more user needs as mentioned above.

Drawbacks

Why should we not do this?

Do we need additional dependencies? Impact performance/package size? None

Rationale and alternatives

Unresolved questions

Optional, stash area for topics that need further development e.g. TBD

heitorlessa commented 1 year ago

moving it to the Python repo ;) thanks a lot for creating it!

heitorlessa commented 1 year ago

ah they're duplicate, I'll close this one and start reading the one in Python: 2003

;)