Sherlock's Analysis: A federated feature flag system requires balancing autonomy for distributed teams (e.g., microservices, business units) with centralized control to prevent chaos, ensure compliance, and enable safe rollouts. This framework enforces policy inheritance (hierarchical defaults), isolation (scoped namespaces), audit trails (immutable logs), and overrides (targeted exceptions with safeguards). It's designed for scalability in cloud-native environments like Kubernetes, using a central store (e.g., Postgres + Redis) and APIs.
Core Architecture
code
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Global Org │───▶│ Team A │───▶│ Service X │
│ Policies │ │ Policies │ │ Flags │
└──────────┬──────┘ └──────────┬──────┘ └──────────┬──────┘
│ │ │
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Audit Store │◀────│ Overrides │◀────│ Evaluation │
│ (Immutable) │ │ (Ephemeral) │ │ Engine │
└──────────────┘ └──────────────┘ └──────────────┘
Entities:
Entity
Scope
Owner
Org
Global
Admins
Team
Business unit
Team Leads
Service
Microservice
Devs
Env
Prod/Staging
Ops
Storage:
Persistent: Postgres for policies/flags/audits.
Cache: Redis for low-latency evaluations.
API: gRPC/REST gateway with RBAC (e.g., via OPA).
1. Policy Inheritance
Policies cascade down the hierarchy. A flag evaluates by merging from root to leaf, with deeper levels overriding shallower ones (unless locked).
Immutable, tamper-proof logs for every mutation/evaluation.
Events:
Event Type
Triggers
Payload Example
CREATE
New flag/policy
{fqn, value, actor_id, timestamp}
UPDATE
Override/rollout change
{fqn, old_value, new_value, reason}
DELETE
Flag removal
{fqn, actor_id}
EVAL
Runtime check (sampled)
{fqn, context.user_id, resolved_value}
Storage: Append-only table with signatures (e.g., BLS for blockchain-like integrity).
sql
CREATE TABLE audits (
id UUID PRIMARY KEY,
fqn TEXT NOT NULL,
event_type TEXT NOT NULL,
payload JSONB NOT NULL,
actor_id UUID NOT NULL,
timestamp TIMESTAMPTZ DEFAULT NOW(),
signature BYTEA NOT NULL -- Cryptographic hash
);
Query API: GET /v1/audits? fqn=org-1.team-sales.*&since=2023-01-01
4. Overrides
Temporary, approved deviations from inherited policies.