Clustering & multi-database
|
This section documents the current Neo4j This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production, as Neo4j iterates quickly. This section’s bibliography lists the reference material consulted while preparing these pages. |
A Neo4j cluster replicates a database with the Raft consensus protocol among a small set of writable servers and fans out read traffic to a larger, independently scalable tier behind them. On top of that cluster, one DBMS can host many logical databases, optionally federated under a single composite database.
Raft-based clustering: server roles and leader election
Terminology change: the server roles are now called primary and secondary — these replace the
legacy CORE and READ_REPLICA naming used by older Neo4j versions. A primary holds a full copy of
a database and takes part in Raft voting for it; a secondary holds a copy kept in step by asynchronous
catch-up but does not vote.
For each database, the primaries hosting it form one Raft group:
-
One primary is elected leader for that database and is the only server that accepts writes to it; the rest are followers.
-
Every write is appended to the leader’s Raft log and must be acknowledged by a majority of the primaries in the group before it is committed — this is what keeps the database available and consistent through the loss of a minority of primaries.
-
If the leader stops heartbeating, the remaining primaries hold a Raft election and a new leader is chosen by majority vote. A client driver using
neo4j://routing discovers the new leader automatically on its next write. -
Secondaries replicate committed transactions from the primaries asynchronously. They scale read throughput and geographic read locality without adding Raft voting overhead, and a load balancer (or driver-side routing) can steer read traffic to them while writes go to the leader.
See Clustering for the full server-role and topology reference, and Clustering: Lifecycle for how a server joins, leaves, and is replaced within a running cluster.
Multi-database and composite databases
A single DBMS instance (or cluster) can host several independent databases, each with its own data, schema, and — in a cluster — its own Raft group of primaries. Databases are managed with Cypher administration commands rather than a separate tool:
// Create a new database (async by default -- add WAIT to block until it comes online)
CREATE DATABASE `orders` IF NOT EXISTS WAIT;
// List every database and its per-server role/status
SHOW DATABASES YIELD name, address, role, currentStatus;
// Inspect one database in detail
SHOW DATABASE `orders` YIELD name, currentStatus, requestedStatus;
// Take a database offline, then drop it
STOP DATABASE `orders`;
DROP DATABASE `orders` IF EXISTS;
Terminology change: the current term for federating multiple databases under one virtual, queryable namespace is a composite database — this is the same capability formerly marketed as Fabric. A composite database has no data of its own; it exposes a set of constituent databases (which can live on the same DBMS or be reached over the network) as named graphs that a single Cypher query can address together.
// Create a composite database, then attach constituents to it
CREATE COMPOSITE DATABASE `analytics`;
CREATE ALIAS `analytics`.`orders` FOR DATABASE `orders`;
CREATE ALIAS `analytics`.`inventory` FOR DATABASE `inventory`;
// Query across constituents from the composite database
USE `analytics`.`orders`
MATCH (o:Order) RETURN count(o);
Aura’s managed take. Neo4j Aura provisions and operates the primary/ secondary Raft topology above for you — a Professional or Business Critical instance is backed by a managed cluster with automatic leader failover, and Aura additionally handles patching, backup scheduling, and scaling the secondary tier without exposing the underlying server administration commands. Multi-database and composite databases are available on the tiers that support them, managed through the Aura console and the same Cypher administration commands shown above rather than through any cluster-lifecycle command, since Aura owns that layer — see the Aura documentation for which capabilities each tier includes.
Related pages
-
MongoDB Replica sets & high availability — a primary/secondary replica set with heartbeat-driven election, contrasted with Neo4j’s Raft-based leader election.
-
MongoDB Horizontal scaling with sharded clusters — partitioning one logical collection across many shards, as a contrast to Neo4j’s per-database Raft group and composite-database federation.
-
Couchbase Clusters, replication, failover & XDCR — vBucket-based intra-cluster replication and cross-datacenter XDCR as another distributed-topology model.