Skip to content

Leader failover

Symptom. One of the single-active subsystems stopped working: dispatch jobs stay PENDING (no scheduler polling), events are not fanned out to subscriptions, scheduled jobs do not fire, the router consumes nothing, or the outbox relay sends nothing. Often after a deploy, a node failure or a Redis incident. Less often the opposite: signs that two copies are active at once (jobs of an ordered group delivered out of order).

With FC_STANDBY_ENABLED=true, each single-active subsystem holds a lock in Redis (FC_STANDBY_REDIS_URL):

Subsystem Lock key (default prefix fc:server:leader)
Router fc:server:leader
Dispatch scheduler fc:server:leader:scheduler
Stream processor (fan-out, projections, partitions) fc:server:leader:stream
Scheduled-job scheduler fc:server:leader:scheduled-job
Outbox processor fc:server:leader:outbox

The holder’s instance id is the key’s value. The lock lives 30 seconds and the holder refreshes it every 10. A standby tries to take it every 10 seconds. A leader that dies stops refreshing, so a standby takes over within about 40 seconds; one that shuts down cleanly releases the lock and is replaced at the standby’s next attempt.

Two properties matter when things go wrong:

  • Fail closed. A process that cannot reach Redis gives up leadership at once and stays a follower until Redis answers. It never falls back to “assume I am leader”.
  • Without standby, every copy is leader. FC_STANDBY_ENABLED=false means each process that runs a single-active subsystem runs it actively.
  • Router: GET <prefix>/monitoring/standby-status on each router replica answers enabled, is_leader and instance_id.
  • Dispatch scheduler: only the leader polls, so the leader is the replica whose fc_scheduler_last_successful_poll_timestamp_seconds keeps moving.
  • Any subsystem: read the lock in Redis.
Terminal window
redis-cli -u "$FC_STANDBY_REDIS_URL" GET fc:server:leader:scheduler
redis-cli -u "$FC_STANDBY_REDIS_URL" TTL fc:server:leader:scheduler

A key that exists with a TTL between 20 and 30 seconds has a live holder. No key means nobody holds it; a key whose TTL counts down to zero without being refreshed means the holder stopped.

Cause Signs Action
No process runs the subsystem No replica has the FC_*_ENABLED flag; no scheduler started or stream processor started in any log Fix the deployment’s environment
Redis unreachable leader election start failed; failing closed (never leader) at start-up, or every replica a follower; Redis errors Restore Redis. Leadership resumes within about 10 seconds of Redis answering
The election could not even be created leader election init failed; failing closed: usually a malformed FC_STANDBY_REDIS_URL Fix the URL and restart
The router never started router run failed in the log: the router’s own election needs Redis at start-up, and if it cannot reach it the router does not start in that process. The rest of the process keeps running Restore Redis, then restart the router processes. They do not retry on their own

While nobody leads, the API keeps serving: events and jobs are accepted and stored, and processing catches up when a leader returns.

The lock is refreshed by its own loop, independently of the work. A leader whose subsystem is wedged but whose process is alive keeps the lock, and no standby takes over. Signs: the lock’s TTL keeps resetting, but the subsystem’s own signals (the scheduler’s poll timestamp, the fan-out backlog, the router’s queues) stand still.

Action: restart that process. A clean shutdown releases its locks, and a standby takes over within 10 seconds. Prefer this to deleting the Redis key by hand: a deleted key is simply taken again by the next process to try, which may be the stuck one.

For the router, the dashboard and <prefix>/monitoring/consumer-health show whether its consumers are polling; a router whose consumers have all stalled reports itself degraded and not ready.

Cause What to do
Two replicas with FC_STANDBY_ENABLED=false Enable standby with a shared Redis, or run one replica
Replicas configured with different FC_STANDBY_LOCK_KEY or different Redis servers Every replica of a deployment must use the same Redis and the same key
A brief overlap during a Redis failover (an asynchronous replica promoted without the latest lock) The old leader notices at its next refresh (within 10 seconds) and steps down. Ordering within that window is not guaranteed; check affected groups

Scheduled jobs are protected regardless: each firing slot is claimed in the database, so two schedulers cannot fire the same slot twice. Dispatch ordering and the router’s per-group buffers have no such second guard; that is why the rest must stay single.

What the new leader does, so you know what to expect:

  • Dispatch scheduler: starts with an empty in-flight set and claims what is PENDING. Jobs the old leader published but had not marked QUEUED are published again; the router and the callback absorb the duplicates.
  • Stream processor: resumes fan-out and projection from the database’s markers; nothing is lost or done twice. Its partition manager’s next pass runs on the new leader at its next daily tick; partitions exist months ahead, so the wait is harmless.
  • Router: the old leader stopped polling, let in-flight deliveries finish (up to FC_DRAIN_TIMEOUT_SECONDS) and handed buffered messages back to the broker. The new leader consumes them; ordered groups come back in order.
  • Outbox processor: rebuilds its blocked groups from the stored refusals before its first claim, and returns rows left in a retryable failure status to PENDING.
  • Scheduled-job scheduler: fires the most recent due slot of each job (earlier missed slots are skipped), and abandons instances stuck in flight past their timeout.