Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transactions crossing aggregate boundaries

I have the following domain modelling problem where I seem to end up either crossing consistency boundaries or creating a huge aggregate. Can someone help me break it up?

There are two job types JobA, JobB. JobA is composed of tasks TaskA. JobB is composed of tasks TaskB. JobA and JobB are unrelated. The only thing is common between them is that they both need an equipment resource. I had originally wanted to create 5 aggregate roots which may reference each other - JobA will reference TaskA and so on.

Domain model

I can possibly put a job and its tasks in one aggregate. That comes at an expense of introducing other overhead as tasks themselves are complex creatures. However, the following constraints prevent me from using either model.

  1. A job cannot be marked complete if any task is still incomplete. This check causes transactions to cross aggregate boundaries (e.g., TaskA and JobA).
  2. An equipment cannot be assigned to more than 1 job. This check will span across both job aggregates.
  3. Equipment has to be released before job can be marked complete. This transaction will cross equipment and job aggregates.

Having a single aggregate will put all transactions inside the boundary but that will make the aggregate impossibly large. Is there a different model hidden in all this that I am missing?

like image 949
341008 Avatar asked Nov 10 '22 09:11

341008


1 Answers

I think the best solution could be using eventual consistency.

When I have doubts about designing agreggates I always take a look to Effective Agreggate Design by Vaughn Vernon.

like image 90
Josué Pech Avatar answered Dec 16 '22 13:12

Josué Pech