Comments (2)
"It Depends",
Yes, avoid dependencies between Projectors (Event Handler) and Processors (Event Handler).
An Event Handler should be as sufficient as possible by itself, since the Event Handler is a linearization factor, otherwise it may be difficult to reason and implement the system.
That means creating a Processor own its Projections as well. The anti-pattern (especially as the system grows) is to use somebody else Projection.
Once again, "It Depends".
from commanded.
Here's some further explanations about this issue and my software design concerns:
I have two aggregates: AggregateA
and AggregateB
.
Both of them have their respective TableA
and TableB
projections, linked by a many-to-many relationship through a TableATableB
join table.
If an instance of AggregateA
is created or updated and therefore its TableA
projection too, the app must either create or delete TableATableB
relationships with TableB
, and vice-versa.
As of now, this workflow is actually done by the event handler of EventA
and the event handler of EventB
:
- When the event handler receives an
EventA
, it queries the database to retrieve allTableB
records usingTableA
and performs a calculation on which relationships should be updated. But because the event handler doesn't have any guarantee thatTableA
has effectively been persisted, it randomly fails.
In order for TableATableB
relationships creation/removal to not depend on an projector and therefore on db inserts, EventA
could carry a list of related TableB
, and its projector would just have to insert both TableA
and related TableAsTableBs
projections in a single transaction, and vice-versa. This also ensures that if any operation fails, the whole transaction will be rolled back.
But if I do that, AggregateB
would have no idea about the relationships stored in the state of AggregateA
, and conversely, if AggregateB
has been commanded to perform the same action from its side, AggregateA
will have no idea about the relationships stored in the state of AggregateB
. This will lead to have up-to-date relationships in the persistence layer but with both aggregate states being out of sync. If one day my requirements are to retrieve the exact value of relationships between AggregateA
and AggregateB
, I'll be in trouble.
How would one deal with it?
This also raises the question of which state should be the source of truth in a relationship between two aggregates, and which events are responsible for updating relationships projections?
from commanded.
Related Issues (20)
- Process manager router option not working
- Lessons learned from performance optimization - an unlikely culprit HOT 3
- no function clause matching in Commanded.Commands.Dispatcher.telemetry_stop/3 HOT 1
- Docs questions
- Stacktrace in event handler error? HOT 2
- Paralelization Strategies in EventHandlers
- Should Commanded.Event.Handler support messages from swarm? HOT 2
- Event retention policies?
- please support multiple commanded application with one eventstore HOT 6
- Process Manager state serialization breaks when using a custom TypeProvider with the JsonSerializer
- `Commanded.ProcessManagers.ProcessManager.identity/0` function returns `nil` in unit tests
- no function clause matching in Commanded.Event.Handler.partition_event/4 HOT 1
- EventstoreDB is sunsetting the TCP protocol HOT 1
- Snapshotting 2 Aggregates having same identity
- Is it possible to log contents of InMemoryEventStore on failed test?
- Ecto Sandbox, Projections and In Memory adapter HOT 3
- Aggregate throws error when execute returns more than 1000 events.
- Individual stream events handling
- Skipped event with concurrency enabled HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from commanded.