Citus for distributed PostgreSQL and sharding

Citus turns PostgreSQL into a distributed database across coordinator and worker nodes. This page explains the design decisions, effort drivers and fit checks you need before scaling past one server.

On this page

When one PostgreSQL server stops being enough and Citus is worth evaluating

Citus is a PostgreSQL extension that turns a PostgreSQL database into a distributed database, spreading tables across a coordinator node and worker nodes. It is the option to test when a self-hosted database has reached the limits of one server and the workload can be split along a natural key, most often the tenant ID in a multi-tenant SaaS product. The Citus documentation names three common use cases: multi-tenant SaaS, real-time analytics and microservices. The first two are where teams most often ask whether to shard, so they are where this evaluation usually starts.

Before committing, confirm that your queries and data model can work with distribution. Applications in multi-tenant SaaS often filter nearly every query by tenant, which fits well. Workloads with many cross-tenant joins, heavy foreign key use across tenants or a single large table that every query touches may need redesign first. The Citus documentation includes a section on when Citus is inappropriate, and that section should be read against your own query patterns. Ask your team to list the ten most expensive queries and state which key each one filters on. That list is the quickest way to see whether distribution helps or hurts.

Testing is worth the effort because the decision is hard to reverse once data is distributed. Build a copy of a representative tenant set in a non-production environment, run your real query mix and measure how the workload behaves when rows are placed across workers. Confirm the Citus version and its compatibility with your PostgreSQL major version against the Citus repository before you start, since extension and server versions must match. The source code is licensed AGPL-3.0, so confirm with counsel how that license applies to how you run and offer the software before the test becomes a production plan.

What Citus does inside a PostgreSQL cluster

Citus adds distribution on top of standard PostgreSQL rather than replacing it. The cards below cover the parts a team must design: which node receives queries, how tables are placed across workers, and which storage and sharding choices come with them. Confirm exact behavior against the release you plan to run.

Coordinator and worker nodes

A Citus cluster has a coordinator node that receives application connections and plans queries, and worker nodes that hold the shards of distributed tables. The coordinator keeps metadata about where shards live, so it is the component whose sizing, backups and failure handling you must plan first. Confirm in the current Citus docs how metadata is stored and what high availability options apply to the coordinator in your setup.

Citus overview

Distributed tables

A distributed table is split into shards by a distribution column, and each shard is stored on a worker. Choosing that column is the most consequential schema decision, because queries that filter on it can be routed to one shard while queries that do not must fan out across workers. Test your most common queries against candidate columns before you load production data.

Reference tables

A reference table keeps a full copy on every node so that joins with distributed tables do not need data from other workers. Reference tables suit small, mostly read-only lookup data such as codes or configuration. Writes to them are replicated to all nodes, so check write volume before you choose this table type for data that changes often.

Schema-based sharding for multi-tenant SaaS

Schema-based sharding places each tenant's schema on a node, which suits multi-tenant applications that want tenant isolation without designing a tenant ID into every table. It changes how you group tenants, move them between nodes and run per-tenant maintenance. Confirm which schema-based features your Citus version supports before committing an application design to them.

Columnar storage

Citus columnar storage compresses data and can speed up scans on regular and distributed tables, which suits append-heavy analytical data. It is a storage choice per table, so rows that are updated often may be a poor fit. Measure compression and scan speed on a copy of your own data, and confirm the write and update limits in the release you run.

Standard SQL on the coordinator

Applications connect to the coordinator with standard PostgreSQL drivers and SQL, and Citus plans distributed queries behind that interface. Not every PostgreSQL feature behaves the same across distributed tables, so review constraints, foreign keys, triggers and extensions that your application relies on. Confirm the supported SQL and feature list for your version in the docs before you port an application.

How coordinator and worker nodes split the work

In a Citus cluster, the coordinator is the node applications connect to. It is an ordinary PostgreSQL server with the Citus extension loaded, and it holds the metadata that records which shards live on which worker. When a query arrives, the coordinator plans it, decides which shards must be touched, sends the work to the workers in parallel and combines the partial results. The workers are PostgreSQL servers that store the shards and run the pieces of the query they are sent. Applications see one database, but the coordinator is the component that decides where each part of the work runs, so its sizing and availability matter to every query in the cluster. Confirm in the Citus docs for your version how the coordinator and workers are registered and how many workers a given cluster design needs.

Citus has two main table types, and they behave differently. A distributed table is split into shards by a value in one column, the distribution column, and each shard lives on a worker. Rows with the same distribution column value are stored together, which is what allows joins and lookups for one tenant or one customer to stay on a single node. A reference table is stored in full on every node, so joins against it are local everywhere, at the cost of extra writes and storage on each worker. Small lookup tables such as country codes or plan definitions are typical reference table candidates. Joins between distributed tables are efficient only when both tables use the same distribution column and are colocated. Check in the Citus docs which join and query shapes are supported for your version, because the planner's support for cross-shard operations has limits.

The distribution column is the most consequential decision in a Citus design. It determines which queries stay on one node, how data spreads across workers, how unique constraints and foreign keys can be enforced, and how hard it is to rebalance later. For a multi-tenant SaaS application it is usually the tenant identifier, but that choice only works if nearly every table can carry that column and most queries filter on it. An illustrative example: if orders are distributed by tenant ID and order lines are colocated with them, a single tenant's checkout queries run on one worker. If the distribution column is chosen later for convenience, the team may face a large data move. Before building, list the dominant queries and confirm each one can be expressed with the chosen column.

Which sharding model fits your workload

Row-based distribution, often called hash distribution, spreads the rows of a table across worker nodes by the value of a distribution column, such as a tenant ID or customer ID. It suits large tables where most queries filter or join on that column, because Citus can route each query to the node that holds the matching rows. It complicates queries that need data from many distribution keys at once, since those cross-shard joins cost more and must be designed around the distribution column. Foreign keys and unique constraints are also tied to the distribution column, so the key design needs to be settled before data is loaded.

  • Query routing: Queries that include the distribution column can run on a single worker.
  • Cross-shard joins: Joins that do not align on the distribution column move more data between nodes.
  • Constraints: Primary keys, unique constraints and foreign keys generally need to include the distribution column.
  • Schema changes: Adding a distributed table or changing its distribution column is a planned operation, not a routine ALTER.
  • Data skew: A poorly chosen column can concentrate rows on a few shards, so check value distribution before choosing it.

Before choosing, confirm in the Citus docs which constraints and SQL features apply to distributed tables and how your chosen column behaves under your largest queries.

What drives Citus effort and how to keep it down

The table lists the factors that most change how much work a Citus migration takes, the direction each one pushes effort, and the mitigation to apply. Read it before estimating scope, because the first three drivers usually decide whether the schema can be distributed with little rework.

DriverEffect on effortHow to keep it down
Existing schema and foreign key countEffort rises with the number of foreign keys and unique constraints that cross the chosen distribution columnMap the constraints before migration, co-locate related tables on the same tenant key, and move cross-table references into reference tables where the data is small
Choice of distribution columnA poor choice forces reshuffling of tables, rewrites of queries and reworked keys laterPick a tenant identifier present in nearly every table, test it against the top query patterns, and document the decision before loading data
Cross-tenant query patternsReports and admin queries that span all tenants need coordinator-side aggregation and can cost more to tuneList cross-tenant reports early, move them to a separate analytics path or accept slower execution, and test them on a realistic worker layout
Data volume and migration pathLarger datasets lengthen the initial distribution, backfill and cutover windowsMeasure table sizes, rehearse the load on a copy, and plan a cutover method that keeps writes safe while data moves
Number of worker nodesMore workers add placement, rebalancing, monitoring and capacity planning workStart with the node count the workload needs, define a rebalancing procedure, and confirm sizing with the Citus documentation before adding nodes
Backup and high availability designEach node and the coordinator need consistent backup and failover, which multiplies the recovery procedures to testDefine one restore runbook that covers all nodes, test restores across the cluster, and align with the PostgreSQL backup and failover designs in use
Application changes for tenant-scoped queriesQueries, connection handling and migrations must include the tenant key, which touches application code across servicesInventory data access code, add tenant filters in a shared data layer, and run integration tests against a distributed test cluster

How a Citus rollout moves from assessment to production

This sequence takes a PostgreSQL workload from a go or no-go fit check to a Citus cluster in production, with each step producing a document or test result that the next step depends on. Most of the risk sits in the distribution key and the query review, so those steps come before any data moves.

  1. Assess the workload and confirm fit

    Start by measuring what the current database does: table sizes, growth, the share of queries that filter on a tenant or entity key, joins across tables, and the write rate. Compare these against Citus's documented use cases and its section on when Citus is inappropriate, and be ready to conclude that a single well-tuned PostgreSQL server or a read replica is the better answer. The output is a short fit assessment that records the decision, the reasons and the open questions, and it should be signed off by the application owner before design work begins.

  2. Design the schema and distribution keys

    Decide which tables will be distributed across worker nodes, which will be reference tables copied to every node, and which will stay local on the coordinator. For multi-tenant SaaS, evaluate schema-based sharding against a tenant ID column, and check that the chosen key appears in primary keys, foreign keys and the most frequent WHERE and JOIN clauses. The output is a distribution design document listing each table, its type, its distribution column and the joins that must be colocated, reviewed by the engineers who own the data model.

  3. Build a test cluster with representative data

    Stand up a coordinator and worker nodes in a non-production environment that matches the planned topology, using the infrastructure you control. Load a representative slice of production data, including the largest tenants or tables, because skew in tenant size is one of the first things that breaks a sharding plan. The output is a running test cluster with recorded row counts per shard, a check that colocated tables land on the same nodes, and a note on how the cluster was built so the production build can repeat it.

  4. Review application queries for compatibility

    Run the application's full query set against the test cluster, including ORM-generated SQL, background jobs, reports and migrations. Flag queries that cross distribution boundaries, use functions or features that the distributed planner does not support, or rely on cross-shard transactions that the design did not anticipate. The output is a query compatibility list with each item marked as works, rewritten or redesigned, and the owner of each rewrite, which becomes the acceptance input for the application team.

  5. Migrate data into distributed tables

    Move data from the source database into the distributed and reference tables in the order that keeps colocated tables consistent, then validate row counts, checksums on critical tables and foreign key integrity against the source. Plan the migration window and a rollback path before the first load, and confirm how writes during the copy will be captured, since this decides whether the cutover is a short freeze or a longer sync. The output is a migration report that compares source and target counts per table and records any rows that were rejected and why.

  6. Test failover and backup restore

    Test what happens when a worker node or the coordinator fails, and confirm which component provides replication, failover and backups in your design, since PostgreSQL itself does not detect a failed primary. Then restore a backup into a separate environment and run the application's checks against the restored cluster to prove the procedure works. The output is a tested restore procedure with measured steps and the failover runbook, both reviewed by the operations team who will run the cluster after handover.

  7. Cut over to production and hand over

    Switch application traffic to the Citus cluster according to the cutover plan, watch query latency, error rates and shard balance during the first period, and keep the source database available for the agreed rollback window. Hand the cluster to the operations team with the distribution design document, query compatibility list, monitoring dashboards, backup schedule and runbooks, and confirm the ownership of each item. The handover is complete when the operations team has run a planned restore and a planned node maintenance step on production themselves.

How application traffic reaches coordinator and worker nodes

Application traffic starts at the application network and connects to the coordinator, which holds no shard data of its own and plans each query. The coordinator then routes work to worker nodes that hold the distributed shards, while reference tables are copied to every worker so joins stay local. Check that the application can reach only the coordinator, that workers accept connections only from the coordinator and each other, and that backups cover every node.

Application traffic enters through the coordinator and fans out to workers.

AGPL-3.0 licensing and when Citus is the wrong fit

The Citus repository is licensed under the AGPL-3.0, while PostgreSQL itself is released under the PostgreSQL License, a liberal license similar to the BSD or MIT licenses. That split matters before any build starts. The AGPL is a copyleft license, and its network provisions can apply when software is made available to users over a network, so the reader should have counsel review how those terms apply to their deployment, to any internal modifications and to any customer-facing service built on the cluster. Ask counsel to confirm which Citus version and build will be used, whether DeployOpen or the client will change Citus source code, and whether any distribution of binaries or images to third parties occurs. Do not assume that running Citus internally carries no obligations.

Citus is not the right answer for every scaling problem. The Citus documentation includes a section on when Citus is inappropriate, and that section should be read in full against the application's query shapes before the team commits to a design. Workloads that depend heavily on cross-shard joins and transactions, or that need a single-node data model without deliberate distribution keys, usually take more engineering work to run well on a distributed layout. Before choosing Citus, the team should evaluate a larger single server, which is often the simplest step, read replicas for read-heavy traffic, native declarative partitioning for time-based data that stays on one node, and, where the data model fits, a different database entirely. Each option has its own limits, so the decision should rest on measured bottlenecks rather than on the expectation of growth.

How Citus connects to the rest of your PostgreSQL platform

A Citus cluster is several PostgreSQL servers that must be pooled, replicated, backed up, monitored, secured and upgraded as one system. Each card below covers a platform component that has to be planned for the coordinator and every worker, not just a single database server.

Connection pooling with PgBouncer

Applications should reach the coordinator through a pooler so that many client connections do not each hold a backend process on the coordinator. Decide whether the pooler sits in front of the coordinator only or also in front of workers, since connections between nodes follow their own limits. Confirm how your PgBouncer pool mode interacts with the session state and prepared statements your application relies on, and test that path before cutover. Pin PgBouncer to a patched release.

PgBouncer site

High availability for coordinator and workers

The coordinator and each worker can fail independently, and losing any one of them affects queries that touch its shards. Plan a standby for the coordinator and for every worker, with a failover method that your team has rehearsed. PostgreSQL streaming replication does not detect failure or promote a standby on its own, so an external tool must handle that step. Ask the implementer which replication mode each node uses and what the application sees during a switch.

PostgreSQL high availability docs

Backup and point-in-time recovery across nodes

A restore of one node does not restore a consistent distributed database. Backups must cover the coordinator and every worker, and recovery targets must be chosen so that all nodes return to a compatible point. Point-in-time recovery needs a base backup and archived WAL for each node, and incremental backups still require a combine step at restore time. Test a full cluster restore into a separate environment and record how long it takes.

Continuous archiving docs

Monitoring and observability

Monitor the coordinator and each worker separately, then add a view of distributed query behavior, since a slow query may be slow on one shard placement only. Track replication lag per standby, connection counts through the pooler, disk use per node and shard size skew. Alerts should identify which node is affected so on-call engineers do not have to query every node by hand. Agree on the metrics and log sources before go-live.

Authentication and TLS across nodes

Every node needs the same authentication rules for client connections and for connections between coordinator and workers. Decide which authentication method each network path uses, such as certificate or SCRAM password authentication, and manage the certificates and credentials for the whole cluster from one process. Confirm that the TLS settings apply to inter-node traffic, not only to application connections, and review pg_hba.conf entries on every node after each change.

Authentication methods docs

Upgrades that keep Citus in step

A major PostgreSQL upgrade must be applied to every node, and the Citus extension version must be compatible with the new PostgreSQL major on each one. Before upgrading, confirm Citus compatibility with the target PostgreSQL major in the Citus release notes and in a staging cluster built from the same versions. Plan the order of node upgrades, the window in which the cluster runs mixed versions, and the rollback path if a node does not come back.

Support per major
5 years
PostgreSQL versioning policy

Questions buyers ask before bringing in a Citus partner

What drives the cost of a Citus implementation?

The cost follows from the written scope, and the main drivers are the number of nodes, the number and shape of distributed tables, how much existing data must be moved, and how many applications must change their queries. Schema and tenant design usually takes the most senior time because distribution keys are difficult to change later. Costs split into one-time work (design, build, data migration, testing) and recurring work (node operations, upgrades, monitoring, on-call support). Ask any partner to quote these phases separately and to state which environments, such as staging and disaster recovery, are included. A quote should also name what the client team must provide, since missing access or unclear ownership is a common source of change requests.

How long does a Citus rollout take?

The timeline depends mostly on the number of tables that need a distribution decision, the size of the data to be moved, and whether the application already sends tenant identifiers in every query. Teams that must refactor queries or rework unique constraints usually spend more time in design and testing than in installation. Ask for a phased plan with explicit gates: a schema review, a load test against representative data, a cutover rehearsal and a rollback path. Confirm the current Citus release notes and your PostgreSQL major version compatibility with the vendor before fixing dates, because supported combinations change over time.

What does the work need from our own team?

Your team needs to supply people who understand the data model, the access patterns of the application, and the business rules for tenants and reporting. A typical engagement needs a database owner who can approve schema changes, an application lead who can change queries, an infrastructure owner for networking, storage and backups, and someone who can run an incident response. Plan for these people to be available during design and cutover, not only at kickoff. Agree in writing who holds the production credentials and who receives runbooks at handover.

Can our team run Citus without a partner?

Yes, a team with strong PostgreSQL operations experience can build and run Citus itself, provided it has time to learn the distribution model and test it thoroughly. The hardest parts are usually distribution key choice, cross-shard queries, schema changes across many nodes, and backup and restore across coordinator and workers. A partner is most useful when the team lacks recent distributed database experience or has a fixed deadline. Whichever path you take, the readiness question is whether you can prove restores and failovers work in your own environment, not whether the install succeeds.

How do we know Citus is the wrong fit for our workload?

Citus is a poor fit when the database fits on one well-sized server, when workloads need many cross-tenant joins or transactions that span most shards, or when the data model cannot choose a stable distribution key. Citus documents a section describing where it is inappropriate, and that is the right starting point for your review. Test the candidate design with realistic queries before committing. Alternatives include vertical scaling, read replicas, declarative partitioning, or a different database, and each should be costed against the same workload.

How do Citus upgrades and the AGPL license affect operations?

Citus must be kept compatible with the PostgreSQL major version you run, so each PostgreSQL upgrade adds a Citus compatibility check, and the coordinator and workers must be upgraded in a planned order. PostgreSQL itself supports each major version for 5 years after its initial release, so plan your upgrade cadence around that window. The Citus repository is licensed AGPL-3.0, which has obligations if you modify the software and make it available to users over a network. Have your legal and open-source review confirm how those terms apply to your internal changes and any hosted service you offer before you build on it.

What should we check during security and compliance review?

Review how coordinator and worker nodes authenticate each other, how client connections are encrypted, and how privileges are granted across nodes, since a mistake on one node can expose data that another node holds. Confirm the audit logging and backup encryption cover every node, not only the coordinator. Ask your auditor which evidence they expect, and note that DeployOpen prepares systems, controls and evidence for compliance assessments but does not issue audit reports or certifications.

Where to verify Citus features and license terms

Before you choose Citus, confirm its current features, supported PostgreSQL versions and license terms against the release you plan to run. The two primary sources are the Citus repository on GitHub and the What is Citus? section of the Citus documentation. The repository shows the source, release tags and the license file, which is licensed AGPL-3.0. The documentation describes the use cases Citus targets, including multi-tenant SaaS, real-time analytics and microservices, and it includes a section on when Citus is inappropriate. Read that section closely, because it is the vendor's own statement of where the extension fits poorly.

Details change between releases. Support for a given PostgreSQL major version, the availability of particular features such as columnar storage options or shard rebalancing, and the packaging for your operating system can all differ from one Citus version to the next. Record the exact Citus version and the PostgreSQL major version you intend to run, then confirm both against the documentation and release notes for that combination. Treat any compatibility statement you find in a blog post or forum thread as unverified until it matches the official docs.

Ask your legal or procurement team to read the AGPL-3.0 terms with your intended use in mind, especially if you plan to offer the database functionality to customers as a hosted service or to modify the extension. Ask DeployOpen or your own engineers to write the verified version, license and supported-PostgreSQL combination into the design document, so that the same check is repeated at every planned upgrade.

How DeployOpen works on this

DeployOpen plans, implements, hardens, documents and supports self-hosted open-source platforms inside your own cloud accounts, data centers or air-gapped networks. For Citus, that means deciding first whether a distributed layer is justified, then building the coordinator and worker topology, the table design and the operating procedures in your environment.

How we scope

  • Written scope states which workloads, tenants and tables move to distributed or reference tables.
  • The scope records the PostgreSQL major version, Citus version and AGPL-3.0 license review agreed with your legal team.
  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.

How we build

  • Build covers coordinator and worker nodes, shard placement, and the distribution column for each table.
  • Schema-based sharding and columnar storage choices are tested against your real query patterns before rollout.
  • Failover, backup and connection pooling are designed for the cluster, not left as separate tasks.

How we hand over

  • Handover includes architecture notes, runbooks for adding workers and rebalancing shards, and tested restore steps.
  • Verification records show that distributed queries, joins and tenant isolation behave as the design states.
  • Your team receives configuration in version control so changes to the cluster can be reviewed and audited.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers after handover.
  • Retainers can cover Citus and PostgreSQL version upgrades, which need to be planned together with the extension.
  • Ask for a quote that separates one-time build effort from recurring support, monitoring and testing.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.