HI version is available. Content is displayed in original English for accuracy.
Advertisement
Advertisement
⚡ Community Insights
Discussion Sentiment
56% Positive
Analyzed from 365 words in the discussion.
Trending Topics
#transaction#transactions#should#design#code#api#own#more#context#ctx

Discussion (7 Comments)Read Original on HackerNews
I believe this is largely an API design problem. Many client APIs (especially ORMs) will start a transaction implicitly for you if you haven't explicitly specified your own, leading to problems like in the article.
Having implicit transactions is just wrong design, IMO. A better-designed API should make transactions very explicit and very visible in the code: if you want to execute a query, you must start a transaction yourself and then query on that transaction supplied as an actual parameter. Implicit transactions should be difficult-to-impossible. We - the programmers - should think about transactions just as we think about querying and manipulating data. Hiding from transactions in the name of "ergonomy" brings more harm than good.
This means that the transaction becomes its own block, clearly separated, but which can reference pure values in the surrounding context.
The problem is that the thing you use to build the transaction can also be used to directly manipulate the DB. A better API design would be to separate those two things.