The Anatomy of a Tool
Every LVD tool comes out of one factory with five named parts. Here is what they are, why validation stays out of the handler, and what a two-part result buys.
A concert-goer is charged for two seats, and then the booking system crashes before it records which seats she bought. She has paid and holds nothing. Any operation that changes state in more than one place can end up in this half-finished state. In LVD the Tools layer is where the business knows which changes belong together, so it is also where the answer lives.
When every change lands in one database, the remedy is the familiar one: wrap the calls in a database transaction, so that either all of them take effect or none do. What LVD adds is a ruling on who creates that transaction. It is the tool.
The reasoning is neat. A repository in the Resources layer sees only its own table. Only the tool knows that creating a booking and holding its seats are one indivisible business act. So the tool opens the transaction and passes the transaction object down to each resource call. Resources stay ignorant of transaction management; they simply accept an optional transaction argument and use it if one arrives.
await db.transaction(async (trx) => {
const booking = await bookingRepository.create(params, trx);
for (const seat of params.seats) {
await seatRepository.hold(seat, booking.id, trx);
}
});
If a seat cannot be held, the booking row disappears with it. No cleanup code is needed, because the database does the undoing.
Now suppose the booking spans separate services, each with its own storage: seat inventory in one, card payments in another, ticket delivery in a third. There is no transaction that covers them all. The saga pattern, which dates to a 1987 paper by Garcia-Molina and Salem, replaces one big transaction with a sequence of small local ones, each paired with a compensating transaction that undoes its effect.
The rule is simple. If every step succeeds, the saga succeeds. If step k fails, the compensations for steps 1 through k minus 1 run in reverse order. Take the booking again:
If the card is declined, only the hold needs releasing. If ticket issuing fails, the refund runs first and the release follows. Reverse order matters because later steps may depend on earlier ones still being in place.
It is tempting to treat sagas as the grown-up answer and local transactions as the beginner's. The book argues the opposite, and the trade-offs explain why.
The guideline follows directly. Prefer a local transaction whenever every state change targets the same datastore, and introduce a saga only when the workflow genuinely crosses service boundaries.
A practical corollary is that you should look hard at whether the boundary is real. Two tables that happen to live in different services because of history are a different situation from two systems that cannot share a database. If the first is true, consolidating the data may remove the saga altogether. If the second is true, accept the cost and design each compensation as carefully as the step it reverses.
Consistency is a business concern, so the tool decides where an atomic unit begins and ends. Use a database transaction when one datastore is involved, and a saga with explicit compensations when several are. Resources stay simple either way. Both techniques are about a single tool's workflow; coordinating several tools is a separate matter, covered by Axiom A5. For the patterns that compose steps within one handler, see orchestrating tools, and for the layer's wider context, Layer 4: Tools.