Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Patterns for implementing transactions outside of a database

I have to send an email, write to a file, and call a web service. To maintain consistency, all steps must happen. If any step throws an exception or errors out, all steps must be rolled back.

Before I go rolling my own object ACID engine, are there any commonly accepted patterns for implementing ACID semantics at the object level?

Better yet, are there any existing libraries I can use for the the .NET platform?

Edit: I know sending an email can't be undone, but failing to connect to the SMTP server is cause to kill the whole transaction. Also, I'd like this to be extensible for use with future actions.

like image 495
Ryan Michela Avatar asked Feb 24 '09 03:02

Ryan Michela


1 Answers

The last time I saw something like this was several years ago. The little bit that I remember about it is that it was using the command pattern and storing each command object in a queue. I think it was a LIFO stack.

So if the "transaction" failed, the engine would pop off a command object, undo the command, then destroy the command object. Repeat until the stack was empty. The stack got cleared if the "transaction" was successful.

Unfortunately, I don't remember more than that.

CSLA.NET implements a similar undo stack. That's the only example with code that I can think off the top of my head.

like image 114
Hector Sosa Jr Avatar answered Oct 20 '22 01:10

Hector Sosa Jr