open-feature / open-feature/flagd
[FEATURE] Support random distributions
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 997
- Forks
- 136
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 11
Description
Requirements
Flagd supports fractional evaluation by providing deterministic traffic routing by hashing the incoming context. This behavior is typically preferred because it prevents users from randomly seeing different behavior on subsequent requestions.
However, there are some valid use cases for non-deterministic behavior. Some examples include:
- OTel demo would like to have 10% of requests fail
- Testing new features where randomness is preferred
Workaround
It's possible to randomly distribute traffic using the $flagd.timestamp context attribute as the hash key. This approach will evaluate to the same value for one second before "randomly" changing.
A user can also supply a seed value in context, which could be used in the fractional operator to achieve randomness.
Proposal
Automatically add a seed in context
We could inject a $flagd.seed into the context in the same way we include $flagd.timestamp. This could be used in a targeting rule to just like any other context. The downside is that we'd be adding additional context that would only be used in very limited situations.
Custom JSON Logic Operator
We could add a custom JSON Logic operator as we did for fractional. It could be something like rand or seed that would return a random value. The downside is that the behavior of custom functions in JSON logic would need to be well-defined and constantly implemented in every language.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing fractional evaluation behavior and the custom JSON Logic operator implementation described in the issue. Compare the proposed context seed and random operator approaches, then clarify the supported semantics and language-implementation requirements before defining what a complete change would entail.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100