[GH-ISSUE #5489] RFC: multi-node support (one panel managing worker nodes) — would you accept it upstream? #3835

Closed
opened 2026-10-31 20:35:18 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @n0ctal on GitHub (Jun 22, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5489

Summary

3x-ui manages one server per panel. Operators running several servers currently run several
independent panels and duplicate every inbound/client change by hand. I'd like to ask whether you'd
be interested in a multi-node feature upstream — one "master" panel that owns the inbound/client
definitions and synchronizes them to "worker" nodes — and, if so, what shape you'd want before I send code.

What I've built (in a fork) and would adapt to your direction

  • A master panel owns inbound + client definitions and pushes them to worker nodes over the existing
    panel API; workers keep serving with no extra moving parts.
  • Durable-first sync: the DB commit happens first, then the remote apply, driven by a monotonic
    per-node generation/fence — so a DB failure never leaves a node diverged, and a stale update can't
    overwrite a newer one.
  • Incremental/full-snapshot reconcile (no full restart per change), per-node serialized apply,
    idempotent + retry-safe delivery, convergence after a node reconnects.
  • Per-node authentication with a least-privilege token scope for the sync calls (not a shared admin key).
  • Online-client and traffic aggregation across nodes.

It's been running a real fleet for months.

The ask

This is a feature, not a small patch — it touches schema, a runtime/transport layer, API, and UI, so
I don't want to drop a large PR cold. Before writing anything upstream:

  1. Is multi-node something you'd want in 3x-ui at all?
  2. If yes, any architectural constraints/preferences (ownership model, sync semantics, auth, schema)?
  3. Would you accept it as a staged series of reviewable PRs (schema → runtime → API → UI) rather than
    one big change?

Happy to write a short design doc first and adapt to whatever you prefer. Thanks for 3x-ui.

Originally created by @n0ctal on GitHub (Jun 22, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5489 ### Summary 3x-ui manages one server per panel. Operators running several servers currently run several independent panels and duplicate every inbound/client change by hand. I'd like to ask whether you'd be interested in a **multi-node** feature upstream — one "master" panel that owns the inbound/client definitions and synchronizes them to "worker" nodes — and, if so, what shape you'd want before I send code. ### What I've built (in a fork) and would adapt to your direction - A master panel owns inbound + client definitions and pushes them to worker nodes over the existing panel API; workers keep serving with no extra moving parts. - **Durable-first sync:** the DB commit happens first, then the remote apply, driven by a monotonic per-node generation/fence — so a DB failure never leaves a node diverged, and a stale update can't overwrite a newer one. - Incremental/full-snapshot reconcile (no full restart per change), per-node serialized apply, idempotent + retry-safe delivery, convergence after a node reconnects. - Per-node authentication with a least-privilege token scope for the sync calls (not a shared admin key). - Online-client and traffic aggregation across nodes. It's been running a real fleet for months. ### The ask This is a **feature**, not a small patch — it touches schema, a runtime/transport layer, API, and UI, so I don't want to drop a large PR cold. Before writing anything upstream: 1. Is multi-node something you'd want in 3x-ui at all? 2. If yes, any architectural constraints/preferences (ownership model, sync semantics, auth, schema)? 3. Would you accept it as a **staged series of reviewable PRs** (schema → runtime → API → UI) rather than one big change? Happy to write a short design doc first and adapt to whatever you prefer. Thanks for 3x-ui.
bsakaguchi 2026-10-31 20:35:18 +07:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jun 22, 2026):

Multi-node management is already a first-class, shipping feature in 3x-ui — it has been present since well before the current v3.3.1 release. Your RFC describes capabilities that are substantially already implemented upstream.

What already exists in the codebase

  • internal/database/model/model.go — Node struct with per-node ApiToken, selectable TlsVerifyMode (verify / skip / pin / mtls), InboundSyncMode (all / selected), and InboundTags for scoped sync.
  • internal/web/service/node.go / inbound_node.go — NodeService and inbound-push logic including incremental client operations, a bulk-push threshold that falls back to full-snapshot reconcile (nodeBulkPushThreshold = 32), per-node serialized apply, and idempotent/retry-safe delivery.
  • internal/web/service/node_tree.go, node_dirty_test.go, inbound_node_reconcile_test.go, node_bulk_dispatch_test.go, etc. — dirty-tracking, reconcile, and bulk dispatch paths with test coverage.
  • internal/web/job/node_heartbeat_job.go — periodic heartbeat polling (concurrency-capped, timeout-bounded) to update node status, Xray version, CPU/mem/net metrics, and online clients.
  • internal/web/job/node_traffic_sync_job.go — traffic aggregation and IP-limit sync across nodes, with a globalPush interval and a structural-change flag that gates full reconcile.
  • mTLS node authentication via internal/web/service/node_mtls.go.

What this means for your RFC

The questions you posed (Is multi-node wanted? What shape?) are already answered by the shipped code. Before writing anything upstream, the productive next step is to diff your fork's approach against the existing implementation and identify:

  1. Specific behaviors your fork has that are absent or different in upstream (e.g., your monotonic generation/fence for durable-first sync — check whether the existing dirty-flag + reconcile path covers the same invariant).
  2. Any gaps your production experience revealed that are not yet addressed by the open bug/feature issues (search the tracker for "node" to find the active backlog).
  3. Concrete, targeted PRs for genuine additions, using the same staged approach you described.

Opening a design-doc issue or a discussion thread comparing your implementation with the existing one would be a natural first step before code.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4769456835 --> @github-actions[bot] commented on GitHub (Jun 22, 2026): Multi-node management is already a first-class, shipping feature in 3x-ui — it has been present since well before the current v3.3.1 release. Your RFC describes capabilities that are substantially already implemented upstream. **What already exists in the codebase** - `internal/database/model/model.go` — `Node` struct with per-node `ApiToken`, selectable `TlsVerifyMode` (`verify` / `skip` / `pin` / `mtls`), `InboundSyncMode` (`all` / `selected`), and `InboundTags` for scoped sync. - `internal/web/service/node.go` / `inbound_node.go` — `NodeService` and inbound-push logic including incremental client operations, a bulk-push threshold that falls back to full-snapshot reconcile (`nodeBulkPushThreshold = 32`), per-node serialized apply, and idempotent/retry-safe delivery. - `internal/web/service/node_tree.go`, `node_dirty_test.go`, `inbound_node_reconcile_test.go`, `node_bulk_dispatch_test.go`, etc. — dirty-tracking, reconcile, and bulk dispatch paths with test coverage. - `internal/web/job/node_heartbeat_job.go` — periodic heartbeat polling (concurrency-capped, timeout-bounded) to update node status, Xray version, CPU/mem/net metrics, and online clients. - `internal/web/job/node_traffic_sync_job.go` — traffic aggregation and IP-limit sync across nodes, with a `globalPush` interval and a structural-change flag that gates full reconcile. - mTLS node authentication via `internal/web/service/node_mtls.go`. **What this means for your RFC** The questions you posed (Is multi-node wanted? What shape?) are already answered by the shipped code. Before writing anything upstream, the productive next step is to diff your fork's approach against the existing implementation and identify: 1. Specific behaviors your fork has that are absent or different in upstream (e.g., your monotonic generation/fence for durable-first sync — check whether the existing dirty-flag + reconcile path covers the same invariant). 2. Any gaps your production experience revealed that are not yet addressed by the open bug/feature issues (search the tracker for "node" to find the active backlog). 3. Concrete, targeted PRs for genuine additions, using the same staged approach you described. Opening a design-doc issue or a discussion thread comparing your implementation with the existing one would be a natural first step before code. *This reply was generated automatically; a maintainer may follow up.*
Author
Owner

@n0ctal commented on GitHub (Jun 22, 2026):

Thanks — you're right, and I should have checked first: 3x-ui already ships multi-node (the Node model, heartbeat/traffic-sync jobs, inbound push with the dirty-flag + reconcile path, mTLS auth). My RFC was wrong-premised; apologies for the noise.

What my fork actually does is harden the existing multi-node, not add it. Diffing against main, the genuine differences (confirmed absent upstream) are three focused things, each offerable as a staged PR:

  1. Monotonic per-node generation fence for durable-first sync. The fork adds desired_generation / applied_generation columns plus an in-transaction bump, used alongside the existing reconcile. To your specific question — does the ConfigDirty flag already cover the same invariant? — a boolean "needs resync" doesn't by itself give: (a) DB-commit-before-remote-apply, (b) stale-update fencing (a late/slow apply cannot ACK over a newer desired state), or (c) failed-apply visibility (desired > applied survives a partial failure so the next reconcile heals it). The generation counter makes those explicit and idempotent. I'd write this up as a design note before any code.
  2. Least-privilege node token scope. Instead of a full admin bearer per worker, a node-sync scope that authorizes only the exact master→worker sync routes (method+route allowlist, fail-closed), with panel-update authority kept on a separate credential — so a leaked worker token can't drive a remote panel update.
  3. Transactional port reservations. A conflict-safe (node, listen, port, transport) reservation acquired in the mutation transaction, instead of a check-then-insert that can race two overlapping listeners onto one port.

If any of these are interesting I'll open a design-doc issue per item and then staged PRs. If not, no problem — I wanted to ask before sending code rather than drop a large diff. Thanks for 3x-ui.

<!-- gh-comment-id:4769886017 --> @n0ctal commented on GitHub (Jun 22, 2026): Thanks — you're right, and I should have checked first: 3x-ui already ships multi-node (the `Node` model, heartbeat/traffic-sync jobs, inbound push with the dirty-flag + reconcile path, mTLS auth). My RFC was wrong-premised; apologies for the noise. What my fork actually does is **harden the existing multi-node**, not add it. Diffing against `main`, the genuine differences (confirmed absent upstream) are three focused things, each offerable as a staged PR: 1. **Monotonic per-node generation fence for durable-first sync.** The fork adds `desired_generation` / `applied_generation` columns plus an in-transaction bump, used alongside the existing reconcile. To your specific question — does the `ConfigDirty` flag already cover the same invariant? — a boolean "needs resync" doesn't by itself give: (a) DB-commit-*before*-remote-apply, (b) stale-update fencing (a late/slow apply cannot ACK over a newer desired state), or (c) failed-apply visibility (`desired > applied` survives a partial failure so the next reconcile heals it). The generation counter makes those explicit and idempotent. I'd write this up as a design note before any code. 2. **Least-privilege node token scope.** Instead of a full admin bearer per worker, a `node-sync` scope that authorizes only the exact master→worker sync routes (method+route allowlist, fail-closed), with panel-update authority kept on a separate credential — so a leaked worker token can't drive a remote panel update. 3. **Transactional port reservations.** A conflict-safe `(node, listen, port, transport)` reservation acquired in the mutation transaction, instead of a check-then-insert that can race two overlapping listeners onto one port. If any of these are interesting I'll open a design-doc issue per item and then staged PRs. If not, no problem — I wanted to ask before sending code rather than drop a large diff. Thanks for 3x-ui.
Author
Owner

@MHSanaei commented on GitHub (Jul 3, 2026):

Thanks for the thoughtful RFC and especially for the gracious follow-up after checking the tree — multi-node (a master panel managing worker nodes over mTLS, with heartbeat, config reconcile, and cross-node traffic/online aggregation) has been shipping in 3x-ui for a while, so the original question is resolved and I'm closing this issue.

The three hardening items you identified (generation fencing for durable-first sync, least-privilege node token scope, transactional port reservations) do look like genuine gaps worth discussing. Please open a separate, focused issue for each one you want to pursue so they can be evaluated and staged independently — a short design note followed by a small PR is exactly the right shape.

<!-- gh-comment-id:4873741553 --> @MHSanaei commented on GitHub (Jul 3, 2026): Thanks for the thoughtful RFC and especially for the gracious follow-up after checking the tree — multi-node (a master panel managing worker nodes over mTLS, with heartbeat, config reconcile, and cross-node traffic/online aggregation) has been shipping in 3x-ui for a while, so the original question is resolved and I'm closing this issue. The three hardening items you identified (generation fencing for durable-first sync, least-privilege node token scope, transactional port reservations) do look like genuine gaps worth discussing. Please open a separate, focused issue for each one you want to pursue so they can be evaluated and staged independently — a short design note followed by a small PR is exactly the right shape.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#3835
No description provided.