Skip to content

feat: add feature flags mechanism to livedashboard#1831

Open
filipecabaco wants to merge 1 commit intomainfrom
feat/feature-flag
Open

feat: add feature flags mechanism to livedashboard#1831
filipecabaco wants to merge 1 commit intomainfrom
feat/feature-flag

Conversation

@filipecabaco
Copy link
Copy Markdown
Member

What kind of change does this PR introduce?

Adds Feature Flags to Realtime

Resolution order:

  1. Tenant specific override (stored as a JSONB map on the tenant record)
  2. Global flag value
  3. false

Flags are cached per node via FeatureFlags.Cache (backed by Cachex). On mutation, global_revalidate/1 multicasts the updated struct to all cluster nodes via GenRpc. Deletes use distributed_invalidate_cache/1. Cache misses fall through to the DB automatically; nil results are intentionally not cached so new flags are visible immediately

# Global flag — no tenant context needed (e.g. a cluster-wide behaviour toggle)
defmodule Realtime.Broadcast do
  import Realtime.FeatureFlags, only: [enabled?: 1]

  def dispatch(message) do
    if enabled?("new_broadcast_engine"), 
      do: NewEngine.dispatch(message), 
      else: LegacyEngine.dispatch(message)
  end
end

# Per-tenant flag — behaviour differs per tenant (e.g. a beta feature rollout)
defmodule Realtime.Presence do
  import Realtime.FeatureFlags, only: [enabled?: 2]

  def track(tenant, payload) do
    if enabled?("enhanced_presence", tenant.external_id), 
      do: EnhancedPresence.track(payload), 
      else: BasicPresence.track(payload)
  end
end
image

@coveralls
Copy link
Copy Markdown

coveralls commented Apr 24, 2026

Coverage Status

Coverage is 91.765%feat/feature-flag into main. No base build found for main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants