northwind/orders-service
1,284 commits
import { db } from '../db.js';import { publish } from './outbox.js';/** * Creates an order and its outbox row in one transaction, so a crash * between them is impossible rather than merely unlikely. */export async function createOrder(input: CreateOrder) { return db.transaction(async (tx) => { const order = await tx.orders.insert(input); await publish(tx, 'order.created', { id: order.id }); return order; });} The service that owns orders, payments and the outbox.
Every write goes through the transactional outbox: the row and the event are inserted together, and a single drainer sends them in the order they were written. Consumers are allowed to be slow. They are not allowed to be surprised.
bun installbun run dev