Scaling and availability
Two design choices make Vesicle scale with the size of your organisation instead of with the size of one server.
Every Vesicle service runs with many replicas
Section titled “Every Vesicle service runs with many replicas”The four first-party services (gateway, engine, worker and auth) are built to run as any number of replicas, from the first release. Multi-replica operation is a correctness requirement, not an add-on:
- No service keeps shared state in its own memory. State that more than one replica can touch lives in PostgreSQL or NATS and is coordinated there (queue groups, unique constraints, leases, compare-and-set updates).
- A replica can be added, removed or restarted at any time: during a rolling upgrade, a node drain or a load peak. Each service has a PodDisruptionBudget, and the default is two replicas.
- Each service scales on its own. Add gateways for HTTP load, engines for client and federation traffic, workers for outbound federation and background queues, and auth for token checks.
gateway: { replicaCount: 4 }engine: { replicaCount: 6 }worker: { replicaCount: 3 }auth: { replicaCount: 2 }You can scale a service with kubectl scale or with a HorizontalPodAutoscaler, since the replicas are stateless.
What still sets the limit
Section titled “What still sets the limit”Replicas remove the limit that one process puts on a homeserver. The capacity of the whole installation is then set by the shared parts:
| Part | How it scales |
|---|---|
| PostgreSQL | One primary for writes, plus read replicas (below). Give it enough CPU, memory and fast storage |
| NATS | The chart runs a single JetStream server by default. Size its storage and memory for your queues and media |
| Network and federation | The traffic you exchange with other servers |
Measure before you scale: the monitoring guide shows what to watch.
PostgreSQL read replicas take read load off the primary
Section titled “PostgreSQL read replicas take read load off the primary”With the default CloudNativePG database, set more than one instance:
database: cnpg: instances: 3 # one primary and two replicasThe operator then provides three Services:
| Service | Goes to |
|---|---|
<cluster>-rw | the primary (reads and writes) |
<cluster>-ro | the replicas only |
<cluster>-r | any instance |
The chart passes the read-only address to the engine as soon as there are replicas, and the engine keeps a separate connection pool for it. SQL that can tolerate a little replication lag is read from a replica, which leaves the primary free for writes. Failover is handled by the operator: if the primary fails, a replica is promoted.
Reads that must see the latest write never go to a replica. The rule is fixed in the design: a read stays on the primary when it is part of a write, takes a row lock, claims work, allocates a stream position, or depends on read-after-write consistency. A replica can lag behind the primary, so using it for those would produce wrong answers.
Replicas also give you a second copy of the data for availability. They do not replace backups.
Putting it together
Section titled “Putting it together”For a larger installation:
- Run several replicas of each service and let them spread over nodes (
topologySpreadConstraintsoraffinity). - Run PostgreSQL with
instances: 3or more, on fast storage, with a memory limit that fits your data. - Watch database and NATS load in monitoring and scale the part that saturates first.