An example demonstrating how to maintain consistency in the absence of transactions, using the Write Last, Read First principle featuring TigerBeetle
The example will implement the API with Resonate’s durable execution framework, Distributed Async Await. Distributed Async Await guarantees eventual completion simplifying reaching consistency even in the absence of transactions.
Read the post on the TigerBeetle Blog
In the absence of transactions, we need to make an explicit architectural decision: Which system determines the existence of an account?
- System of Record (TigerBeetle): The champion. If the account exists here, the account exists on a system level.
- System of Reference : The supporter. If the account exists here but not in the system of record, the account does not exist on a system level.
Write last, read first
When Writing: Write to the system of record last.
When Reading: Read from the system of record first.
Since the system of reference doesn’t determine existence, we can safely write to it first without committing anything. Only when we write to the system of record does the account spring into existence. Conversely, when reading to check existence, we must consult the system of record, because reading from the system of reference tells us nothing about whether the account actually exists.
The example is a command line interface to consistently create an account in the system of reference (here sqlite) and the system of record.
Download the required binaries to the bin/ directory:
- TigerBeetle: Download from https://docs.tigerbeetle.com/start
- Resonate: Download from https://github.com/resonatehq/resonate/releases
Install dependencies:
npm installRun the setup script to prepare the databases:
./scripts/setup.shThe setup script will:
- Clean up any existing databases
- Create a new TigerBeetle data file at
bin/0_0.tigerbeetle - Create a new SQLite database at
bin/accounts.db
In a separate terminal window, start TigerBeetle:
./bin/tigerbeetle start --addresses=3000 bin/0_0.tigerbeetleIn a separate terminal window, start Resonate:
./bin/resonate devCreate an account:
tsx create-account.ts <uuid>Example:
tsx create-account.ts user-123./scripts/check.sh