<!-- https://tinyactors.dev/when-to-use/ -->
# When to use tinyactors

Kind: explanation. For: [Tech lead who approves dependencies](https://tinyactors.dev/audiences/tech-lead.xml), [Agent-platform engineer](https://tinyactors.dev/audiences/agent-platform.xml), [Workflow developer who tests](https://tinyactors.dev/audiences/workflow-tester.xml).
Voice: [Explanation](https://tinyactors.dev/voices/explanation.xml).

> Why tinyactors fits an embedded event loop, what a crash keeps and how it compares with Temporal, Durable Objects, Rivet and XState.

tinyactors embeds SCXML actors on your event loop across [Node.js, Python, browsers and C](https://tinyactors.dev/architecture/index.md#what). Your code owns the [process, store, effects and cross-host placement](https://github.com/tinyactors-dev/tinyactors/blob/main/README.md#layers-and-responsibilities) while the core [passes 191 W3C tests](https://tinyactors.dev/performance/index.md#correctness).

[Check capacity numbers](https://tinyactors.dev/performance/index.md) · [Write a first chart](https://tinyactors.dev/guides/charts/index.md#first-chart) · [Build a team chat](https://tinyactors.dev/chat/index.md)

<a id="use-it-when"></a>

## tinyactors fits millions of in-process statechart actors

tinyactors fits when you need memory density, SCXML charts, event-based effects, simulated-clock tests and one core across runtimes.

- **Small actors and hibernation**: Actors take [about 530 bytes started and 120 hibernated](https://tinyactors.dev/guides/capacity/index.md); operations [cost about the same](https://tinyactors.dev/performance/index.md) at four million as at two. Idle actors hibernate and wake on events; [two million actors ran](https://tinyactors.dev/guides/hibernation/index.md#at-scale) with at most 1000 in memory.
- **Explicit SCXML statecharts**: Each actor runs an [SCXML chart](https://tinyactors.dev/guides/charts/index.md) of states, events and transitions with JavaScript or Python expressions. SCXML `invoke` runs [long operations per state](https://tinyactors.dev/guides/services/index.md), and [QuickJS sandboxes user-uploaded charts](https://tinyactors.dev/guides/quickjs/index.md).
- **Effects as events without mocks**: A chart reaches the world only through sends to an [I/O processor](https://tinyactors.dev/guides/io-processors/index.md), a handler you give the host. Because effects are events, tests avoid mocking external services: [test handlers](https://tinyactors.dev/guides/testing-recipes/index.md#three-tools) record sends and answer, return errors or never reply.
- **Timeouts tested with a simulated clock**: A `SimulatedClock` [moves only when the test moves it](https://tinyactors.dev/guides/testing/index.md): a timeout of an hour takes no time. A payment that retries every 30 seconds runs all three attempts in milliseconds, alongside [property tests](https://tinyactors.dev/property-testing/index.md).
- **One C core across runtimes**: One C core [runs the same tests](https://tinyactors.dev/performance/index.md#correctness) and the same chart in Node.js, Python, C and [browsers](https://tinyactors.dev/guides/browser/index.md).

<a id="do-not-use-it-when"></a>

## Limits: SCXML charts, single hosts and changing APIs

tinyactors stops at SCXML charts inside single hosts under active development with frequent breaking changes.

- **Arbitrary actor code**: Each actor runs an [SCXML chart](https://tinyactors.dev/guides/charts/index.md) with JavaScript or Python expressions. Erlang and Akka actors run any code you give them.
- **Managed clustering and failover**: Actors stay in their spawning host, so your program runs a [named host per process](https://tinyactors.dev/guides/other-systems/index.md#systems). [Placement, deployment, failover and transport](https://github.com/tinyactors-dev/tinyactors/blob/main/README.md#layers-and-responsibilities) between hosts are your program's work.
- **A stable API**: The README says tinyactors is under active development and makes [frequent breaking changes](https://github.com/tinyactors-dev/tinyactors/blob/main/README.md#status). Follow each package release and upgrade change in [the tinyactors changelog](https://tinyactors.dev/changelog/index.md).

<a id="crash"></a>

## A crash stops memory and keeps saved state

Actors live in process memory, so a crash stops every actor and keeps only what your program saved.

- **Host snapshots with `Host.restore`**: `Host.restore` runs a snapshot in this process or another with [variables, queued events and pending timers](https://tinyactors.dev/guides/snapshots/index.md#what-it-holds). [One snapshot](https://tinyactors.dev/guides/snapshots/index.md) holds two million actors in 165 MB.
- **Host-bound hibernation blobs**: Each hibernated blob carries [its host's random identity](https://tinyactors.dev/guides/hibernation/index.md#what-a-blob-holds), so a fresh host refuses blobs from another host. A host restored from the original host's snapshot accepts those blobs.
- **Input journal replay**: A restored host starts at snapshot time and accepts blobs hibernated since. Your program [replays all other inputs](https://tinyactors.dev/guides/journal/index.md) after the snapshot from its own journal.
- **Application store ownership**: tinyactors saves blobs through your store and takes snapshots when asked, [restoring with matching options](https://tinyactors.dev/guides/snapshots/index.md#restoring). All storage I/O stays in [your application layer](https://github.com/tinyactors-dev/tinyactors/blob/main/README.md#layers-and-responsibilities).
- **Chart updates and missing actors**: [Live migration](https://tinyactors.dev/guides/migration/index.md) updates actors at rest to a new chart while keeping sessions, states and queues. A send to a hibernated actor wakes it, while a [send to an absent actor](https://tinyactors.dev/guides/missing-actors/index.md) fails immediately.

<a id="lock-in"></a>

## Portable charts and MIT license, build-bound snapshots

Charts, event boundaries and the MIT license move across runtimes, whereas snapshots require matching memory layout.

- **W3C SCXML charts meet code at events**: Each chart is a W3C SCXML document rather than a proprietary format. Your code meets tinyactors only at event boundaries: inputs go in, and effects come out to your handlers. Source: [W3C, "State Chart XML (SCXML)"](https://www.w3.org/TR/scxml/)
- **Core passes all 191 W3C SCXML tests**: The C core passes all 191 automatic tests of the W3C SCXML conformance suite. Every binding runs the same suite across Node.js, Python, C and [browsers](https://tinyactors.dev/guides/browser/index.md). Source: [Memory, capacity and performance, "Correct by the standard"](https://tinyactors.dev/performance/index.md#correctness) · [W3C, "State Chart XML (SCXML)"](https://www.w3.org/TR/scxml/)
- **MIT license covers every tinyactors package**: Every package is MIT licensed, allowing you to use, change and ship tinyactors while keeping its copyright and permission notice. Source: [tinyactors, `LICENSE`](https://github.com/tinyactors-dev/tinyactors/blob/main/LICENSE)
- **Snapshots require matching memory layout**: Snapshots and blobs use tinyactors' own format, and a snapshot restores only on a build with the same memory layout. Keep data that must last in your own database. Source: [Snapshots, "Restore with the options the snapshot had"](https://tinyactors.dev/guides/snapshots/index.md#restoring)

<a id="compare"></a>

## tinyactors runs SCXML directly inside your own hosts

Temporal, Durable Objects and Rivet manage persistence or placement, whereas XState is inspired by SCXML.

- **Temporal runs a server; tinyactors runs in-process**: Self-hosted Temporal runs Temporal Server and persistence stores on Docker, Kubernetes or by hand. Your program creates a tinyactors host object directly for tests and runtime, handling journaling and [cross-host transport](https://tinyactors.dev/guides/other-systems/index.md). [tinyactors compared with Temporal](https://tinyactors.dev/compare/temporal/index.md) sets the two side by side: tests, crashes and running changes. Source: [Temporal, "Temporal Service"](https://docs.temporal.io/temporal-service) · [Temporal, "Self-hosted Temporal Service guide"](https://docs.temporal.io/self-hosted-guide)
- **Durable Objects place Workers; tinyactors uses your process**: Cloudflare describes a Durable Object as a Worker that combines compute with storage, placed near its first request. A tinyactors actor runs inside any server or browser tab your program operates, with storage under your control. [tinyactors compared with Durable Objects](https://tinyactors.dev/compare/durable-objects/index.md) sets the two side by side: idle sessions, tests and deploys. Source: [Cloudflare, "Durable Objects"](https://developers.cloudflare.com/durable-objects/)
- **Rivet places durable processes; tinyactors pins to hosts**: Rivet describes its actors as durable processes in your backend, placed by Rivet Cloud or your control plane. A tinyactors actor stays in the host that spawned it, and your program routes across hosts. [tinyactors compared with Rivet](https://tinyactors.dev/compare/rivet/index.md) sets the two side by side: placement, sleeping actors and deploys. Source: [Rivet, "Actors"](https://rivet.dev/docs/actors)
- **XState takes SCXML inspiration; tinyactors runs SCXML**: XState's README says it is inspired by the SCXML specification. tinyactors runs SCXML documents themselves, the same chart in every language, and the C core passes 191 W3C tests. [tinyactors compared with XState](https://tinyactors.dev/compare/xstate/index.md) sets the two side by side: the format, populations and running changes. Source: [XState, `README.md`](https://github.com/statelyai/xstate) · [Memory, capacity and performance, "Correct by the standard"](https://tinyactors.dev/performance/index.md#correctness)

[Write a first chart](https://tinyactors.dev/guides/charts/index.md#first-chart) · [Test your charts](https://tinyactors.dev/guides/testing/index.md) · [Check capacity numbers](https://tinyactors.dev/performance/index.md)
