Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • In this hypothetical example, if a Chat was deleted, I would fire off a domain event which would eventually lead to consistency w.r.t. messages being deleted. I wouldn't necessarily consider Message and independent aggregate root because it has to contain a chat My principal understanding is that the Message should indeed be an aggregate root because the number of messages could grow out of bound. Following the logic of Vaughn Vernon's principals of effective aggregate design, a message should be an aggregate root in order to avoid the problems of modeling as an entity. Commented Jan 4, 2021 at 15:06
  • Yes, you could fire a domain event. Meanwhile your Chat is deleted, but some messages are still there. If you are in the same database, you'd again be inconsistent with your schema (i.e. that a component of the key relates to your chat). You could still argue that your chat component in the key does not need to be an integrity controlled foreign key. My point here was not to claim that it is impossible. It's just to highlight that low-level design (composite-key) would contradicts high-level intent (independent aggregates) and that it is therefore not a good practice :-) Commented Jan 4, 2021 at 15:16
  • Moreover, what are the benefits? You'd perhaps save 16 bytes per messages (i.e. the key component that you would be at the same time the chat reference). But you'll need a second component to have your full id (e.g. an integer: you would have to ensure uniqueness within the chat, whereas many participants may create a new messages for the same chat at the same time. How would you achieve this uniqueness? storing a counter on the chat (and the argument of the unit of consistency would be back like a bomerang)? Or go for an additional GUID (and then you'd have a plain Id anyway)? Commented Jan 4, 2021 at 15:28