Skip to content

feat: add feature flags mechanism to livedashboard#1831

Merged
filipecabaco merged 2 commits intomainfrom
feat/feature-flag
Apr 29, 2026
Merged

feat: add feature flags mechanism to livedashboard#1831
filipecabaco merged 2 commits 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.712%feat/feature-flag into main. No base build found for main.

@filipecabaco filipecabaco force-pushed the feat/feature-flag branch 2 times, most recently from 4275b76 to 2316062 Compare April 24, 2026 18:13
Comment thread test/realtime/feature_flags_test.exs Outdated
Comment thread test/realtime/feature_flags_test.exs Outdated
Comment thread test/realtime/feature_flags_test.exs Outdated
Comment thread lib/realtime/feature_flags/cache.ex Outdated
Comment thread lib/realtime/feature_flags/cache.ex Outdated
Comment thread lib/realtime/feature_flags/cache.ex
Comment thread lib/realtime/feature_flags/cache.ex
Comment thread lib/realtime/feature_flags/cache.ex
Comment thread lib/realtime_web/live/feature_flags_live/index.ex
@filipecabaco filipecabaco merged commit ed21de8 into main Apr 29, 2026
8 checks passed
@filipecabaco filipecabaco deleted the feat/feature-flag branch April 29, 2026 16:05
@realtime-release-bot
Copy link
Copy Markdown

🎉 This PR is included in version 2.89.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants