A SaaS team sees its database grow and starts discussing sharding. The useful next question is what needs to spread across machines: storage, write activity, analytical work, or a group of large customers. A distributed system earns its operating cost when its data placement matches an observed workload.

Citus is a PostgreSQL extension for distributing data and queries across nodes. It can suit workloads with useful distribution boundaries, but it also makes data placement part of application design. Evaluate it with representative tenant workflows, cross-tenant queries, and a tested operating plan before treating additional workers as the next scaling step.

The key ideas

  • Establish a measured reason to distribute the database.
  • Choose data boundaries that keep important transactions and joins local.
  • Validate constraints, workload skew, and cluster recovery before migration.

Identify the constraint that a cluster should solve

Start with query plans, growth measurements, lock behavior, and resource use on the current system. Separate inefficient access patterns from genuine capacity limits. A tenant list that repeatedly scans unnecessary rows deserves investigation before introducing network boundaries. Record which business operation is constrained and why targeted improvements or a different single-node capacity would not meet the requirement.

Set explicit success criteria for a prototype: acceptable request latency, storage growth, import throughput, and the engineering effort needed for daily operation. Compare the cluster against a credible simpler alternative. Include the people who will run migrations, respond to incidents, and restore data; distributing ownership poorly can be as limiting as distributing rows poorly.

Understand the coordinator, workers, and sharding model

In the coordinator-and-worker model, the coordinator uses metadata about data placement to route or distribute work and combine results. Citus documents both row-based sharding, where a distribution column groups rows into shards, and schema-based sharding, where distributed schemas provide a different tenancy boundary. Confirm which model and features the selected Citus and PostgreSQL versions support.

This guide focuses on a shared-schema application considering row-based distribution. Write down where an application's queries enter the cluster, how data placement is managed, and which components must remain available. Installation support, extension compatibility, upgrades, and deployment options need validation in the actual environment; a PostgreSQL-compatible query interface does not make a cluster operationally identical to one server.

Reference: Citus: nodes, sharding models, and table concepts

Choose a distribution key around real transactions

For a tenant-scoped workload, tenant_id can be a candidate distribution key. Related orders, order lines, and customers can be colocated so queries joining on the appropriate distribution relationships can execute together. Small shared lookup data may fit reference tables, which Citus replicates across workers. Model shared and distributed data deliberately rather than marking every table the same way.

Test a representative checkout or booking operation and include the distribution key in the relevant filters and relationships. Then test the largest tenant, because tenant-based distribution does not automatically divide one tenant's traffic evenly across workers. Averages can hide a hot customer. Decide how you would identify and address skew before growth makes the chosen boundary expensive to change.

Reference: Citus: nodes, sharding models, and table concepts; Citus: distributed tables, constraints, and colocation

Review constraints and cross-tenant queries explicitly

Distributed uniqueness and referential integrity have placement requirements. For row-based distributed tables, primary keys and unique constraints generally need to include the distribution column; foreign-key support depends on the table types, distribution, and colocation. Review the current Citus DDL documentation and test every important business invariant in the proposed schema.

List the queries that span tenants: billing summaries, support searches, exports, and global analytics. Inspect their distributed plans and test network and aggregation costs under concurrency. Colocated joins and queries that require data movement have different execution characteristics. A fast tenant-scoped operation does not establish that the monthly cross-tenant report will also meet its target.

Workload questions before a Citus prototype
WorkloadDesign questionEvidence to collect
Tenant requestsCan related rows and joins stay colocated?Query plans and transaction latency
Large customer importsDoes the distribution create a hot tenant or shard?Per-worker load and skew
Global reportingHow much work and data cross worker boundaries?Distributed plans and concurrent report duration
Business identifiersWhere is uniqueness enforced?Constraint and concurrent-write checks

Reference: Citus: distributed tables, constraints, and colocation; Citus: querying distributed tables

Rehearse migration and cluster operation

Create a migration inventory covering schema changes, identifiers, tenant-aware queries, background jobs, reporting, and deployment tools. Rehearse data movement and validation with a realistic dataset. If new writes continue during a migration, define how they are captured, reconciled, and cut over. Name the point after which returning to the previous system requires more than redirecting connections.

Plan monitoring for the coordinator and workers, placement metadata, storage pressure, and uneven load. Define backups and restore procedures covering a consistent cluster state using supported tooling. Practice failure recovery, maintenance, and capacity changes in the chosen environment. Distribution, high availability, and recoverability are separate design concerns that all need concrete operating procedures.

Approve a scaling decision with workload evidence

Compare prototype results with the original single-node baseline and the success criteria. Include regressions as well as wins: migration complexity, slower global queries, operational burden, or a key that does not suit the largest tenant. Keep configuration and workload assumptions with the results so the decision remains useful after traffic changes.

Choose Citus when the distribution model and measured benefits justify those responsibilities. Keep improving a simpler PostgreSQL deployment when it still meets the business need. Either outcome is useful if the team can explain where its data belongs, how important operations behave, and how it will restore service when part of the system fails.

Sources & further reading

The guidance above combines our engineering recommendations with the official references below. Service features and platform requirements can change; check the current documentation when implementing.