Ir al contenido
Español
actor-ts wordmark with interconnected-actors logo

actor-ts

The actor model for TypeScript — cluster sharding, event sourcing, distributed data, persistence, observability. Runs on Bun, Node, and Deno.

Actors, supervision, lifecycle

The classic actor model in idiomatic TypeScript. Each actor owns its state and processes messages one at a time, so you stop reasoning about locks and race conditions. When a child fails, its parent gets to decide whether to restart, escalate, or stop it — supervision trees give you fault tolerance as a structural property, not as a try/catch afterthought.

Cluster + sharding

Run the same actor system across many nodes. Members discover each other via gossip, the failure detector flags unreachable peers, and split-brain resolvers decide who survives a partition. Sharding distributes long-lived stateful entities across the cluster, rebalances when nodes join or leave, and remembers which entity lives where so a restart picks up cleanly.

Event sourcing + persistence

Make actor state survive crashes by recording the events that led to it instead of the state itself. PersistentActor replays its event log on startup; DurableState writes a single snapshot when full history isn’t useful. Journals plug in — in-memory for tests, SQLite for single-node prod, Cassandra or S3 for scale — with first-class snapshotting + projections for read-side views.

Distributed data (CRDTs)

Shared state across the cluster without a coordinator. Eight conflict-free replicated data types — counters, registers, sets, maps — that always converge to the same value no matter the order of updates. Pick quorum reads + writes when you want strong-ish consistency, or accept gossip propagation when you don’t. Durable backend keeps the state across restarts.

Integrations

The world outside the actor system, behind one consistent shape. HTTP with a directive-style route DSL on Fastify, Express, or Hono backends. Message brokers — Kafka, MQTT, AMQP, NATS, Redis Streams, gRPC, SSE, WebSocket, raw sockets — all wrapped by a common BrokerActor base with reconnect, buffering, and fan-out baked in. Cache + serialization are pluggable abstractions.

Observability + testing

Production-grade visibility from day one. Stock metrics for every actor, mailbox depth, gossip lag, restart counts — exported via Prometheus or OpenTelemetry. Per-message tracer spans, so a request flows through your cluster with one trace ID. Management HTTP endpoints expose cluster state. TestKit gives deterministic multi-node tests with a manual scheduler for time control.

Two end-to-end sample apps live in the repo, each with six interchangeable frontends (Plain HTML, Lit, Angular, React, Next.js, SvelteKit) talking the same WebSocket protocol to a clustered backend. Clone, bun examples/<sample>/backend/main.ts, open the frontend in a browser, and poke at a real running actor system.

actor-ts is pre-1.0. The API surface is broad and battle-tested in internal use, but breaking changes can land between minor versions until 1.0 is cut. Pinning a specific minor version in your package.json and reading the CHANGELOG before upgrading is the safe play during this phase.