Two-phase commit
Coordinate atomic state changes across multiple Meridian workers without losing writes when one peer crashes mid-transaction. The two-phase commit (2PC) protocol splits each operation into a prepare round and a commit round, giving every participant a veto before any side effect lands.
1.The prepare phase
The coordinator broadcasts a PREPARE message to every participant carrying the proposed change. Each participant writes the change to its undo log, locks the affected rows, and replies with YES only after the log fsyncs to disk. A single NO aborts the whole transaction.
2.The commit phase
If every participant voted YES, the coordinator persists a commit record to its own log and fans out COMMIT. Participants apply the change, release locks, and acknowledge. The coordinator only forgets the transaction once every acknowledgement is in hand, which is why crash-safe logging matters more than raw throughput here.
3.Meridian wiring
Meridian ships a built-in coordinator that wraps any registered tool call in a 2PC envelope. Pass atomic: true and a participant list. Meridian handles the prepare fan-out, timeout backoff, and recovery replay on coordinator restart.
const tx = await meridian.transact({
atomic: true,
participants: ["wallet", "ledger", "audit"],
payload: { from: "A", to: "B", amount: 42 }
});
if (tx.status === "committed") {
console.log("All three peers durably applied", tx.id);
}