gobridge

Hot-reload and production config updates

Hot-Reload

GoBridge watches the bootstrap-selected config source: a file with a poll-based watcher, or a DynamoDB config item with strongly consistent polling or Streams. Both feed the same config manager and runtime apply path without process restart. Clustered deployments retain their existing rollout barrier or whole-cohort replacement requirements; changing the source does not bypass them.

Reload Sequence (file source)

sequenceDiagram
    participant EFS as EFS (bridge.yaml)
    participant W as Poll Watcher
    participant M as Config Manager
    participant A as App (bootstrap)
    participant RT as Runtime

    loop every poll_interval
        W->>EFS: Read file + SHA-256 hash
        alt content changed
            W->>M: Emit new BridgeConfig
            M->>M: Merge layers + validate
            M->>A: Config change event
            A->>A: resolveInputs (SSM keys)
            alt only reload units changed
                A->>RT: Retire changed units
                A->>RT: Graft their replacements
            else bridge-wide or HTTP change
                A->>RT: Build new runtime
                A->>RT: Start new runtime
                A->>RT: Stop old runtime
            end
        end
    end

Why Poll Mode Instead of Notify

The bootstrap library forces poll mode (ModePoll) for file watching. The default notify mode uses fsnotify (kernel inotify/kqueue events), which does not reliably propagate across NFS mounts. EFS is an NFS-based file system, so writes from one Fargate task or an external writer may not trigger inotify events on other tasks. Poll mode reads the file at a fixed interval and compares SHA-256 hashes, which works reliably regardless of the underlying filesystem.

Poll Interval Tuning (file source)

Environment Recommended poll_interval Rationale
Development "1s" (default) Fast feedback during local iteration.
Staging "5s" Balance between responsiveness and EFS read cost.
Production "5s" to "30s" Lower EFS I/O; config changes are infrequent.

DynamoDB source

DynamoDB config polling defaults to 30s; poll_interval overrides it. The loader watches the version of the current item for config#<bridge_id> and also serves as the admin ConditionalConfigStore, so commits use atomic compare-and-swap rather than the file source single-writer assumption. Streams mode uses the same loader and requires an enabled stream and read permissions; config_dynamodb.stream_poll_interval controls its GetRecords cadence. The adapter falls back to polling if Streams is unavailable.

The EFS update procedure below applies to the file source. For DynamoDB, update the selected item through CAS-aware tooling or admin transactions, preserving its monotonically increasing version. A missing item starts the transaction at version zero; the first successful CAS commit creates version one. Other source errors fail the transaction rather than falling back to an empty config. Config validation, runtime apply and cluster rollout coordination remain unchanged.

Admin applies and watcher updates are serialized within each process. For the DynamoDB source, an update older than either the latest logical config or the running config is ignored before it can change runtime or health state. This prevents a delayed admin apply from undoing a newer writer’s change. A superseded commit remains successful without applying or rolling back its older version; the response confirms that the write succeeded, not that its version is still running. Replaying the same version retains content-based deduplication and can retry a failed apply. Restoring old content through CAS creates a new version. This ordering rule does not apply to operator-controlled file versions, to coordinated boot/barrier decisions, or to recovery of the last good runtime.

In-place reload

A change reconnects only what it touches. The bootstrap library splits each configuration into reload units: groups of sessions, receivers, senders, bindings and routes joined by the ids they reference (a session_id, a binding’s sender_id, a route’s receiver_id, bindings and session block). On a change it compares the units of the running and the new configuration. A unit whose content is the same in both keeps running untouched: its sessions stay connected and its routes keep delivering. A unit that changed, or was removed, is drained, stopped and removed from the running runtime; a unit that changed, or was added, is built over the running runtime’s stores and started inside it. Routes that share a session are one unit, so give each tenant its own sessions when tenants must not disturb each other. See ADR 0018.

The in-place attempt runs after the same deployment-profile admission, cluster checks and durable-state guards as every apply, with the secrets resolved once for it and for the full swap that may follow. The bootstrap library falls back to the full swap when:

When an added unit claims an exclusive broker identity, or a retired unit holds one on a transport an added unit still attaches to (the bridge.RequiresSerializedSwap rule under Swap Modes, asked of the retired units against the added ones), the retired units stop before their replacements are built; otherwise the replacements are built first. Inside the runtime a replaced unit always stops before its replacement starts, so a changed unit has a short gap — its drain plus its start — even on SQS, where a full overlap swap has none. Unchanged units have no gap.

A successful in-place reload keeps the same runtime and transport factories, restarts the post-swap convergence watch, and logs:

bootstrap: reloaded in place  outcome=applied retired_routes=[...] added_routes=[...] retired_sessions=[...] added_sessions=[...]

A failure logs bootstrap: in-place reload failed with the same fields, the outcome and the error, and ends one of three ways:

Keeping MQTT tenants connected

An MQTT session’s options depend only on its own configuration. Its receive_maximum is the count you set, or the default 192; nothing is derived from the task memory or from the number of other sessions. So adding one tenant’s MQTT session, or removing an ephemeral one, replaces only that session’s reload unit. Every other tenant’s MQTT session stays connected. No per-session setting is needed to keep them apart. Removing a persistent or exclusive session also replaces only its unit, and ends the broker session it leaves behind; see reloads that change a durable broker identity.

GoBridge does not estimate memory. It limits MQTT by counts:

A reload that would go over bridge.max_mqtt_sessions is refused, and the running configuration keeps serving. Changing the limit itself is a change to the bridge section, so it uses the full swap. Choose the task size (MemoryMiB) by measuring the deployment under its real load; see deployment scaling.

sessions:
  - id: tenant-a
    transport: mqtt
    session_mode: persistent
    options:
      session:
        broker_url: tls://broker.example.com:8883
        client_id: bridge-tenant-a
        receive_maximum: 192   # a count; 192 is also the default

Reloads that change a durable broker identity

A live reload accepts a change to a durable subscription’s broker identity, and the removal or rename of what holds it (ADR 0024):

The task retires the old reload unit as for any other change. As it closes the old unit, after in-flight deliveries drained and before it releases the session’s lease, it ends the state the broker keeps for the old identity. MQTT disconnects the session, then connects once more as the old client ID with clean start and disconnects, so the broker deletes that session, its subscriptions and its queued messages. AMQP 1.0 closes the link with a closing detach, so the broker deletes the durable subscription. If the drain does not settle every delivery within drain_timeout, the state is kept (a Warn and BrokerStateEndFailures). So it is when the MQTT session or the AMQP 1.0 receiver still holds a delivery it received and nothing settled, for example one that arrived after the drain and was dropped when its route was cancelled. Only the task that is connected as the identity does this. For an exclusive session it must also hold the session’s lease, and that lease must not have expired by the task’s own clock; an ending that cannot finish before that lease’s deadline is abandoned. Renaming only the session_id ends nothing, because the broker identity is still there. Switching an MQTT session between persistent and exclusive, or changing clean start, the session expiry or the MQTT protocol version, keeps the identity and ends nothing. Changing a session to ephemeral drops the identity, so the reload ends its broker session.

An AMQP 1.0 receiver ends its subscription only when it stops on its own after the retire cancels it. A receiver that is still running when the runtime stops waiting and force-closes it drops the connection instead, and the subscription stays.

If ending the state fails (access denied, broker unreachable), the task logs a Warn naming the session_id, counts BrokerStateEndFailures, and the reload continues. The broker then keeps the state until it expires (MQTT) or for good (AMQP 1.0). An MQTT session whose own disconnect fails sends nothing, because its connection may still be up as the client ID, and counts the same failure.

What such a reload loses:

For no loss, change in two reloads: first add the new session next to the old one, then remove the old one. Messages that arrive while both run are delivered twice; downstream idempotency absorbs them.

A shutdown, a restart, a pause, a lease loss or failover, and the rebuild of a failed session never end broker state.

Reloads that strand durable state

Some changes leave durable state behind when a running task applies them. The AWS runtime refuses them before anything is resolved, seeded or rebuilt, whether the change would reload in place or replace the runtime. The checks and their errors are the Supervisor’s reload guards (bridge.ValidateDurableReload):

Change What it strands
A lease, outbox, DLQ or managed subscription store changes type or backing location (path or table), or the managed subscription store is removed. The records in the old store.
A lease-bearing exclusive route changes its session_id. Ownership of its source: the old and new session_id are different lease keys.
The outbox or DLQ store is removed, or a shared_outbox partition loses its drainer. The outbox or DLQ records.

The running configuration keeps serving, the version is reported rejected, and the config manager logs an Error whose error says what was refused:

config manager: runtime apply FAILED; desired config is NOT running ...  desired_version=4 running_version=3 error="bridge: refusing live reload: it can strand durable records [dlq store removal]; ..."

The Supervisor’s WithAllowDestructiveReload has no AWS counterpart. To make such a change, cut over:

  1. Stop ingress and let the old store’s records drain.
  2. Store the new version in the config source: the file, or the DynamoDB item through CAS-aware tooling. An admin-API commit of it fails and is rolled back. The running task refuses the version and keeps serving.
  3. Restart the task. A starting task has no running configuration to compare with, so it applies the stored version.

A clustered deployment refuses these changes in the cluster reload seam; see the cluster config rollout runbook.

Swap Modes

When a config change cannot be reloaded in place, the bootstrap library must swap the old runtime for a new one. The swap strategy is auto-detected from the new config through bridge.RequiresSerializedSwap, the same check the Supervisor uses.

Overlap mode (default): The new runtime is started first, then the old runtime is stopped. This provides zero-downtime for stateless transports like HTTP and SQS where multiple concurrent listeners are safe.

Prepare/commit mode: The old runtime is stopped first, then the new runtime is built and started. It is selected when the incoming config claims an exclusive broker identity, or when the running config holds one on a transport the incoming config still uses — an ordinary consumer is refused beside an exclusive one that is still attached. A config claims an identity when:

A transport the incoming config no longer uses cannot contend for anything the old runtime holds on it, so dropping a transport altogether keeps overlap.

flowchart TD
    DETECT[Config change detected] --> CHECK{New config exclusive,\nor old one exclusive on a\ntransport still in use?}
    CHECK -- No --> OVERLAP[Overlap Mode]
    CHECK -- Yes --> PREPARE[Prepare/Commit Mode]

    OVERLAP --> O1[Start new runtime]
    O1 --> O2[Stop old runtime]
    O2 --> DONE[Swap complete]

    PREPARE --> P1[Stop old runtime]
    P1 --> P2[Complete + start new runtime]
    P2 --> DONE

    style OVERLAP fill:#27ae60,stroke:#333,color:#fff
    style PREPARE fill:#e67e22,stroke:#333,color:#fff

If the new runtime fails to start in prepare/commit mode, the bootstrap library attempts to recover the previous configuration by rebuilding and restarting the old runtime. This prevents a bad config push from leaving the bridge in a stopped state.


Config Updates in Production

Follow this workflow for safe configuration updates in production.

Update Flow

  1. Update the YAML on EFS. Use CI/CD, a manual mount, or the admin API config-transaction flow (open → patch → commit). The commit enforces optimistic concurrency via the version field (check-and-set). There is no PUT /config endpoint — see HTTP API — Config transactions.

  2. Poll watcher detects the change. Within one poll_interval cycle, the watcher reads the file, computes the SHA-256 hash, and detects the difference.

  3. Config is parsed and validated. The YAML is deserialized into a BridgeConfig struct. The validateFilesystemProfile function checks topology constraints (e.g. shared_outbox routes are rejected under filesystem_replicated topology). A change that would strand durable state is refused.

  4. SSM parameters are resolved. The resolveInputs function reads admin_api_key_param, monitor_api_key_param, and any http_receiver_api_key_params / http_sender_api_key_params from SSM Parameter Store with decryption.

  5. The change is applied. When only reload units changed, the running runtime is reloaded in place and only those units reconnect. Otherwise the appropriate swap mode (overlap or prepare/commit) is selected and the runtime is replaced.

  6. If validation or build fails: The change is rejected, the last good runtime continues running, and a warning is logged:

    bootstrap: config reload rejected; keeping last good runtime  error="..."
    

The Version Field

The version field in BridgeConfig is an integer counter incremented on each config commit via the admin API. When multiple instances share the same config file on EFS, this field provides optimistic concurrency control:

version: 7
bridge:
  id: my-bridge
  deployment_mode: clustered
# ...

A config-transaction commit includes the current version value. The write succeeds only if the on-disk version matches. If another instance updated the file first, the commit fails with a conflict (409), and you should re-read and retry. A version of 0 (or absent) means the config has never been committed through the API.