Lesson 1 of 2 · 4 min 36 sec

RSX: From One Database to Many Actors

Chapters

  1. The design you know
  2. Start from ownership
  3. Four tools for the line
  4. Know before you ship
Transcript
Download transcript

The design you know

You probably know this design. A few stateless services, and one database that holds every fact. At Matinee, a small cinema, selling a seat means checking the show, charging the customer and writing the ticket. One transaction, in one place. It is a good design, and it is easy to reason about. As the app grows, everything meets at that one database. When writes compete there, more servers alone do not help. So teams split the data. Now one sale spans several places, with waiting, retries and races that are hard to see and harder to test.

Start from ownership

The actor model starts from the other end. An actor is code, its own private memory, and an inbox. Only that code can change that memory, and it runs one message at a time. On the Internet Computer an actor is a canister. Its memory persists, and a trap rolls back the writes made during that message. RSX draws the same line again inside the actor. The box office has a shows module and a tickets module. Each owns its saved memory, and the others must ask through its service. Yet inside one call they still check and change things together, like the transaction you know. The shapes of that memory, and of each message, are written as types, and the build checks them. Upgrades are checked too. New code states which saved memory it expects, and any change of shape is a migration you write. Data arriving from outside is still checked when it arrives. Money answers to someone else, so the wallet is a second actor. And every cinema gets its own box office. Separate actors share no memory, so their work can overlap across many machines. That is sharding, drawn as ownership. How much it gains depends on the design. The line between actors has a price. Run the same sale again. It now sends a message and waits. While it waits, other messages run, even in the same actor. And the answer can be yes, no, or not known yet. In everyday code this is where the tangle of flags and retries begins.

Four tools for the line

Takt lets you write the sale as a workflow. Hold the seat. Charge the wallet. Then confirm the ticket, or release the seat. The workflow is a graph you can read. A person or an AI can write it, and the build checks it against your types. Its progress is saved, so you can see where each sale is. Reactor carries the message. It keeps each one until the other side confirms it was stored, resends the same bytes if it must, and delivers in order for that peer. Rechain keeps the wallet's history. The charge is an action. Reducers check it against their own state, and either all accept or nothing changes. Each accepted action becomes a block, linked to the one before. That makes the log tamper-evident, for the actions you choose to record. Ashroot is an optional layer of tables, indexes and relationships. A unique index means seat C4 for show seven is sold once. A relationship means a ticket cannot point at a show that does not exist. Under it are the collections: ordered maps and sets, like a database index, and others, such as approximate filters, when a feature needs them.

Know before you ship

You can rehearse all of this. A test runs the whole sale in a fixed order, including the awkward cases, and counts the instructions each step executes. That measures work. Time and fees on a live network are separate questions. Rules you write down can also go to formal tools. The SDK checks parts of its own memory foundations this way, each proof with a stated scope. A proof covers what you specify, and nothing more. So keep the database way of thinking, and add one question: who owns each fact? RSX gives you the tools to hold those lines. Private, typed memory. Checked upgrades. Workflows, delivery, history and integrity. Next, we open one module and see what it owns.

Matinee cinema

Inside a ticket sale

Back to the film
Step through the ticket sale
One ticket sale, two actors
Box office Actor
Seat C4Held
What’s nextAsk wallet
Wallet Actor
Ana’s balance30 credits
ChargeNone
Ready to send the payment request
The box office holds the seat. Only the wallet can change Ana’s balance.