Code examples of process managers/sagas?

2,398 views
Skip to first unread message

Esko Luontola

unread,
Nov 2, 2016, 11:09:14 AM11/2/16
to DDD/CQRS
I've been reading about CQRS and Event Sourcing lately, and I plan to try it out by creating a demo application about hotel reservations - that domain should be rich enough to require all tools in the Event Sourcing toolbox (I have experience about the domain through work projects). I want to implement it "without frameworks" (on top of RDBMS) to learn CQRS/ES more deeply. I'll also share it on GitHub as an example application.

I found the article Building an Event Storage [1] useful for understanding how to store the events, and Greg Young's CQRS Class [2] I found useful for understanding how to write aggregate roots and command handlers. They had enough code examples to make the concepts concrete and understandable.

I still need help in understanding how to implement process managers (or sagas) and projections.

Greg Young's CQRS class went through process managers at a far too abstract level, without concrete code, so I'm having a hard time understanding how to implement them. I've understood that process managers can be implemented as aggregate roots, but that description still leaves far too many implementation details open. Some things I'm struggling with: how process managers are created, how events are sent to process managers, how the process manager is persisted etc. etc. I need to see code.

Similarly I'm not yet 100% sure about how to implement projections. The part that wonders me is that how the events make their way from the event store to the projections, and how projections will keep track of which events they have already processed. I suppose there are various options depending on how the event store is implemented.

Do you know about good code examples for implementing process managers? For example a full example application which uses them, or a good concrete article similar to [1]. Ideas for the various ways of implementing projections are also welcome.



Message has been deleted

Nick Chamberlain

unread,
Nov 3, 2016, 8:33:37 AM11/3/16
to DDD/CQRS
As for finding code samples for process managers, Vaughn Vernon has an example done in Scala and Akka that goes along with his book "Reactive Messaging Patterns with the Actor Model" (based on Enterprise Integration Patterns by Gregor Hohpe and Bobby Woolf) here: https://github.com/VaughnVernon/ReactiveMessagingPatterns_ActorModel/blob/master/src/co/vaughnvernon/reactiveenterprise/processmanager/ProcessManager.scala

I ported Vaughn's example to Akka.NET here: https://github.com/heynickc/akka_process_manager.  Meant to write a blog post about it but haven't gotten to it yet.

Whether or not you are using the Actor Model, the example shows a lot of the mechanics of keeping state in Messages like Greg talks about.

Greg Young

unread,
Nov 3, 2016, 8:36:14 AM11/3/16
to ddd...@googlegroups.com
"Similarly I'm not yet 100% sure about how to implement projections.
The part that wonders me is that how the events make their way from
the event store to the projections, and how projections will keep
track of which events they have already processed. I suppose there are
various options depending on how the event store is implemented."

See catchupsubscription then you just remember the last event you
processed (so on a restart etc you can continue from it). Another way
of doing the same thing is with uris over an atom feed (the principle
works in the same way).

"Greg Young's CQRS class went through process managers at a far too
abstract level, without concrete code, so I'm having a hard time
understanding how to implement them."

To be fair I teach another class where we do go through this. Of
course that is an entire 3 day class. Getting that into a 2 hour
period is impossible :)
> --
> You received this message because you are subscribed to the Google Groups
> "DDD/CQRS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to dddcqrs+u...@googlegroups.com.
> Visit this group at https://groups.google.com/group/dddcqrs.
> For more options, visit https://groups.google.com/d/optout.



--
Studying for the Turing test

Esko Luontola

unread,
Nov 3, 2016, 10:17:45 AM11/3/16
to DDD/CQRS
On Thursday, 3 November 2016 14:36:14 UTC+2, Greg Young wrote:

To be fair I teach another class where we do go through this. Of
course that is an entire 3 day class. Getting that into a 2 hour
period is impossible :)

I see you have a two day workshop about process managers at DDD Europe Amsterdam in January. Maybe we'll meet there. :)

Newion

unread,
Nov 4, 2016, 12:19:41 PM11/4/16
to DDD/CQRS

I just published a blog post about process managers in context of CQRS/Event-sourcing: http://pkaczor.blogspot.com/2016/11/reactive-business-processes.html

Pawel
Reply all
Reply to author
Forward
0 new messages