tephra
A DCB-compliant, immutable event store with global ordering.
Tephra is a Dynamic Consistency Boundary (DCB) event store. Instead of a static consistency
boundary baked into an aggregate, the boundary is derived per decision from a query. Events
carry a type plus a set of tags (course:c1, student:s1), so one event can belong to several
entities at once, and a decision reads exactly the events it depends on and guards exactly those
on append.
This crate is the embedded engine: the durable log, the single writer, the index, and the read
paths. Use it directly in-process, or reach it over the network with the
tephra-server TCP server and the
tephra-client client.
Design
The log is the source of truth and everything else is derived. Data is written once, never
updated and never deleted, keyed by a dense monotonic position assigned by the single writer.
Indexes need no write-ahead log and no fsync on the write path, because they can be rebuilt by
replaying the log. See
ARCHITECTURE.md for the full
rationale and the alternatives that were rejected.
Example
use ;
// Open (or create) a log directory and start the single-writer coordinator.
let set = open?;
let = start?;
// Build a packed event, then append it guarded so it fails if course:c1 already exists.
let ty = new?;
let tags = new?;
let event = new?;
let guard = new;
handle.append?;
// Reads run on the caller's thread over a snapshot. `read` returns a lending iterator, so it
// is consumed with `while let`, not a `for` loop.
let query = item;
let mut reads = handle.read;
while let Some = reads.next
coordinator.shutdown;
Related crates
tephra-types: the shared vocabulary (positions, names, query model).tephra-server: a TCP server exposing the engine.tephra-client: a synchronous client for the server.seglog: the low-level segmented record log underneath.
License
Licensed under the Apache License, Version 2.0.