performance suggestions on Aggregate root containing thousands of child entities

I understand that DDD is a design concept and implementation through ORMs are tricky but help me understand how would you solve this problem? So here is my confusion on changing on aggregates only though aggregate roots. Given my case(rehashed through JIRA case). I feel this aggregate and DDD feels good about how we modify this and simplifies logic. But my question is performance. Just to add a comment to a sub-task we are loading en entire aggregate root into memory. How can this be efficient? So we have for example An aggregate root Epics which contains Story and that contains sub-tasks. Lets assume For 1 Epic there could be about 1000 Stories and for each of the Stories there could be 10000 sub-tasks Now if i want to add a comment to a sub-task or add a comment to story I need to do this Put Request api/lates/epics/{epicid}/stories/{storyid}/subtask/{subtaskid}/comment api/lates/epics/{epicid}/stories/{storyid}/comment Implement EpicModificationController @Autowired EpicModificationService epicModificationService; ........ EpicID epicId = new EpicID(long) StoryId storyId = new StoryID(long) SubtaskId subtaskId = new SubtaskID(long) Comment comment = new Comment("comment text") ....... epicModificationService.addSubtaskComment(epicID, storyId, subtaskId, comment) EpicModificationService Epic epic = epicRepository.findOne(epicId); epic.addSubtaskComment(storyId, subtaskId, comment); epicRepository.saveandflush(epic); Domain Entity @Entity class Epic { addSubtaskComment(StoryId, SubtaskId, Comment) { Story story = this.getStory(StoryId); Subtask subtask = story.getSubtask(subtaskId) subtask.addComment(Comment); } } I can directly go fetch my subtask through DAO and update it? Sounds to be more performant? I am not there at the level of CQRS + DDD yet as I am yet to understand nuances in DDD itself. There are reasons why my domain model in correct in way because some actions on Stories cannot be done when Epics are in some state. E.g) you cannot edit a story (add subtask, change 'status' etc , comments are ok) when an Epic in closed. [again Epic/story e.g is just a representation of my real case]

Apr 8, 2025 - 01:24
 0
performance suggestions on Aggregate root containing thousands of child entities

I understand that DDD is a design concept and implementation through ORMs are tricky but help me understand how would you solve this problem?

So here is my confusion on changing on aggregates only though aggregate roots. Given my case(rehashed through JIRA case). I feel this aggregate and DDD feels good about how we modify this and simplifies logic.

But my question is performance. Just to add a comment to a sub-task we are loading en entire aggregate root into memory. How can this be efficient?

So we have for example An aggregate root Epics which contains Story and that contains sub-tasks.

Lets assume For 1 Epic there could be about 1000 Stories and for each of the Stories there could be 10000 sub-tasks

Now if i want to add a comment to a sub-task or add a comment to story I need to do this

Put Request

api/lates/epics/{epicid}/stories/{storyid}/subtask/{subtaskid}/comment

api/lates/epics/{epicid}/stories/{storyid}/comment

Implement EpicModificationController

@Autowired
EpicModificationService epicModificationService;
........
EpicID epicId = new EpicID(long)
StoryId storyId = new StoryID(long)
SubtaskId subtaskId = new SubtaskID(long)
Comment comment = new Comment("comment text")
.......
epicModificationService.addSubtaskComment(epicID, storyId, subtaskId, comment)

EpicModificationService

Epic epic = epicRepository.findOne(epicId);
epic.addSubtaskComment(storyId, subtaskId, comment);
epicRepository.saveandflush(epic);

Domain Entity

@Entity
class Epic {

  addSubtaskComment(StoryId, SubtaskId, Comment) {
     Story story = this.getStory(StoryId);
     Subtask subtask = story.getSubtask(subtaskId)
     subtask.addComment(Comment);

  }

}

I can directly go fetch my subtask through DAO and update it?

Sounds to be more performant?

I am not there at the level of CQRS + DDD yet as I am yet to understand nuances in DDD itself.

There are reasons why my domain model in correct in way because some actions on Stories cannot be done when Epics are in some state. E.g) you cannot edit a story (add subtask, change 'status' etc , comments are ok) when an Epic in closed. [again Epic/story e.g is just a representation of my real case]