Implementing Transactions with Sequelize
Throughout the previous chapters, we went over how to ensure that data integrity is maintained from within our Node.js application using life cycle events, validations, and constraints. However, these methods do not guarantee that the data is internally consistent in the database itself. Databases offer a way to atomicize integrity using transactions.
Transactions are used for ensuring a process has been completed without interruptions such as a connection failure or the power abruptly failing. They are also used for isolating, or locking, applications from manipulating data concurrently, which alleviates race condition issues. Transactions promise data validity by following the ACID principle, which stands for atomic (“all-or-nothing” behavior), consistent (adheres to constraints), isolated (transactions happen sequentially and unbeknownst toward each other), and durable (persistent storage).
A generic use case for transactions...