feat: build feature flags system with deterministic percentage rollouts - #449
Merged
Merged
Conversation
|
@mallison031 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
@mallison031 please resolve conflicts |
Contributor
|
This PR has merge conflicts that need to be resolved. Please rebase your branch on the latest |
Contributor
|
This PR has merge conflicts. Please rebase on latest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #415
Summary
percentage-based rollouts, and specific user targeting, backed by a 60-
second Redis cache. This introduces the
FeatureFlagentity, an admin/userflag controller, and a
FeatureFlagGuardto restrict access withoutrevealing features via 404s.
redis-yet
for strict caching requirements. - **Database**: Addedfeature_flagstable and migration. - **Service & Caching**: AddedFlagsServiceusing deterministic hashing (userId+flagKey) for stable percentage rollouts. Flag definitions are cached to prevent any per-request DB hits. - **Guard**: Implemented a NestJS mixinFeatureFlagGuardthat integrates smoothly withJwtAuthGuard. - **Gates**: Applieddao_votingfeature flag gates toProposalController` routes.converted to an integer mod 100. This guarantees a stable rollout
distribution that is immune to random variance across requests for the same
user.
- Redis Fallback: Since Redis was not previously configured, the
FlagsModulefalls back to an in-memory cache ifREDIS_URLis absent,preventing pipeline breaks in existing setups.
- Soft Deletion: Instead of native
TypeORM@DeleteDateColumn(),deleting archives the key explicitly to avoid unique constraint violations
if an admin later re-creates a flag with the same name.
userIdacross multiple calls- [x] Flag with
targetUserIds=[userId]enables the feature for that usereven at 0% rollout
- [x] Disabled flag causes route to return 404 — not 403
- [x] Flag state cached in Redis — DB not queried on every API request
- [x]
GET /flagsreturns correct enabled/disabled state forauthenticated user
- [x] Updating a flag via admin clears the Redis cache immediately
FeatureFlagGuard.- Passed all tests. New files achieved 100% Line Coverage.
- Note: The global CI might show some compilation errors/lint warnings,
but these are inherited from existing issues on the
v2upstream branch.The newly added feature flag code typechecks and lints completely cleanly.
These modules/controllers do not currently exist in the
v2codebase, sothe guard was only applied to the DAO
ProposalController. They can begated trivially with
@FeatureFlagGuard('key')once created.