Skip to content

Sharding.ts

Runs shard ownership and message routing for Effect Cluster.

Sharding decides which shard owns an entity id, tracks which shards belong to the local runner, and sends cluster messages to local handlers or remote runners. It also registers entities and singletons, creates clients for entity requests, polls stored messages, and tracks shutdown state. The main layer connects these responsibilities to runner communication, storage, health checks, configuration, and local resources.

Since v4.0.0



Layer that constructs the Sharding service from sharding configuration, runner communication, message storage, runner storage, runner health, the snowflake generator, and the entity reaper.

When to use

Use when you need to assemble a cluster sharding runtime from explicit sharding configuration, runner communication, message storage, runner storage, and runner health layers.

Details

The layer provides the Sharding service and installs its own snowflake generator and entity reaper. Callers still provide ShardingConfig, Runners, MessageStorage, RunnerStorage, and RunnerHealth.

Gotchas

Persisted messages require a non-no-op MessageStorage; if this layer is provided with MessageStorage.layerNoop, persisted sends defect.

See

  • Sharding for the service provided by this layer

Signature

declare const layer: Layer.Layer<
Sharding,
never,
Runners | MessageStorage.MessageStorage | RunnerStorage | ShardingConfig | RunnerHealth.RunnerHealth
>

Source

Since v4.0.0

Service that registers entities and singletons, routes messages to owned shards, generates runner-local snowflake ids, and polls storage for persisted work.

When to use

Use to access or provide cluster routing, shard ownership, entity registration, singleton registration, and persisted-work polling.

Signature

declare class Sharding

Source

Since v4.0.0