Is Using Command Interceptors to Maintain Relationships Between Aggregates an Anti-Pattern?

Thank you so much for your reply @Steven_van_Beelen. I really appreciate the feedback, it’s very helpful. To clarify, the following describes the relationships between the different models (I still have yet to implement the BusinessAccount and all it’s various access controls):

To briefly summarize the core idea of the project, I am trying to create a platform for small businesses to be able to offer loyalty rewards to their customers. The platform will allow users (customers) to have a LoyaltyBank to track their reward points per business they enroll in, and view other businesses local to them that they may want to participate in.

As such, the LoyaltyBank establishes a relationship between an Account and Business. This is part of the reason why I didn’t initially create the LoyaltyBank as an aggregate member of the Account because it really “belongs” to both and I having either the Account or the Business didn’t really feel right to be a third level aggregate member on the LoyaltyBank. Knowing this, do you still think it makes sense to have the LoyaltyBank as an aggregate member on the Account? Also I’ve since removed the requirement for a business name to be unique and have been keeping track of them through an businessId just in case two businesses happen to have the same name.

In general, I really like how the interceptors and command projections work together to “guard” the aggregates from processing an invalid command, my main concern is if there are any negative performance implications or things that I should be looking out for as the project scales, or if I introduce multiple instances of the command API? Does it make sense to persist those projections into the same database as my event store, or should I try and use something that is known to be a little faster like a Redis Cache maybe?

If you or anyone else has any additional insights, that would be greatly appreciated. I must say, working with Axon Framework has been one of, if not the, most enjoyable experiences I’ve had in developing software thus far.

Thank you again for your reply @Steven_van_Beelen, and for all your contributions to this amazing community.

1 Like