Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Flag System - Overview #2235

Open
tobi-bams opened this issue Dec 19, 2024 · 1 comment
Open

Feature Flag System - Overview #2235

tobi-bams opened this issue Dec 19, 2024 · 1 comment
Labels

Comments

@tobi-bams
Copy link
Contributor

tobi-bams commented Dec 19, 2024

Feature Flag System - Overview

General Overview

We aim to implement a dynamic feature flag system to control feature availability seamlessly. This system will include the following components:


Backend

Database Schema

  1. Feature Flags Table:

    • uuid (UUID): Unique identifier for the feature flag.
    • name (String): The name of the feature flag.
    • description (Text): A brief description of the feature flag.
    • enabled (Boolean): Status indicating whether the feature is enabled or disabled.
  2. Endpoints Table:

    • uuid (UUID): Unique identifier for the endpoint.
    • path (String): The API endpoint path (e.g., /api/v1/chat).
    • feature_flag_uuid (UUID): Foreign key linking the endpoint to a feature flag.

Middleware

A middleware will intercept every incoming request to the backend and:

  1. Extract the requested endpoint's path.
  2. Check if the path is associated with a feature flag in the database.
  3. If associated:
    • Verify the feature flag's enabled status.
    • Enabled: Allow the request to proceed.
    • Disabled: Reject the request with an error message stating:
      "This feature is currently unavailable."

Future Plan:
In the future, we plan to integrate Redis as a caching layer to store feature flags and their associated endpoints. This will reduce database queries and enhance performance, especially for high-traffic endpoints. Redis will sync with the database to ensure real-time consistency whenever feature flags are updated.


API Endpoints

  1. Feature Flag Endpoints:

    • GET /feature_flags:
      Retrieves the list of feature flags and their associated endpoints.
      Accessible to admins and users.

    • POST /feature_flags:
      Allows admins to create a new feature flag.
      Takes the feature flag name, description, and an array of associated endpoints.
      Restricted to admin access.

    • PUT /feature_flags/{id}:
      Updates an existing feature flag, including its name, description, or status.
      Restricted to admin access.

    • DELETE /feature_flags/{id}:
      Deletes a feature flag and its associated endpoints.
      Restricted to admin access.

  2. Endpoint Management:

    • POST /feature_flags/{feature_flag_id}/endpoints:
      Adds new endpoints to an existing feature flag.
      Requires the feature_flag_id and an array of endpoint paths to be provided.
      Restricted to admin access.

    • PUT /feature_flags/{feature_flag_id}/endpoints/{endpoint_id}:
      Updates an existing endpoint (e.g., modifies its path).
      Requires the feature_flag_id and the endpoint_id.
      Restricted to admin access.

    • DELETE /feature_flags/{feature_flag_id}/endpoints/{endpoint_id}:
      Deletes an endpoint linked to a specific feature flag.
      Requires the feature_flag_id and the endpoint_id.
      Restricted to admin access.


Frontend

Feature Flag Synchronization

  • On page load, the frontend will call the GET /feature_flags endpoint to retrieve the list of feature flags and their current statuses.
  • The data will be stored in a global state (e.g., MobX).

Feature Visibility

  • Based on the retrieved feature flag statuses, the frontend will dynamically determine whether to display certain features.

Example:

if (featureFlags.FF_Chat.enabled) {
    showChatComponent();
} else {
    hideChatComponent();
}

Admin Dashboard

  1. Feature Flags Tab:

    • Displays a table of all feature flags and their associated endpoints.
    • Visible only to super admins.
  2. Create Feature Flag:

    • A button to open a modal or navigate to a form where admins can:
      • Add a feature flag name, description, and a list of endpoints.
    • Submit the form to store the feature flag in the backend.
  3. Edit and Delete Feature Flags:

    • Each feature flag will have:
      • An Edit button to update its details or associated endpoints.
      • A Delete button to remove the feature flag and its associated endpoints.
  4. Endpoint Management:

    • Add, edit, and delete endpoints associated with a feature flag using dedicated forms or modals.

Summary

This enhanced feature flag system provides:

  1. Dynamic control over feature availability.
  2. Granular management of endpoints associated with feature flags.
  3. A robust middleware to enforce feature restrictions at the backend.
  4. Seamless synchronization between the backend and frontend for consistent feature visibility.
  5. An admin-friendly interface for managing feature flags and their associated endpoints.

Future Scalability:
Redis integration will further enhance the system's performance by caching feature flags and their associations, minimizing database interactions, and supporting high traffic.

@MahtabBukhari
Copy link
Contributor

MahtabBukhari commented Dec 19, 2024

@tobi-bams @humansinstitute please assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants