Skip to content

ShardCoordinator

Defined in: src/cluster/sharding/ShardCoordinator.ts:130

Cluster-wide authoritative source of shard-to-region assignments. Runs on every node but only responds to requests when the local node is the cluster leader. Non-leader coordinators ignore incoming messages so that duplicate coordinators during a leader transition are harmless.

State is reconstructed from Register messages: each region reports the shards it currently hosts, and the coordinator merges that with any new allocation requests. This is deliberately lightweight — a production upgrade would snapshot state to a journal so the coordinator can recover across restarts without re-allocating every shard from scratch.

  • Actor<CoordinatorInbox>

new ShardCoordinator(settings): ShardCoordinator

Defined in: src/cluster/sharding/ShardCoordinator.ts:185

ShardCoordinatorSettings

ShardCoordinator

Actor.constructor

readonly settings: ShardCoordinatorSettings

Defined in: src/cluster/sharding/ShardCoordinator.ts:185

onReceive(msg): void

Defined in: src/cluster/sharding/ShardCoordinator.ts:263

Main message handler. Receives each envelope dequeued from the mailbox. A thrown error (sync or async) is caught by the supervisor.

CoordinatorInbox

void

Actor.onReceive


postRestart(_reason): void | Promise<void>

Defined in: src/Actor.ts:55

Called on the fresh instance after a restart. Default: call preStart().

Error

void | Promise<void>

Actor.postRestart


postStop(): Promise<void>

Defined in: src/cluster/sharding/ShardCoordinator.ts:251

Called after the actor has been terminated. Children are already stopped.

Promise<void>

Actor.postStop


preRestart(_reason, _message?): void | Promise<void>

Defined in: src/Actor.ts:50

Called before a restart, on the instance about to be thrown away. The default stops children and then calls postStop().

Error

CoordinatorInbox

void | Promise<void>

Actor.preRestart


preStart(): Promise<void>

Defined in: src/cluster/sharding/ShardCoordinator.ts:192

Called after construction and before the first message is processed.

Promise<void>

Actor.preStart


supervisorStrategy(): SupervisorStrategy

Defined in: src/Actor.ts:63

Supervisor strategy for this actor’s children. Defaults to restart, up to 10 times per minute, then stop.

SupervisorStrategy

Actor.supervisorStrategy


static pathFor(typeName): string

Defined in: src/cluster/sharding/ShardCoordinator.ts:188

Path used by ClusterSharding to locate the coordinator on any node.

string

string