Skip to content
Web Design & Development

Database Transactions, Done Properly

Grouping database operations so they either all succeed or all fail, keeping data consistent.

Marcus Adeyemi Technical Director 2 min read 21 views
Database Transactions, Done Properly

Where most projects go wrong

The usual mistakes:

  • API calls inside open transactions
  • Transactions spanning user interaction
  • Ignoring rollback handling
  • Assuming default isolation fits every case

What good looks like instead

  • Wrap related writes in transactions
  • Keep transactions short
  • Handle deadlock retries
  • Avoid external calls inside transactions
  • Test failure paths
What to do and what to avoid with database transactions, side by side
Good practice against the usual mistakes, from the sources listed below.

Why it matters

Without transactions, interrupted operations leave half-finished data such as orders without payments.

The specs that matter

Published figures for Database Transactions
MeasureFigure
Atomicityall operations in a transaction succeed or none do
Isolation levelscontrol what concurrent transactions can see
Deadlocksoccur when transactions wait on each other
Long transactionshold locks and block other work

Knowing when to hand it over

Tip: Bring in help when data inconsistencies appear after failures.

Where this comes from

The figures and practices above come from the sources listed.

Working on something like this?

We take on Web Design & Development work for teams who want it done once, properly. Tell us what you are building and we will tell you honestly whether we are the right studio for it. Start a project.

Where to go next

Spotted something wrong? Report an error on this page. We correct on the page and say what changed.

All services

The work behind this article, and what it costs.

Marcus Adeyemi

Builds and maintains the web work. Writes about front-end architecture, performance, accessibility and the unglamorous parts of keeping a site alive.

Keep reading

More in Web Design & Development