Leader-gated stream processor and dispatch scheduler for per-group FIFO in HA
Status
Section titled “Status”Accepted.
Approx. 2026-05 (the standby package was added 2026-05-26).
Context
Section titled “Context”FlowCatalyst runs as one binary, and teams run several instances for availability. Some subsystems keep ordering in process memory: the router’s per-group drainer, the stream processor that moves accepted events forward, and the dispatch scheduler that claims jobs and publishes them. If two instances run any of these at once, two drainers can deliver the same group’s messages concurrently and order is lost. Duplicate scheduling also wastes work.
Stateless subsystems (the HTTP API, the console) have no such constraint and should scale horizontally without coordination.
Decision
Section titled “Decision”- Single-active subsystems are leader-gated. With
FC_STANDBY_ENABLED=true, instances contend for a Redis lock (SET NX EXwith periodic refresh, keyFC_STANDBY_LOCK_KEY, defaultfc:server:leader). Background subsystems elect on subsystem-suffixed keys, such as…:stream, so leadership can spread across instances. - The router starts its pools only on acquiring leadership. On loss it follows the same drain sequence as shutdown (stop intake, drain, stop).
- Election failure fails closed: if the instance cannot confirm leadership, the gated subsystem does not run.
- Scheduled jobs are the exception. Each tick is claimed in the database before a firing is created, so a tick fires once even if two nodes both believe they lead. That keeps duplicate firings away without depending on Redis timing alone.
- When standby is disabled (the default, and the single-instance case), subsystems start unconditionally.
Consequences
Section titled “Consequences”Good:
- Per-group FIFO holds in a multi-instance deployment without moving the ordering state into a shared store.
- Standby instances are warm: the API stays active on all of them, and failover is a lease expiry.
- Failing closed prefers a pause over silent reordering.
Bad:
- Redis becomes a dependency for HA. A Redis outage pauses the gated subsystems.
- Failover time is bounded by the lease TTL; messages wait, they are not lost.
- Throughput of these subsystems scales vertically, with the leader as the ceiling. Subsystem-suffixed keys help only by distributing different subsystems across instances.
Alternatives considered
Section titled “Alternatives considered”| Alternative | Why not |
|---|---|
| Postgres advisory locks | Viable, but ties leadership to a connection and complicates pool sizing. Redis was already in use for caches. |
| Partition groups across instances (consistent hashing) | Needs ownership rebalancing and a handoff protocol for in-memory buffers. |
| Run active-active and de-duplicate downstream | Cannot restore order. |