Pepster
Pepster

Reputation: 2166

CQRS where to store statistics that are used by other BC's

In our current application the user needs to be able to see certain statistics in his account. This data comes from different bounded contexts in the form of events. They typically consist of counters, like total distance tracked. Some user-bound stats are used for reports and charts as well. My question is where to store the user-bound stats. Like, are they part of the domain model (User aggregate)? Or are they just a materialised view eventually updated on multiple places?

So to visualize, using materialized views:

                                        /-> [User View updater]
[BC1] --> SomeInterestingToCountEvent1 <
                                        \-> [Report View updater]

                                        /-> [User View updater]
[BC2] --> SomeInterestingToCountEvent2 <
                                        \-> [Report View updater]

Or by having f.e. a Stats value object in user:

[BC1] --> SomeInterestingToCountEvent1 ---> [User Saga: update Stats]
[BC2] --> SomeInterestingToCountEvent2 ---> [User Saga: update Stats]

                                        /-> [User View updater]
[User BC] --> UserStatsUpdatedEvent    <
                                        \-> [Report View updater]

Upvotes: 1

Views: 97

Answers (2)

Alessandro Santini
Alessandro Santini

Reputation: 2003

Materialised views generated and updated by listeners attached to any relevant event.

Upvotes: 1

VoiceOfUnreason
VoiceOfUnreason

Reputation: 57249

In our current application the user needs to be able to see certain statistics in his account. This data comes from different bounded contexts in the form of events.

So you may want to be thinking in terms of composite UIs

My question is where to store the user-bound stats. Like, are they part of the domain model (User aggregate)? Or are they just a materialised view eventually updated on multiple places?

You probably want to be thinking of them as one or more materialized views.

Upvotes: 2

Related Questions