The concept of Saga needs to be decomposed still in DDD (at least I haven't read an article from DDD community that is complete). From the writings I have the feeling that there are many things that are put under the Saga umbrella that may not map with the concept o "long running business activities".
For instance. Say that you have 3 commands to be executed in parallel, and you want a forth command to be executed once the first three are completed. This is typical control flow in parallel algorithms and it's not necessarily a "long running business process". Some programming languages support logical operators to do this. Some visual workflow solutions (with diagrams) support this kind of operators in their engines and visual languages.
What has baffled the computer scientists for a long time, is how to prove that something is false. For instance, how can we prove that a command wasn't completed in the absence of an exception. It is an NP problem. Negation in languages such Prolog is a process intensive computation. The engineering approach is to define a time interval that when consumed, any non verifiable predicate is considered false until that moment (even though is was not proven as such).
In case of an Purchase Order of the example, the system might cancel the Order out rise alerts for the operator to take action.
Now is this leaked domain logic from the domain model to the environment? Well at least it's a low level implementation of an operator for parallel computation.
The question in my mind is, is it ok to consider this part of the domain model design? I think it can.
Here is what is actually going on in that examples
1. - -> PlaceOrder
2. OrderPlaced -> ReserveSeats
3. SeatsReserved -> PayOrder
4. SeatsReserved and !(OrderPayed) -> UnreserveSeats // need a saga here. Timer for computing the negation.
5. OrderPlaced and !(OrderPlaced and OrderPayed) -> CancelOrder(). // need a saga here. Timer for computing the negation.
As you can see the challenge here more the have not's rather then the have's. That is why a Saga is needed in this case.
So is indeed an operator implemented using a low level technical artifact, a Saga. Yet these artifacts are part of the domain model design. In this case a SAGA is logic.
Hope it clarifies.
Nuno
PS: I omitted the facts correlations for simplification.
What has been discovered is different ways to manage state machines or workflows. I think the goal for this business behavior is to be inside your domain model. If you have a workflow defined outside your domain perhaps that's a smell something is missing in the domain model?
Sagas contain state machines, so do other concepts in programming. Not every state machine is a Saga however. What's being discussed here are not Sagas.
+1. Original definition of sagas (as in this white paper mentioned by Kelly) is about technical approach to manage long running transactions that involve multiple resource managers (e.g. Databases).I think, this original definition has nothing to do with domain driven design.
ok I read this conversation and I am really confused. added to backlog a blog post about "sagas" none of this makes sense to me.
"To amend partial executions, each saga transaction T, should be provided with a com-pensating transaction C, The compensatmg transaction undoes, from a semantic point of view, any of the actions performed by T,, but does not necessarily return the database to the state that existed when the execution of T"
"In other cases, it is the database itself that is naturally partitioned mto relatively independent components, and the actions on each component can be grouped into a saga transaction "
"so that each transaction adds the tracing code to one of the components"
The Saga in DDD adds tracing code by calling commands that in turn adds the so called tracing code (events to the log).