9

Suppose you've got two aggregates in your bounded context which have some constraints amongst each other. Using DDD these inter aggregate constraints can't be enforced in the same transaction i.e. the aggregate boundaries are transactional boundaries.

Would you consider using what in the Microsoft CQRS journey is called a "process manager" to coordinate two aggregates in the same bounded context or is a process manager only used to coordinate between two bounded contexts? What would the equivalent of a process manager that coordinates two or more aggregate roots within the same bounded context be?

1 Answer 1

10

An aggregate root defines a bounded context by default, albeit a lower level one (btw the lowest level bounded context you can find is an object, any object). The process manager is the name they used instead of a saga, proabably you can come up with other names too, it doesn't matter, they all have the same purpose.

And yes, I would consider using a saga to achieve eventual consistency. In fact, I think this is the best way and this is exactly what I'm doing in my own apps. Anyway, I'm using a message driven architecture (yes, in a local, non-distributed application) and I have automatically saga support via the service bus (my own, not released yet).

What is important when dealing with eventual consistency is to ensure idempotency everywhere. That is the aggregate roots should reject a duplicate operation and of course the event handler should be able to cope with the fact that the same event can be published more than once. However, be aware that you can't guarantee 100% idempotency but you can get very close to.

6
  • 1
    +1. Great answer. I wouldn't go as far as saying that an AR defines a BC in itself, but totally agree with everything else. Nov 23, 2012 at 8:30
  • 3
    This is a good answer, but overstates one point. Just to clarify: a bounded context is a model boundary, not an aggregate or object boundary (c.f. pg. 8 of the DDD Reference. Conflating aggregate and object with bounded context is too reductionistic. A model within a bounded context is typically made up of multiple aggregates. Nov 24, 2012 at 0:06
  • 3
    Both an object and an aggregate root (as a facade of an aggregate) define explicit boundaries for some model. Each BC is just a group of smaller BCs. I know that when saying BC, it is about a higher level BC, but even the lowly object matches the bounded context definition. This just proves that the concept of DDD is sound even at the object level. Maybe that's why some people say that DDD is just OOP done right.
    – MikeSW
    Nov 24, 2012 at 9:09
  • Saga is an orchestrator, and if you see your aggregates as bounded contexts, then you would have Orders, Shipping, Payment. Then you will create a saga, which coordinates the process of selling goods in Ecommerce website. Imagine your flow is place order, pay, ship. Now what happens when you can ship to VIP customers without paying, and let them pay after 60 days? What if VIP is who has more than 10 orders, tomorrow Vip is the Visa Gold cald holder, and later on Vip customer who's shipping address is in list of vip countries? Would you grab all that data from 3 bounded context into saga? Mar 4, 2020 at 16:34
  • 1
    Thank you for the point that even a domain, an aggregate, or an everyday object all are a bounded context on some scope. That was the validation I needed. But as @DmitriBodiu said, I would also favour choreography if possible. But thank you for your answer too
    – alaboudi
    Apr 2, 2022 at 21:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.