Skip to content
StackDecode
System Design
15. Software Design PatternsAnimated walkthrough

Unit of Work Pattern

Track changes and save them together.

The idea

Collects new, changed and deleted objects and commits them in one transaction.

Watch it work

The steps light up one at a time. Use the controls to pause or step through.

  1. 1Begin a unit of work
  2. 2Track changes
  3. 3Commit once
  4. 4Roll back on error
1/4

Step by step

  1. 1Begin a unit of work
  2. 2Track changes
  3. 3Commit once
  4. 4Roll back on error

Where it is used

ORMs and transactions.

Watch out for

Long units hold memory and locks.

Related