Architecture

Small, boring, self-hostable

Four containers and PostgreSQL. No message broker, no cloud services. Watch one outage move through the system, from alert to recovery; pause it or jump to any chapter.

SQL read job write + verify Vendor status pages ~70 live sources, polled Your alerts signed webhooks Your team browser · Slack · SSO FlagMesh FastAPI · Next.js · worker PostgreSQL state · job queue · audit chain Worker apply · read back · verify Flagsmith Management API · Feature Health Watch + intake Blast radius Approvals by role SSO · roles Audit chain

An outage starts · step 1 of 5

A vendor's bad day opens your incident, by itself.

FlagMesh polls about 70 public sources: vendor status pages, AWS, Google Cloud and Azure health, internet outage monitors and news.

Flagsmith stays the source of truth for flags. FlagMesh talks to it only through the Management API and Feature Health, never its database.

Inside the API

One codebase, clear seams

Thin routers, services hold the logic, repositories hold the queries, adapters live in integrations/.

01

Intake

integrations/vendors.py · alertmanager.py

Five vendor formats, Alertmanager v4 and a signed generic webhook become one signal shape. Constant-time secret checks, HMAC with a 5-minute replay window, dedupe on (source, fingerprint).

02

Correlation

services/incidents.py

An open incident for the same resource absorbs new signals. Resolved incidents are never reopened silently, and a resolved signal never closes an incident on its own.

03

Blast radius

services/blast_radius.py

Reverse breadth-first walk over dependency edges up to depth 6. Path confidence is the weakest edge on the path. Coverage gaps (unmapped, ownerless, stale, no fallback) always come back too.

04

Actions + approvals

services/actions.py · slack_approvals.py

Proposals are checked against live Flagsmith state and capture each prior state. Approval needs the approve permission, never the requester, from the UI or Slack.

05

Execution

services/execution.py · workers/

Ordered writes through the Management API, a drift check before and a read-back after each one, stop on first failure, at most 25 items per request.

06

Auth + RBAC

integrations/oidc.py · security/rbac.py

OIDC with PKCE, state and nonce; scrypt passwords with lockout; hashed API tokens for break-glass. Seven roles, every query scoped by workspace from the session, never from input.

State machines

Every state is explicit

Incident

Promotions are human decisions, each one audited.

alertsuspectedconfirmedresolvedclosed

Action request

Mitigation and recovery share this lifecycle; recovery needs its own approval.

proposedapprovedqueuedexecutingsucceeded
rejectedfailedcancelleddry_run_complete

Job

Backoff 2ⁿ seconds, capped at 300 s, then dead letter. Stale running jobs are reclaimed.

queuedrunningsucceeded
failed → retrydeadcancelled
Blast radius

Walk the graph backwards

When a resource fails, FlagMesh asks “who depends on this?” and follows edges outward, ring by ring.

  • Depth limit 6, configurable. Cheap at the expected 10⁴ edges per workspace.
  • Path confidence is the weakest edge: verified, declared or inferred.
  • Coverage gaps always returned: unmapped features, ownerless resources, edges older than 90 days, features with no fallback.
  • Honest output: nothing declared means “nothing declared”, never “no impact”.
verifieddeclaredverifiedinferreddeclared AI provider unavailable summary-svc service chat-svc service AI summaries feature · fallback ✓ Weekly digest feature · no fallback Help chat bot feature · fallback ✓
Depth 0 fails, depth 1 and 2 light up in turn. “Weekly digest” is flagged as a gap: no fallback declared.
job claim, simplified
SELECT * FROM jobs
 WHERE status = 'queued'
   AND run_after <= now()
 ORDER BY run_after
 LIMIT 1
 FOR UPDATE SKIP LOCKED;

-- on failure
run_after = now() + min(2^attempts, 300) s
status    = attempts >= max ? 'dead' : 'queued'
Job queue

The queue is a table

Approval and enqueue commit in one transaction, so an approved change is never lost and never queued twice.

  • Idempotency key on the request id. Retrying an approval cannot double-apply.
  • SKIP LOCKED lets any number of workers run side by side without stepping on each other.
  • Backoff and dead letter: 2ⁿ seconds capped at 300, then dead for a human to look at.
  • Flagsmith down? Reads and incident work continue; execution retries and shows the failure.
Audit

A log you can't quietly edit

Each event's hash covers the previous hash plus its own canonical JSON. Writes are serialised per workspace with a PostgreSQL advisory lock, so the chain never forks.

#41 incident.confirmed
prev
9f2c…a71e
hash
4b0d…13c2
#42 action.approved
prev
4b0d…13c2
hash
e87a…5f90
#43 flag.applied
prev
e87a…5f90
hash
1c6f…b2d4
#44 flag.verified
prev
1c6f…b2d4
hash
77e3…0a5b

hash = sha256(prev_hash ‖ canonical_json(event)) · change one byte anywhere and every later hash stops matching.

Security

Defence in layers

Secrets stay server-side

The Flagsmith key, SSO and Slack secrets live in the API, encrypted with FLAGMESH_SECRET_KEY. The browser only ever talks to the Next.js server.

Sessions, not tokens, in the browser

Opaque 12-hour server-side sessions in an httpOnly cookie. Nothing a script can read.

Signed everything

HMAC-SHA256 webhooks with timestamps, signed Slack interactivity, OIDC ID tokens checked against the provider's JWKS.

Tenant isolation

Workspace comes from the authenticated membership on every query, never from the request alone.

Approval by role

Production changes need an approver with the right role who is not the requester. Enforced in the API, mirrored in the UI.

Tamper evidence

The audit chain is append-only and hash-linked; verification recomputes every hash from the start.

Deployment

What runs

UnitBuilt withScalesPort
websiteAstro, staticCDN or nginx:4321
frontendNext.js App Router, TypeScriptstateless, horizontal:3000
apiFastAPI, Pydantic v2, SQLAlchemy 2, Alembicstateless, horizontal:8080
workerPython, shares the backend packagehorizontal via SKIP LOCKEDnone
postgresPostgreSQLsystem of record and queueinternal
Tradeoffs

What we chose not to build

ChoseOverWhy
Modular monolith + workerMicroservicesSmall team, shared transactions.
Queue in PostgreSQLRedis, Celery, KafkaTransactional enqueue, one less moving part. Tens of actions per hour, not thousands per second.
Relational graph + BFSNeo4jUp to about 10⁴ edges per workspace; recursive CTEs if it ever needs more.
Refuse v2-versioned environmentsImplement the versions APICorrect or nothing in v0.1.
Management API onlyRead Flagsmith's databaseFlagsmith stays the source of truth and its upgrade path stays clean.

The full design record lives in decisions/ARCHITECTURE.md in the repository.