Design a multi-tenant feature flag governance: isolation, inheritance, overrides, and…
- User
Design a multi-tenant feature flag governance: isolation, inheritance, overrides, and audit trails.
- Assistant
Design a multi-tenant feature flag governance: isolation, inheritance, overrides, and audit trails.
Okay, the user is asking about designing a multi-tenant feature flag governance system with specific capabilities: isolation, inheritance, overrides, and audit trails. This is a complex architectural question that requires balancing flexibility with control in a SaaS environment.
First, I need to break down what each requirement means in this context. Isolation means tenants shouldn't interfere with each other's flags. Inheritance suggests a hierarchical model where defaults can be set at higher levels (like organization or workspace). Overrides allow tenant-specific tweaks. Audit trails are about tracking changes for compliance and debugging.
I should structure this as a layered system. Starting with the core data model seems logical—how flags are stored and related. Then governance rules to enforce isolation and inheritance. Overrides need a clear precedence order. Audit trails must capture who changed what and when.
Implementation considerations include storage choices (graph vs relational), conflict resolution for overrides, and real-time vs batch evaluation. Security is critical—RBAC, encryption, and strict tenant scoping. The evaluation flow needs to be deterministic and fast.
I'll avoid diving too deep into code but provide concrete examples of how inheritance and overrides would work in practice. The response should feel like a blueprint someone could actually build from, not just theoretical. Keeping it structured but conversational will help. Excellent question. Designing a multi-tenant feature flag governance system is a critical challenge for SaaS platforms, balancing flexibility for tenants with control and security for the platform operator.
Here is a comprehensive design for a multi-tenant feature flag governance system, covering Isolation, Inheritance, Overrides, and Audit Trails.
The system should view tenants not in a flat list, but within a logical hierarchy (e.g., Platform > Organization > Workspace > Project). Governance rules flow down this hierarchy, and overrides flow up. This enables both global standards and tenant-specific agility.
** Principle:** Absolute data isolation. A tenant must never see, query, or be affected by another tenant's flag definitions, targets, or overrides.
Implementation:
flags, targeting_rules, overrides, audit_logs) has a mandatory tenant_id (or organization_id). All database queries must include this filter at the application or ORM layer. Use Row-Level Security (RLS) in the database as a final safeguard.flags: id, tenant_id, key, description, creation_time.flag_hierarchy_links: child_tenant_id, parent_tenant_id, inheritance_enabled (bool). This table defines the DAG (Directed Acyclic Graph) of your tenant hierarchy.Principle: A child tenant (e.g., a specific Workspace) inherits flag configurations from its parent (e.g., the Organization) unless it has an explicit local configuration or an override is applied.
How it Works:
Organization level, it is visible (but not yet active) in all child Workspaces.Tenant C:
Tenant C.C -> B (Org) -> A (Platform)) until a local configuration for the flag key is found.Platform defines new_dashboard: OFF for all.Org-A enables new_dashboard: ON for employee emails.Workspace-A1 (child of Org-A) has no local config.@company.com emails see the new dashboard ON (inherited from Org-A).Principle: Overrides are direct, declarative assignments that take precedence over inherited rules. They are a "break glass" mechanism for tenant admins or platform operators.
Types & Precedence (Highest to Lowest):
user:alice@example.com -> flag:true).segment:"beta_testers" -> flag:true).Implementation:
flag_overrides (id, tenant_id, flag_id, override_type, target_value, target_identifier, created_by, created_at).(tenant_id, flag_id, override_type, target_identifier)).expires_at fields and be surfaced prominently in auditing/UI as "non-standard."Principle: Every single change to a flag's definition, rule, override, or hierarchy link must be immutably logged with full context.
What to Log (The "Who, What, When, Where, Why"):
user_id (platform admin or tenant admin) + tenant_id they were acting within.CREATE_FLAG, UPDATE_ROLLOUT, ADD_OVERRIDE, CHANGE_HIERARCHY, DELETE_FLAG.flag_id, flag_key.previous_value and new_value separately.source_tenant_id (for inheritance changes).change_note field from the admin (e.g., "Enable for Q4 marketing campaign").Implementation:
flags table) and an immutable audit store in the same transaction. The audit store can be:
audit_logs table with partitioned by date.GET /flags/{key}/history?tenant_id=xyz returns all changes for that flag within that tenant's scope.GET /audit?tenant_id=xyz&start_date=... for compliance reporting.GET /debug/evaluate?flag=xyz&context={...}&tenant_id=xyz returns exactly which rule (override, local, inherited) won and the audit log ID of its creation.Here’s the deterministic algorithm the Flag Evaluation Service follows for (tenant_id, flag_key, context):
tenant_id is active and the caller has permission to access this tenant's flags.tenant_id (e.g., [Workspace-A1, Org-A, Platform]).flag_overrides for flag_key and tenant_id and all parent tenant IDs in the path.
b. Filter overrides where context matches (user, segment, etc.).
c. If match found: Return target_value. LOG this evaluation path in a lightweight, transient debug log.tenant in path (from leaf to root):
i. Check if flag has a local configuration (status, rollout, rules) for flag_key.
ii. If found: Evaluate this config's rules against the context. Return the result. LOG the source tenant of the config.
b. If none found, return Platform Default (typically false/OFF).(context_hash, result) for a short period (e.g., 1-5 min) with a key that includes the tenant_hierarchy_version. Invalidate cache on any flag change in the hierarchy.expires_at > 30 days").SuperAdmin, SupportAgent (read-only all), ComplianceOfficer.OrgAdmin (full control within org), WorkspaceAdmin (control only within workspace, cannot break inheritance from parent), ReadOnly.WorkspaceAdmin cannot create a local flag that conflicts with an inherited disabled flag from Org? Decision Required: This is a key policy choice. Usually, yes—local config can override inherited config (child has priority). But you might want a "locked" flag concept at the Org level.tenant_id.email:alice@example.com). Encrypt these fields at rest. Provide data redaction for audit export.change_note for all flag mutations. Integrate with Jira/ServiceNow via webhooks for critical flag changes.| Concept | Implementation Artifact | Key Property |
|---|---|---|
| Isolation | tenant_id in all tables + RLS | Zero cross-tenant visibility |
| Inheritance | flag_hierarchy_links DAG + "first writer wins" traversal | Defaults flow down, child has priority |
| Overrides | flag_overrides table with precedence order | Fast, explicit exceptions |
| Audit | Immutable audit_logs (snapshot + context) | Immutable, queryable, complete |
| Evaluation | Deterministic service: Overrides -> Local Config -> Inherited Config | Fast, debuggable, consistent |
This design provides a powerful, secure, and auditable governance model. It empowers tenant admins with flexibility within their sphere while giving the platform owner ultimate oversight and control through the hierarchical model and comprehensive audit trails. The most complex part is the hierarchy traversal and conflict resolution logic, which must be rigorously tested and documented.