Start from an application like yours
Ten applications, from a shop's orders to a game server that comes back after SIGKILL. Each one's test plays the cases that make it hard, under Node.js and under Bun.
One actor per session or connection
A session's limits, timers and members live in one actor. The code around it only finds the actor by name and sends it events.
- A rate-limited API gatewayEvery client session needs a token bucket, a cap on requests in flight and timeouts against a slow, flaky upstream. On
node:http, the session's chart picks every status, 429, 502 and 504 included, and retries only aGET. It shows an async I/O processor that answers withfetch, and a request'straceparentcarried to the upstream and to OpenTelemetry. - A chat with workspaces, rooms and connectionsThousands of rooms and connections keep their members and history, though most sit idle. A workspace decides which rooms exist and spawns them; only a bound of actors stays in memory, the rest one file each on disk. It shows a store and a resident bound, the Spawner and each way a send meets an actor that is not there.
Retries, timeouts and refunds as states
Each of these runs a business process whose steps fail the way real ones do. Its test plays every failure on a simulated clock, so a 48-hour SLA takes no time.
- An order that pays, ships and refundsA payment times out or its answer is lost, a customer cancels during the shipment, the stock runs out after the charge. The order retries under one idempotency key and refunds what it charged, so a delivered order is charged exactly once (its test loses an answer and checks that the retry charges nothing more). It shows invoked services for the payment and the shipment, timeouts as delayed sends and a failed send that becomes a retry.
- Subscriptions billed during a releaseA subscription lives for years, and its chart changes under it. Release 2 renames a variable and adds states; a canary, then each chart, moves to it while renewals and payments are in flight. It shows migration of a mostly hibernated population, and the typed methods an operator uses to find who is left on the old release.
- A document reviewed by legal and financeTwo reviews run at once, finance waits for legal on large amounts, and a stage past its SLA escalates the document to a manager. Parallel regions,
In()guards and history states hold those rules. It shows an admin view over HTTP that reads every document's states, variables and due SLAs with the typed methods. - Background jobs with retries and deadlinesWorkers throw, hang or run past a deadline, and a slow recurring run must not push the schedule back. A job's delayed sends are its whole schedule, and the process exits by itself when the last job ends. It shows an I/O processor that aborts a hung worker, a graceful shutdown on
SIGTERMand the drift of fixed-delay jobs, measured.
Two systems, each a host, over a socket
The host decides which sends leave its system. The wire, the connection and what to do when it is gone are your code's, written in a transport.
- Stock held across a warehouse and a storefrontTwo carts race for the last unit, a hold expires, the warehouse goes down in the middle of a checkout. Each SKU is an actor that takes one request at a time and answers a repeated one as it answered the first (its test duplicates every message both ways); a cart compensates by releasing every line. It shows a transport over TCP, a failed delivery and a snapshot the warehouse comes back from.
- A Python system and a Node.js systemActors in two processes and two languages address each other by
tinyactors://address. A Node.js chart and a Python chart trade pings over one TCP connection, and a send to an actor the other side lacks fails back to its sender. Values cross unchanged, integers up to 2^64 included.
Customers' code in a sandbox per rule
- Alert rules your customers uploadAn uploaded rule may loop for ever, hoard memory, look for
requireor send to another customer's device. Each rule runs on a host of its own on the quickjs datamodel, with limits on operations and memory, so a runaway evaluation becomeserror.executionand the rule is suspended after three. Its README measures how long a loop holds the host and what a rule costs per device.
Turn timers that survive a crash
- A game server that survives being killedA match's turn timers must come back from a crash with the time they had left. The server takes a snapshot of the whole host every second, journals each client input, and after
SIGKILLrestores and replays the journal, or drops it. Its matchmaking service starts again from the lobby's waiting list.
Run a recipe on its own
A recipe runs against the published package, outside the repository. Install @tinyactors/node in a new project and copy the recipe into its examples/ directory:
git clone --depth 1 https://github.com/tinyactors-dev/tinyactors
mkdir -p recipes/examples && cd recipes
npm install @tinyactors/node@0.4.0
cp -r ../tinyactors/tinyactors-napi/examples/order-fulfillment examples/
node examples/order-fulfillment/main.mjs
node examples/order-fulfillment/test.mjsmain.mjs runs the application and prints what its README describes; test.mjs plays its hard cases. Three recipes differ:
- inventory-syncreuses the framing of remote-python, so copy
remote-pythonbeside it. - subscription-billingruns on 0.4.0, but two of its tests, a payment in flight during a migration, need a core change made after that release.
- remote-pythonbuilds the Python binding from the repository, so it runs only there:
mise run remote-pythonintinyactors-napi.