On this page
Level: deployment view. Read this if you are an SRE or platform engineer and need to know what runs where today, which parts are stateful, and what must change before a second node can join.
Up/Down: up: L2 Containers. Technology choices and versions: Technology and deployment. Edge behaviour: Edge and loading performance.
In short#
Today MSO Cloud runs as one Docker Compose project on one host behind Cloudflare and Traefik. Web and the workers are stateless and can be replaced; Postgres, Redis and the object store are single instances and hold all durable state. Web is ready to scale horizontally except for one local upload volume; the worker is ready once the rollup lock (now in the tree) ships; the data tier and the edge are not.
Today: one host#
| Service | State | Notes |
|---|---|---|
| Traefik | Stateless; certificate store outside the repo | A separate compose project, shared with other stacks on the host, with its autoheal and Docker socket proxy. Its configuration is not in this repository except the response middleware (infra/) |
| web | Stateless; read-only root filesystem | One replica; a deploy scales to two, waits for the health check, drains the old one, returns to one |
| worker | Stateless | One process runs every pool and registers the schedulers |
| archive-worker | Scratch volume | Same image as the worker, own database identity, pool archive |
| watchdog | Stateless | Polls web and worker by service name |
| idp, cube | Stateless | Started with deploy flags; cube uses an in-memory cache |
| pdf-browser | Stateless | Headless Chromium, reached over a WebSocket endpoint |
| Postgres 19 | Stateful | Single primary, 2 GB shared buffers, max_ left at the default 100 |
| Redis 8.12 | Stateful | Single instance, append-only file, 512 MB, no eviction; holds queues, rate limits, events and cache invalidation |
| Object store (RustFS 1.0.7) | Stateful | Single node, S3 API |
Three networks separate duties: internal carries the data tier and has no route to the internet; balancer carries inbound HTTP from Traefik; egress is an outbound-only bridge for web and worker to reach vendor APIs, model providers and email.
Shared volume. Organization archive uploads land in a named volume shared by web and the archive-worker, because the upload route writes there and the worker reads it. This is the one piece of web state.
Connection budget. Against 100 connections: web 25 plus 5 for the sign-in pool, so 30 per replica and 60 during a rollout; worker 20; archive-worker 20 (all configurable per service). Adding a web replica spends 30 more.
Deploy. One script builds every image on the host, runs the one-shot migrate job (schema, runtime roles and policies) before web is swapped, rolls web, restarts workers, then fills the CDN cache with the new hashed assets and verifies the cache headers. Migrations are additive so old and new code run together during the roll.
Backups. Postgres is dumped nightly and the object volume is copied with it; Redis holds queue state only. A restore drill (scripts/ops/verify-restore.sh) restores the newest dump into a throwaway container and prints PASS or FAIL. There is no continuous WAL archive.
Target: multiple nodes#
This is the proposal, not what runs. App nodes run web only. Worker nodes split pools: sync, ai and alerts scale with queue depth, materialize plus scheduled stay in one process, archive runs once. All nodes reach a replicated Postgres through a connection pooler, a replicated Redis and an S3 object store over a private network. Images are built once and pulled from a registry; secrets come from one source. Phases and triggers: Scaling and clustering (internal).
Scale-out readiness#
| Item | Verdict | Evidence |
|---|---|---|
| Web statelessness | Ready, one exception | Read-only root filesystem and tmpfs in docker-; two replicas already run together during a rollout |
| Sessions, stickiness | Ready | JWT sessions (apps/); no sticky routing; every node needs the same session and encryption secrets |
| Rate limiting | Ready | Redis-backed rateLimitOrgMutation (apps/) |
| In-process web caches | Partially | Per-process maps with a short TTL (apps/); a Redis broadcast bumps other processes, so nodes are eventually consistent |
| Archive uploads | Not ready | Local volume (ORG_, apps/) |
| Object store | Partially | Endpoint is configuration (S3_); the in-cluster store is one node |
| Scheduler duplicates | Ready | Stable-id upsert (apps/) |
| Second worker process | Ready once the rollup lock is released | Rollup rebuilds take a transaction-scoped advisory lock (packages/), replacing the in-process mutex in packages/ |
| Migrations | Ready (one runner) | One-shot job before the web swap; packages/ retries deadlocks but does not serialize concurrent runners |
| Zero-downtime deploy | Ready on one host | Rolling script; no cross-node orchestration |
| Redis | Not ready | Single instance; an outage stops jobs and cache invalidation |
| Postgres replicas, pooling | Not ready | Single primary, no pooler; transaction-mode pooling with row-level security is plausible (the pin is set per transaction in packages/) but unverified |
| Secrets distribution | Not ready | One environment file on one host |
| Service discovery | Partially | Stable alias for web; data tier addressed by container name, which resolves on one host only |
| Observability | Partially | / on web and / on worker; the watchdog watches one web and one worker target; no metrics server or log shipping in the repository |
| Edge | Not ready | One Traefik terminates TLS for every host; certificate state is not shared |
| Backup | Partially | Nightly dump plus restore drill; no WAL, so recovery point is the last dump |
| Cube | Partially | In-memory cache; a second instance needs a Redis cache driver |
Adding a second web node#
- Make the data tier reachable on a private interface with TLS; parameterize the Postgres, Redis and object-store host parts that compose currently bakes in as service names.
- Move archive uploads to the object store (stream in the upload route, fetch in the archive-worker). Until then, route the upload paths to node 1 only.
- Raise
max_connectionsor add a pooler (budget 30 per web replica plus 40 for workers) and lower the per-node pool size if needed. - Put identical session, encryption, RLS-context, metrics and internal tokens on node 2 from one source, and check a hash of the environment before start.
- Pull the same web image from a registry instead of building on node 2.
- Add node 2 to the load balancer with the existing health path; review the trusted-proxy hop count, because the proxy chain changes.
- Run
migratefrom node 1 only; roll node 2 after node 1 is healthy. - Add node 2's metrics endpoint as a second watchdog target.
Adding a second worker#
- Confirm the rollup lock release is deployed and that
verify:datais green against it. - Split pools with the overlay or per-node settings so exactly one process owns
materializeandscheduled. The pools overlay in the repository definesai,alertsandmaterialize,scheduledservices but nosyncservice, and the watchdog still polls the single all-in-one worker; complete both before using it. - Give each node the worker secrets and its own database pool budget; add its metrics port to the watchdog targets.
- Start the new pool, then drain the old all-in-one process: it stops taking new jobs and finishes running ones.
Quality goals, SLOs and risks#
Only numbers that exist in the repository are stated here.
| Goal | Value | Source |
|---|---|---|
| Recovery point (RPO) | Target 15 minutes; today up to about 24 hours (nightly dump) | disaster-recovery runbook (internal) |
| Recovery time (RTO) | Target 1 hour; a 1.2 GB dump restored in 5 min 34 s in the drill | same runbook |
| Page speed, p75 | LCP 2.5 s, INP 200 ms, CLS 0.1, TTFB 0.8 s; budgets documented, not measured in CI | Limits and budgets |
| Availability, queue latency, error budget | Not defined | none |
| Alarms | Rules for Redis memory, evictions and down, database pool waiting and utilisation, API error rate, web down and worker down | apps/ |
| Backup retention | Not reconciled between the repository and the host | Limits and budgets |
| Risk | Effect | Mitigation today |
|---|---|---|
| Single host | Host loss is total outage | Backups; restore drill |
| Single Postgres | Outage stops everything; no replica | Nightly dump; no failover |
| Single Redis | Jobs and cache invalidation stop | Append-only file; memory alarm |
| Edge outside the repository | Routing changes are not reviewed with the code | Compose verification covers the application stack only |
| Pooler with row-level security | A pinned scope could be lost if pooled across transactions | Not verified; test before adoption |
Where it stops#
One self-hosted deployment is in use; the multi-node view is a proposal. Readiness per capability: Project status.