Federated Feature Flag Governance Design
Overview
This design outlines a federated feature flag system that balances centralized governance with decentralized control. It supports a hierarchical inheritance model where feature flags cascade from higher levels (e.g., organization-wide) to lower levels (e.g., service-specific environments). Overrides allow child entities to customize inherited flags without breaking the hierarchy.
Key principles:
- Federation: Teams/services own their flags but inherit defaults from parents.
- Inheritance: Flags flow down the hierarchy unless overridden.
- Governance: Centralized auditing, permissions, and workflows enforce compliance.
- Scalability: Handles thousands of flags across orgs with 100s of teams/services.
- Evaluation: Real-time, context-aware resolution (e.g., user, env, service).
The system is implemented as a centralized service (e.g., "FlagHub") with a hierarchical database, backed by APIs for management and SDKs for evaluation.
Hierarchy Structure
Flags are organized in a tree:
Organization (Root)
├── Team A
│ ├── Service 1
│ │ ├── Dev Env → Inherits from Service 1 → Team A → Org
│ │ ├── Stage Env
│ │ └── Prod Env
│ └── Service 2
│ └── [Envs]
└── Team B
└── [Services + Envs]
- Levels (configurable): Org > Team > Service/App > Env (Dev/Staging/Prod).
- Inheritance Path: Evaluate from leaf (e.g., Prod Env) → root (Org). Use the closest explicit value; fall back to parent's if unset.
Data Model
Stored in a relational DB (e.g., Postgres) with a flags table and a hierarchy_nodes table for tree structure.
Core Tables
-- Hierarchy nodes (e.g., Org=1, TeamA=2, Service1=3, Service1-Prod=4)
CREATE TABLE hierarchy_nodes (
id BIGINT PRIMARY KEY,
parent_id BIGINT REFERENCES hierarchy_nodes(id),
type ENUM('org', 'team', 'service', 'env'), -- Extensible
name VARCHAR(255),
owner_team VARCHAR(255), -- For permissions
created_at TIMESTAMP
);
-- Feature flags
CREATE TABLE feature_flags (
id BIGINT PRIMARY KEY,
node_id BIGINT REFERENCES hierarchy_nodes(id), -- Scoped to this node
key VARCHAR(255) UNIQUE PER NODE, -- e.g., "new-payment-ui"
value JSON, -- Flexible: {"enabled": true}, {"rollout": 20%}, {"rules": [...]}
description TEXT,
owner VARCHAR(255), -- User/Team
locked BOOLEAN DEFAULT FALSE, -- Prevents overrides
approval_required BOOLEAN DEFAULT FALSE, -- Needs review
created_at TIMESTAMP,
updated_at TIMESTAMP
);
-- Audit log
CREATE TABLE flag_audits (
id BIGINT PRIMARY KEY,
flag_id BIGINT,
action ENUM('create', 'update', 'delete', 'override'),
old_value JSON,
new_value JSON,
actor VARCHAR(255),
reason TEXT
);
-- Permissions (RBAC)
CREATE TABLE permissions (
id BIGINT PRIMARY KEY,
principal VARCHAR(255), -- User/Group/Service Account
node_id BIGINT,
action ENUM('read', 'write', 'override', 'lock', 'approve')
);
- Flag Value Schema (JSON):
{
"enabled": true, // Boolean flag
"rollout": 50, // % rollout
"rules": [ // Advanced targeting
{"user_segment": "premium", "enabled": true},
{"geo": "EU", "enabled": false}
],
"metadata": {"expires": "2024-12-31"}
}
Flag Evaluation Logic
SDKs (JS, Go, Python) query FlagHub API for resolution.
Algorithm (Pseudocode)
def evaluate_flag(context: Context, flag_key: str) -> Dict:
# Context: {'org': 'acme', 'team': 'billing', 'service': 'payments', 'env': 'prod', 'user_id': '123'}
path = build_hierarchy_path(context) # ['prod', 'payments', 'billing', 'acme']
for node in reversed(path): # Bottom-up
flag = db.get_flag(node_id, flag_key)
if flag and flag.value is not null:
return apply_rules(flag.value, context) # Evaluate targeting
return {"enabled": false} # Default: off
- Caching: Client-side TTL cache (e.g., 30s) + edge caching (e.g., CDN).
- Fallbacks: Configurable org-wide defaults.
- A/B Testing: Built-in rollout % and user bucketing (e.g., via hash(user_id)).
Management Interface
API (REST/gRPC)
POST /flags: Create flag at node (authz check).
PATCH /flags/{id}: Update/override.
GET /flags/{node}/effective: List all resolved flags for a node (with inheritance).
POST /flags/{id}/override: Propose override (triggers workflow).
UI (Web Dashboard)
CLI/SDK
flaghub flags create --node=team/billing --key=new-ui --value='{"enabled": true}'
flaghub flags eval --service=payments --env=prod --key=new-ui --user=123
Governance Features
-
Permissions (RBAC + ABAC):
- Org admins: Full control.
- Team owners: Write to team/services/envs.
- Service accounts: Read-only eval.
- Enforce via JWT scopes.
-
Overrides & Locks:
- Overrides stored as child flags; parent changes don't propagate.
locked flags: Can't override without org approval.
- Drift Detection: Alerts on overrides >30 days old.
-
Workflows:
- Approval gates for prod overrides (e.g., GitHub PR-like: propose → review → merge).
- Rollback: Revert to parent with one click.
-
Auditing & Compliance:
- Immutable audit log.
- Reports: "Flag usage heatmap", "Override summary".
- Expiry: Auto-disable stale flags.
-
Federation Controls:
- Teams can "opt-in" to org flags.
- Shadow mode: Log evaluations without enabling.
Implementation Considerations
- Storage: Postgres + Redis for cache. Sharding by org.
- Tech Stack: Go (backend), React (UI), gRPC (internal), OpenAPI (docs).
- Deployment: Kubernetes, multi-region for low-latency eval (<50ms P99).
- Migration: From legacy (e.g., LaunchDarkly): Import as org-level, then federate.
- Edge Cases:
- Cycles: Prevent via DB constraints.
- High Cardinality: Limit flags/node to 10k.
- Offline: SDK fallbacks to bundle.
This design enables safe, scalable feature management in federated orgs like microservices at scale. For prototypes or refinements, provide more context (e.g., org size, existing tools)!