| ▲ | sixtram 9 hours ago | |
I use a similar strategy for API design. Every API call is wrapped in a large database transaction, and I either roll back or commit the transaction based on dry-run or wet-run flags. This works well as long as you don’t need to touch the file system. I even wrap emails this way—emails are first written to a database queue, and an external process picks them up every few seconds. | ||
| ▲ | sixtram 9 hours ago | parent [-] | |
To continue, this design has additional benefits: The code is not littered with dry-run flag checks; the internal code doesn’t even know that a dry run is possible. Everything is rolled back at the end if needed. All database referential integrity checks run correctly. Some drawbacks: any audit logging should run in a separate transaction if you want to log dry runs. | ||