[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"$f2a7ma11vxboi7":3},{"_id":4,"slug":5,"title":6,"subtitle":7,"kind":8,"cards":9,"tags":58,"categories":60,"source":62,"lang":65,"author":66,"audioState":69,"stats":70,"publishedAt":73,"renderer":74},"6abaf092ca21c797c7e9b847","two-phase-commit-is-a-trap-how-real-systems-do-distributed-t-58085f8f","Two-Phase Commit Is a Trap: How Real Systems Do Distributed Transactions","Hello, I'm Maneshwar, and I'm building LiveReview — a blast-radius aware AI code review built for your business-critical systems.","news",[10,13,18,23,28,33,38,43,48,53],{"headline":6,"body":11,"imageUrl":12,"sourceImageUrl":12},"Hello, I'm Maneshwar, and I'm building LiveReview — a blast-radius aware AI code review built for your business-critical systems. Star us to help devs discover the project, give it a try, and share your feedback to help improve the product. When you are first building an application, a transaction is the cheapest guarantee you will ever get. A customer places an order. You charge their card, reserve the inventory, write a ledger entry for accounting.","https:\u002F\u002Fmedia2.dev.to\u002Fdynamic\u002Fimage\u002Fwidth=1200,height=627,fit=cover,gravity=auto,format=auto\u002Fhttps%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4mgi75atdryieg00wkie.jpg",{"headline":14,"body":15,"imageUrl":16,"images":17},"You wrap the whole thing in BEGIN and","You wrap the whole thing in BEGIN and COMMIT, and if any one of those writes falls over, the database quietly rewinds the other two. It is as if the order never happened. You probably wrote that code in four minutes and never thought about it again. What you were leaning on there are two of the ACID guarantees, doing unpaid labour on your behalf.","\u002Fapi\u002Fmedia\u002Fposts\u002Ftwo-phase-commit-is-a-trap-how-real-systems-do-distributed-t-58085f8f\u002F1.webp",{"local":16},{"headline":19,"body":20,"imageUrl":21,"images":22},"Atomicity. All three writes land, or none of","Atomicity. All three writes land, or none of them do. There is no universe where the card gets charged but the stock never gets reserved.","\u002Fapi\u002Fmedia\u002Fposts\u002Ftwo-phase-commit-is-a-trap-how-real-systems-do-distributed-t-58085f8f\u002F2.webp",{"local":21},{"headline":24,"body":25,"imageUrl":26,"images":27},"Isolation. While the transaction is in flight, nobody","Isolation. While the transaction is in flight, nobody else can see the half-finished middle. Another request checking the customer's balance will not catch a charge for an order that has not finished processing. You wrote the SQL. The database did the genuinely hard part, for free, and never asked for credit. Then you split the database, and the guarantee quietly leaves Traffic grows. Writes grow. That one box starts breathing heavily. So you do what everyone does. You shard, or you break the monolith into services and give each one its own database.","\u002Fapi\u002Fmedia\u002Fposts\u002Ftwo-phase-commit-is-a-trap-how-real-systems-do-distributed-t-58085f8f\u002F3.webp",{"local":26},{"headline":29,"body":30,"imageUrl":31,"images":32},"The details vary. The outcome is identical: your","The details vary. The outcome is identical: your data now lives on several independent machines that have never been introduced to each other. That one payment flow is now three separate operations against three separate databases. Card charged in the payments database. Stock reserved in the inventory database. Ledger entry recorded in accounting. There is no BEGIN big enough to cover all three, because none of them knows the others exist.","\u002Fapi\u002Fmedia\u002Fposts\u002Ftwo-phase-commit-is-a-trap-how-real-systems-do-distributed-t-58085f8f\u002F4.webp",{"local":31},{"headline":34,"body":35,"imageUrl":36,"images":37},"So when the card charge commits and the","So when the card charge commits and the inventory reservation then fails because the last unit just sold, nothing rolls back. That charge is already durable, on a different machine, in a database that has no idea an order died somewhere else.","\u002Fapi\u002Fmedia\u002Fposts\u002Ftwo-phase-commit-is-a-trap-how-real-systems-do-distributed-t-58085f8f\u002F5.webp",{"local":36},{"headline":39,"body":40,"imageUrl":41,"images":42},"At a few hundred orders a day, you","At a few hundred orders a day, you will see this maybe once and fix it by hand. At a few thousand transactions a second across distributed infrastructure, partial failure stops being an incident and starts being a Tuesday.","\u002Fapi\u002Fmedia\u002Fposts\u002Ftwo-phase-commit-is-a-trap-how-real-systems-do-distributed-t-58085f8f\u002F6.webp",{"local":41},{"headline":44,"body":45,"imageUrl":46,"images":47},"This whole shape of problem has a name","This whole shape of problem has a name: the distributed transaction. One logical operation spanning multiple independent databases or services, where every step needs to either succeed together or get cleaned up when something goes sideways.","\u002Fapi\u002Fmedia\u002Fposts\u002Ftwo-phase-commit-is-a-trap-how-real-systems-do-distributed-t-58085f8f\u002F7.webp",{"local":46},{"headline":49,"body":50,"imageUrl":51,"images":52},"The literature offers you two answers. The industry","The literature offers you two answers. The industry has very firmly picked one of them, and knowing why will save you a genuinely painful quarter. The textbook answer: two-phase commit Two-phase commit is the classic academic solution, formalised decades ago in the X\u002FOpen XA specification.","\u002Fapi\u002Fmedia\u002Fposts\u002Ftwo-phase-commit-is-a-trap-how-real-systems-do-distributed-t-58085f8f\u002F8.webp",{"local":51},{"headline":54,"body":55,"imageUrl":56,"images":57},"You introduce a new component, a coordinator, whose","You introduce a new component, a coordinator, whose entire job in life is to make every participant agree on the outcome before anybody makes anything permanent. It runs in two phases, which is where the name comes from.","\u002Fapi\u002Fmedia\u002Fposts\u002Ftwo-phase-commit-is-a-trap-how-real-systems-do-distributed-t-58085f8f\u002F9.webp",{"local":56},[59],"dev",[61],"Technology",{"name":63,"url":64},"Dev.to","https:\u002F\u002Fdev.to\u002Flovestaco\u002Ftwo-phase-commit-is-a-trap-how-real-systems-do-distributed-transactions-9i9","en",{"handle":67,"displayName":68},"spots","Spots","queued",{"views":71,"likes":72,"saves":72,"shares":72,"completions":72,"opens":72,"skips":72,"depthSum":72},3,0,"2026-09-28T22:56:18.565Z","local"]