Scaling

sxs runs unchanged from a laptop to a large cluster. Scaling it is a matter of three independent levers:

  1. the query fleet — add stateless sxs replicas behind a load balancer;
  2. workload isolation — split ingestion and extraction onto dedicated processes (lxs, wxs) using capacities;
  3. the data stores — scale ClickHouse and MongoDB.

Principle

A deployment runs several instances of the same image. What each instance is allowed to do is set by its capacities (MODES). Because work between them travels through durable queues — MongoDB for ingestions, exports and remote worker jobs; AMQP for events and RPC — and claims are leased, replicas can be added or removed at any time without losing or duplicating work.

  • the query fleet is stateless: scale it by replica count;
  • ingestion and extractions are asynchronous and queued: scale them independently;
  • all processes still share the same MongoDB and ClickHouse.

See sxs, lxs and wxs for the capacity model and Execution modes and resource profiles for how a request is classified.

Reference topologies

DeploymentProcessesWhen to use
All-in-oneone process, all capacitiesdevelopment, small installations
sxs + lxsquery fleet + ingestion/RPCkeep heavy loads off the query path
sxs + lxs + wxs+ a worker/export fleetlarge query volume, big/history queries

Scaling the query fleet (sxs)

An sxs instance handles HTTP requests on a single main thread (the Node.js event loop), so one instance uses roughly one core for request handling, with a small memory footprint. The most effective way to add bandwidth is to run more replicas behind a load balancer (the Proxy sits in front of the fleet).

To protect the event loop from large or history queries, offload them to a worker:

  • requests above WORKER_OBS_COUNT_LIMIT (and all includeHistory / updatedAfter requests) run in a worker;
  • if the process has the workers capacity, the worker runs in a local pool;
  • if it does not (a pure sdmx process), the job is sent to the remote wxs queue and executed by wxs.

So a common pattern is: many thin sxs replicas (MODES=sdmx) for latency, and a separate wxs fleet for the heavy work. See Bulk resource profile and worker jobs for thresholds and classification.

Scaling ingestion (lxs)

Ingestion is asynchronous and durable:

  • requests are stored in a MongoDB queue (the ingestions collection) and claimed with a lease;
  • AMQP uses a shared queue, so replicas are competing consumers — a message is processed by one replica only;
  • each replica processes INGESTION_PER_INSTANCE ingestions concurrently (default 1), so total concurrency is replicas × INGESTION_PER_INSTANCE.

Adding lxs replicas is safe at any time: a restart reclaims only ingestions whose lease has expired. See Ingestion queue.

Scaling extractions (wxs)

wxs hosts the workers and exports capacities:

  • workers — a local pool of node:worker_threads executes worker jobs. Each worker is recycled after WORKER_POOL_MAX_JOBS jobs and bounded by WORKER_POOL_MEMORY_MB; the pool queue is per process (WORKER_POOL_QUEUE_SIZE, WORKER_POOL_MAX_PER_SPACE). A full queue returns 429 with Retry-After. Scale by adding wxs replicas.
  • exports — the export queue is durable in MongoDB and its concurrency counters are shared across all replicas (backed by MongoDB), so limits such as EXPORT_MAX_PER_SPACE and EXPORT_MAX_PER_MEMBER hold fleet-wide. The same 429 / Retry-After admission applies.

See Bulk resource profile and worker jobs and Asynchronous exports.

Scaling the data stores

When the observation volume grows, ClickHouse scales in two directions:

  • vertically — add cores to the nodes;
  • horizontally — shard the data and add replication.

sxs supports both: with a sharded cluster the normal resource profile queries the distributed table (query spread across shards), while the bulk profile queries the local table of a single shard and is throttled. This is how a large extract is prevented from saturating the cluster — see Execution modes and resource profiles.

For MongoDB, when the number of artefacts grows, use replica sets: sxs reads with a nearest read preference, so read requests are spread across the nodes.

Sizing signals

Both fleets expose their state on the health endpoints:

  • worker fleet — /healthcheck reports workers (busy, queued, rejected) and per-worker heap usage;
  • ingestion fleet — ingestions stats (pending, processing, oldestPendingAgeMs).

Rules of thumb:

SignalAction
pending ingestions rising, processing flatscale lxs, or raise INGESTION_PER_INSTANCE
worker rejected rising (429)scale wxs, or raise WORKER_POOL_QUEUE_SIZE
high query latency, low CPUadd sxs replicas
ClickHouse saturation during extractsscale the cluster, or lower BULK_OBS_COUNT_LIMIT usage

See also