Skip to content

fc-server and subsystems

fc-server is the platform’s one production binary. Every running part of the platform except the ingestor runtime is a subsystem inside it, switched on or off with an environment variable, so the same image can run as an all-in-one server, as an API tier, as a worker tier, or as a router on its own. fcdev wraps the same orchestrator (server.Run) with an embedded PostgreSQL and development defaults (see fcdev).

This page is about the binary itself: what it reads, what it starts, in which order, and how copies coordinate. The components overview has the one-line summary of each subsystem; the other Platform pages go inside each one.

Subsystem Toggle (alias) Default Needs the database Runs on
Platform API, console, OIDC provider, delivery callback FC_PLATFORM_ENABLED (PLATFORM_ENABLED) on Yes Every replica
Platform housekeeping with the platform on Yes Every replica (idempotent sweeps)
Ingestion routes FC_INGESTION_ENABLED off Yes Every replica (part of the API)
Stream processor FC_STREAM_PROCESSOR_ENABLED (STREAM_PROCESSOR_ENABLED) off Yes Leader of <lock>:stream
Dispatch scheduler FC_SCHEDULER_ENABLED (DISPATCH_SCHEDULER_ENABLED) off Yes (its own pool) Leader of <lock>:scheduler
Scheduled-job scheduler FC_SCHEDULED_JOB_ENABLED (SCHEDULED_JOB_SCHEDULER_ENABLED) off Yes Leader of <lock>:scheduled-job
Outbox processor FC_OUTBOX_ENABLED (OUTBOX_PROCESSOR_ENABLED) off Yes, or MySQL, MongoDB or SQLite (FC_OUTBOX_BACKEND) Leader of <lock>:outbox
Message router FC_ROUTER_ENABLED (MESSAGE_ROUTER_ENABLED) off No Leader of <lock> (pools start only on the leader)
Push gateway FC_PUSH_ENABLED off Yes Every replica serves streams; one relay at a time (database lock)
MCP server FC_MCP_ENABLED off No (calls the API) Every replica
Function runner FC_FUNCTIONS_ENABLED off No (calls the API) Every replica

<lock> is FC_STANDBY_LOCK_KEY, default fc:server:leader. The stream processor’s four loops have their own sub-toggles, on by default, so the top-level switch is enough.

Configuration comes only from the environment. There are no configuration files. The central loader is server.LoadEnv (internal/server/envcfg.go); a handful of packages read their own variables at start-up (encryption, email, rate limits, login backoff, the scheduled-job scheduler, MCP, the function runner). Older variable names used by existing deployments are honoured as aliases; the FC_ name wins when both are set. Every variable is in the environment reference. See one binary with subsystem toggles.

Listener Default Variable Serves
API :8080 FC_API_PORT (PORT) /api, /bff, /oauth, /auth, /portal, /field, /ui, the router under /router, the push gateway, /health
Metrics :9090 FC_METRICS_PORT /metrics (Go runtime and process metrics, plus the scheduler’s and the push gateway’s), /health, /ready
MCP 127.0.0.1:8090 FC_MCP_BIND, FC_MCP_PORT /mcp (streamable HTTP), /health
Function runner 0.0.0.0:8095 FC_FUNCTIONS_BIND, FC_FUNCTIONS_PORT /fn/<address><path>; an optional public entry on FC_FUNCTIONS_PUBLIC_PORT
Outbox admin off FC_OUTBOX_ADMIN_PORT Group state on 127.0.0.1 only

The router’s own Prometheus series are served at /router/metrics on the API listener, not on the metrics port.

sequenceDiagram
  participant M as main
  participant DB as PostgreSQL
  participant R as server.Run
  M->>M: LoadEnv, refuse test headers outside local/test
  M->>M: outbound guard policy, runtime tuning
  alt a database-backed subsystem is enabled
    M->>DB: resolve credentials (URL, DB_* or Secrets Manager)
    M->>DB: connect
    M->>DB: migrations (goose, bootstrap first)
    M->>DB: seed roles, permissions, event types, bootstrap admin
  end
  M->>R: Run
  R->>R: resolve dispatch queue settings (fail fast)
  R->>R: wire platform API, router surface, push gateway
  R->>R: bind API and metrics listeners
  R->>R: start housekeeping and subsystems
  R->>R: serve
  1. Load and check configuration. fc-server refuses to start if FC_AUTH_ALLOW_TEST_HEADERS is on and APP_ENV is not local or test: that header bypasses authentication.
  2. Outbound policy. The delivery guard is configured. The function runner’s URLs are exempted for the platform’s own deliveries to it, never for customer-supplied URLs; the dispatch callback needs no exemption.
  3. Runtime tuning (internal/runtimetune). Under a CPU quota of one core or less, with no explicit GOMAXPROCS, it is set to 1. When the router or the dispatch scheduler runs and GOGC is not set, the GC target is raised (FC_GC_PERCENT, default 200) and a soft memory limit of 90% of the container’s limit is set, unless GOMEMLIMIT is.
  4. Database. Only if a database-backed subsystem is on; a router-only process skips this entirely. The URL comes from FC_DATABASE_URL (DATABASE_URL), else from DB_HOST, DB_NAME, DB_USERNAME and DB_PASSWORD, else from AWS Secrets Manager (DB_SECRET_ARN with DB_HOST), which can also be polled for rotated credentials (DB_SECRET_REFRESH_INTERVAL_MS) and injected into new connections without a restart.
  5. Migrations run before anything else touches the schema (see data model). A failure stops the process.
  6. Seeding inserts built-in roles, permissions, platform event types and default processes when missing (it never rewrites an existing built-in role). The initial anchor administrator is created only when FLOWCATALYST_BOOTSTRAP_ADMIN_EMAIL and FLOWCATALYST_BOOTSTRAP_ADMIN_PASSWORD are both set and no anchor user exists yet.
  7. server.Run resolves the dispatch queue settings once (an SQS type without a prefix stops the server here), wires the platform API, mounts the router’s HTTP surface and the push gateway, then binds the listeners before starting the subsystems. The router fetches its configuration document over HTTP, and in a single-process deployment that document is served by this very listener; binding first means the first fetch finds an open port. Serving starts after the subsystems, so nothing is answered before its dependencies run.

A panic in main’s own call tree is logged as one structured JSON line before the process exits.

These loops run with the platform on every replica, not leader-gated, because each one is a bounded, idempotent statement:

Loop Cadence Work
Auth purger Every minute Expired OAuth payloads, OIDC login states, passkey ceremonies, portal login flows, expired email PINs, trusted devices and password-reset tokens, reset-approval requests 90 days after they end, field nonces, codes and sessions, old field sign-in attempts, rate-limit events, lapsed previous client secrets; keeps iam_login_attempts quarterly partitions ahead and drops those older than three years
Stranded-sibling reaper Every 2 minutes Returns QUEUED or PROCESSING siblings behind a failed BLOCK_ON_ERROR head to PENDING
Dispatch-job key retention Every 10 minutes Prunes idempotency keys older than 7 days
Function trace retention Hourly by default Prunes trace records past retention
Ingestion retention and unheld gauge Periodic, when ingestion is on Prunes runtime records; counts polled ingestions no runtime holds
Function control-plane listener Continuous LISTENs for desired-state changes and wakes this replica’s waiting runners

With FC_STANDBY_ENABLED=true (alias STANDBY_ENABLED), copies elect leaders through Redis (FC_STANDBY_REDIS_URL, falling back to REDIS_URL). The algorithm (internal/standby) is a SET NX EX lock with a 30-second lifetime, refreshed every 10 seconds by a compare-and-extend script. Any Redis error demotes a leader at once (it would rather stop working than risk a second leader). A copy that shuts down cleanly releases its lock, so a follower takes over at its next attempt, within 10 seconds; if the leader dies instead, its lock expires and failover takes up to about 40 seconds.

Each leader-gated subsystem runs its own election on a suffixed key (fc:server:leader:stream, :scheduler, :scheduled-job, :outbox); the router uses the bare key. Leadership of different subsystems can therefore land on different copies, and one subsystem’s election never starves another’s.

stateDiagram-v2
  [*] --> Follower
  Follower --> Leader: acquired the lock
  Leader --> Leader: refresh every 10 s
  Leader --> Follower: lock lost or Redis error
  Follower --> Follower: lock held elsewhere, retry
Subsystem While a follower On becoming leader On losing leadership
Stream processor Loops idle, claim nothing Claims whatever is unstamped Stops claiming; open transactions finish or roll back
Dispatch scheduler Poller, stale recovery and backlog idle Claims what is PENDING with an empty in-flight set Stops claiming; lanes finish their batch
Scheduled-job scheduler Both loops idle Fires each job’s latest unclaimed slot Stops
Outbox processor Polls nothing Rebuilds blocked groups from the table, then claims Forgets its preparation
Router Pools not started Starts pools, registers with the load balancer Deregisters, stops polling, drains, releases buffers

Elections fail closed. If the election cannot be created or started (Redis unreachable at boot), the subsystem is never leader in that process. Standby is on, so other copies exist, and running ungated would break the single-active rule the gate exists for.

Without standby every copy is its own leader. Run exactly one copy of each leader-gated subsystem then. The API, housekeeping, MCP and the function runner can always run on any number of copies. See leader-gated processors and the leader failover runbook.

Two subcommands of the same binary run once and exit. Both connect to the database fc-server would use (FC_DATABASE_URL, DB_* or DB_SECRET_ARN), neither runs migrations, and both need FLOWCATALYST_APP_KEY.

Command What it does
fc-server signing-keys list Lists every key in the JWT keyring: KID, algorithm, status, source and its dates
fc-server signing-keys rotate --alg ALG [--immediate] Prepares a successor for RS256, EdDSA, ML-DSA-65 or HS256. Without --immediate it signs after the usual publish lead; with it, it signs now and the old key is retired but still verifies for the retire grace
fc-server signing-keys expire KID Ends a PENDING or RETIRED key now: it stops verifying on every process within 30 seconds and its private key is erased
fc-server reencrypt [--dry-run] [--batch-size N] Re-encrypts every value stored under FLOWCATALYST_APP_KEY with the current key, after a key rotation. Values open with the current key or any in FLOWCATALYST_APP_KEY_PREVIOUS. It rewrites row by row with compare-and-set, so it is safe while the platform serves traffic and safe to rerun. --batch-size defaults to 500

reencrypt exits 0 when done, 1 on an error (rerun to resume), 2 on a usage error and 3 when it finished but some values no configured key opens (listed in the log by row, never by value). Run it only once every process has been deployed with the new key as current. The signing-key commands audit every change. The keyring itself, its automatic rotation and the emergency procedure are described in the security model and the key rotation runbook.

On SIGTERM or SIGINT:

  1. The push gateway ends its open streams and refuses new ones with 503, so clients reconnect to another copy.
  2. Every subsystem’s context is cancelled. The router starts its own ordered drain (deregister, stop polling, wait up to FC_DRAIN_TIMEOUT_SECONDS, 60).
  3. The API and metrics servers shut down gracefully, waiting up to 30 seconds for requests in flight.
  4. Run waits for every subsystem to return, then the database pool closes.

Subsystems are cancelled before the pool closes, so no loop keeps polling a closed pool.

SIGQUIT does not stop the process: it writes a dump of the router’s workers, held groups and every goroutine to stderr. A second SIGQUIT within 5 seconds dumps and exits.

Endpoint Meaning
GET /health (API and metrics listeners) The binary is up: {"status": "UP", "version": ...}
GET /ready (metrics listener) Ready to serve
/router/health/live, /ready, /startup Router probes, when the router runs

Logs are JSON on stderr; FC_LOG_LEVEL sets the level (debug, info, warn, error; default info). FC_DEBUG_ENDPOINTS_ENABLED=true mounts pprof, expvar and the router dump under /router/debug/ (or /debug/ without the router). They always require authentication (router Basic auth, or an anchor principal’s bearer token or session) and are not mounted at all if neither is available.

Shape Toggles
All-in-one (small deployments, one copy) Platform, stream, scheduler, scheduled-job, router; outbox if the platform drains its own outbox
API tier, any number of copies Platform only
Worker tier, two or more copies with standby Stream, scheduler, scheduled-job, router, FC_STANDBY_ENABLED=true; set FC_DISPATCH_PROCESSING_ENDPOINT to the API tier
Router on its own Router only: no database, configured from the platform’s document
Function runners Function runner only, one deployment per runner pool
Push gateway Push gateway (with or without the platform), behind its own route

The topologies, sizing and cloud specifics are in deployment topologies and scaling.