All articles

SOFTWARE ENGINEERING

Protect related business records with transactions

Treat a workflow update as a consistent data operation and define what happens on failure.

Related updates need a shared outcome

PostgreSQL transactions group operations into a unit that can be committed or rolled back. This matters when a workflow updates several related records. The application should define which changes belong together and how it reports a failed operation. A transaction boundary is a data design decision rather than a visual feature of the interface. [1]

Sketch failure before success

Take one operation and list the records it reads or changes. Then consider a failure between each pair of steps. Decide what should remain visible to the user and which stored changes should be retained. Separate the database outcome from operations outside the database, such as sending a notification or writing to another service.

For a repeated request, define whether the second attempt should create a new operation or refer to the existing one. Retain stable identifiers where the workflow needs them. Test the result with failures and retries instead of checking only the successful path. This suggested exercise can uncover issues before they appear as inconsistent totals or duplicate records.

Make the result clear in the interface

A user needs a dependable status after submitting an operation. Do not show completion merely because a button was clicked. Connect the message to the actual outcome and preserve enough context to retry safely. Document the expected behavior for corrections and cancellation. These rules are useful in a browser product, a native desktop application, and a service API. Keeping them in the data contract helps the interfaces stay consistent as the system grows.

Sources

  1. PostgreSQL: transactions