January 16, 2009
@ 07:08 PM
In a post called "Rhino Service Bus: Saga and State" Ayende said
"In a messaging system, a saga orchestrate a set of messages. The main benefit of using a saga is that it allows us to manage the interaction in a stateful manner (easy to think and reason about) while actually working in a distributed and asynchronous environment."

I really don't agree with this definition of a saga. The Saga provides a context for set of messages to allow manging an effort for distributed concensus. It does not "orchestrate" messages (that's what workflows are for) - you can read more on Saga's in an excerpt from my SOA patterns book:  Saga pattern.

Here's the comment I left on Ayende's site:
"What you describe is nice except it isn't a Saga it is more of a workflow. The notion of Saga which is originated from databases relates to the overall coordination of state between the different services - or the context for the whole business process.
In the coffee shop example you use that would be the whole "transaction" from the point the customer orders her coffee until she either gets it or the transaction is canceled (e.g. it took too long and the customer leaves or the coffee shop is out of milk etc.)
Unlike database (or distributed) transaction when/if a saga is aborted the different component of the system might not return to their previous state e.g. if the customer complains that the coffee is not good and gets her money back. the milk is not separated back from the coffee beans and returned to the bottle - rather the coffee cup goes to the trash.

Workflow is one strategy a service can take to handle the long running interaction within a saga. In your case the BristaSaga class (which I think should be BristaWF) orchestrate the internal state transitions depending on the different messages that arrive within the saga. In your case you have a hardcoded workflow - but it is also possible to use a workflow engine for the job.

By the way, in the above example you could also use a statemachine instead of a WF to manage the process "
In another comment Kristofer asked me:

Arnon: I'm not 100% sure of how you distinguish a Saga from a Workflow, could you elaborate some more on this?

A Saga involves a number of underlying workflows?
A Saga might as well contain a number of underlying Sagas?

Isn't it just a question of at what level it is initiated?

If a Saga should represent the whole transaction / business process, then who should handle it? Couldn't it be implemented as a Saga, exactly as Ayende describes it, by the initiating service (in this case the ordering)?, which then also is given the responsibility to handle restoring the total state etc of underlying/involved services if the transaction is aborted? The possibility to restore state does of course depend on what the specific Saga is handling, some processes might not be able to "rollback" completely, it's rather a question of rolling back all involved parties to a known/acceptable state."

The answer is that ,again, Saga is similar to a transaction in the sense that it provides a shared context for an attempt to get a distributed consensus  Unlike a transaction which insures ACID properties. Sagas are not.
The concept of dissipating that shared context, having each party (service) affect whether the saga should be aborted or successful etc. is what I call a saga.
When a saga is aborted the only thing the coordinator can do is pass the status to the participants. Each of the services is responsible to do its best effort to handle the abort (either by rolling back, compensation or whatever)

Workflow is another thing altogether. which keeps a context between calls and means externalizing the decisions on the logic flow from the business logic (usually with a workflow engine). You can use workflows within a service (a pattern I call workflodize) or you can use them externally (a pattern I call orchestrated choreography e.g. BPM)
You can use either form of workflow to support the implementation of a saga but you can also implement sagas without workflows.
In our system we use an "event broker" (see www.rgoarchitects.com/.../EventingInWCF.aspx) the event broker infrastructure dissipates the saga context when you raise a saga event. A service that initialized a saga (by sending the first event) can choose to close the saga (commit) or abort it. etc. We don't currently have any workflow driven services (but some of them use a state machine as an alternative)

(I think the term Saga does not describe Ayende's class since the "barista" is just on of the participants in the saga there are other participants.)

Powered by ScribeFire.


 
Sunday, January 18, 2009 9:26:27 AM (GMT Standard Time, UTC+00:00)
This is the Saga definition I posted as a comment on the same Ayende post:

"My understanding of sagas has always been from the perspective of long-lived transactions (LLT) and typically those running / orchestrated across multiple enterprises within some supply / value chain. That the [various] transactions and compensating transactions within each enterprise involved in an LLT are 'bundled' into a saga which is bound to an LLT by some mechanism. The idea essentially being that each saga is responsible for maintaining the consistency of its [component] state thereby contributing to the consistency of the parent LLT state. But after all this discussion I can now see this saga pattern / notion exhibits somewhat of a 'fractal' characteristic relative to its application at various scales both within and across enterprises."

I do like the concept of "dissipating that shared context" and your thoughts on services and events are interesting as well - I'll definitely have to give that one a look and lot more thought. Thanks...
Sunday, January 18, 2009 10:43:55 AM (GMT Standard Time, UTC+00:00)
Personally, I don't like the term Long Lived Transaction since the distributed manner makes it very different from transactions.
It is about distributed conscensus but it doesn't have the pretance that a distributed transaction has.
The Saga term send out the message of "long-running" and that the conversation is related - which is why I like it better

Arnon
Monday, January 19, 2009 10:50:23 PM (GMT Standard Time, UTC+00:00)
I think if you're going to use the term Saga to describe both the overarching multi-enterprise consensus / conversation / orchestration and also the 'bundling' of transactions and counter-transactions within each enterprise, then I'd say the 'fractal' nature of Saga scoping and state management is an essential aspect of the pattern. But I personally would prefer it if 'Saga' were confined within a single enterprise and another term used
Monday, January 19, 2009 10:51:46 PM (GMT Standard Time, UTC+00:00)
...for the conversation across multiple enterprises.
Tuesday, January 20, 2009 10:15:44 PM (GMT Standard Time, UTC+00:00)
I don't think a different term is suitable for the cases - because, the way I see it, you can't really tell the difference.
SOA means reduced assumptions and if you start off with something working "internally" that doesn't mean it will stay that way it can change and in many cases it will.

I don't think that Sagas include handling the orchestration both in the wider (cross-service) sense and the narrower internal workflow sense. It just handles coordinating the context so that the different parties can get to a consensus (and that's enough of a problem as it stands) Note that is isn't "absolute" consensus that transactions seek (which is why I referred to it as shared context)

Arnon
Thursday, January 22, 2009 9:49:55 AM (GMT Standard Time, UTC+00:00)
I do see your point relative to "not being able to tell the difference" relative to that 'fractal' nature of it looking the same at different scales. Where I think it does start to differentiate is once that 'scale' backs out to the point it crosses 'domain' / enterprise boundaries. I still can't quite give up my perception of Sagas as that bundle of transactions and counter-transactions which always resolve to specific state or outcome within some well-bounded context.

That, as opposed to the broader, multi-enterprise scale where I very much agree with you the imperative is not necessarily on seeking some "absolute" resolution - that resolving to one or more 'good enough' outcomes may be acceptable or even necessary. It might also be a case where a 'good enough' resolution is 'committed' by everyone involved, but with one or more parties disagreeing with that outcome and filing an 'appeal' for [later] third party adjudication of some form. Naming this outer scope / scale is where we all seem to run afoul of our own particular vantage points, perceptions, and biases.

Again, I do like your notions of 'dissipating' and framing the goal as a multi-party 'consensus'. That is quite apt given how difficult, if not impossible, it is to specify all potential transactional outcomes within and across extended supply chains - and it does a good job at conveying the [conversational] messaging nature of the discourse as you point out. So - Saga, LTT, ACTA, etc. - at this point I think agreeing on, and sharing, these ideas you are putting out there is more important than sharing a naming convention.
Comments are closed.