Community Comment: Part 1

The comments I provided in reaction to a community discussion thread on October 13, 2020:
https://www.linkedin.com/feed/update/urn:li:activity:6721405361934479360?commentUrn=urn%3Ali%3Acomment%3A%28activity%3A6721405361934479360%2C6721451805441622016%29

Software Engineer at Facebook: A lot of developers I talk to have trouble understanding database transactions and why they're incredibly useful.

A transaction is a way to group several reads and writes into ONE logical unit. When we encapsulate reads/writes into transactions, we can (usually) assume several guarantees, described by "ACID".

Atomicity
– either ALL the reads/writes succeed or ALL fail. If a fault occurs after some of the writes, then the database undos them and aborts.
– error handling is MUCH easier, we don't have to worry about some writes succeeding and some failing.

Consistency
– a transaction cannot violate invariants (or constraints) of your database.
– Ex. a constraint limits an integer attribute to values between 1 to 10. Transactions cannot violate that.

Isolation
– Most databases are accessed by several clients at the same time, this can cause concurrency problems.
– Databases ensure that when all transactions are committed, the result is the same as if they had run serially (one after another).

Durability
– Once a transaction is committed, you won't lose it!

Not ALL databases have ACID transactions! Some may make the tradeoff for speed or accessibility.

Gfesser: Definitely important for developers to understand. Just keep in mind that database products tend to implement ACID differently, so developers cannot simply rely on claims of compliance. Also, keep in mind that "C" arguably doesn't really belong in the acronym. Kleppmann's summary perhaps said it best, commenting that it was "tossed in to make the acronym work" in the original paper. The reality is that "atomicity, isolation, and durability are properties of the database, whereas consistency (in the ACID sense) is a property of the application. The application may rely on the database's atomicity and isolation properties in order to achieve consistency, but it's not up to the database alone."
Designing Data-Intensive Applications
https://www.erikgfesser.com/weblog/2018/06/new-book-review-designing-data-intensive-applications-big-ideas-behind-reliable-scalable-maintainable-systems-martin-kleppman.html

Subscribe to Erik on Software

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe