From what I've read online an Aggregate when loaded from the database must be in the complete state. Meaning it must have access to all the entities inside of it also loaded from the database so that the aggregate is never in an invalid/incomplete state.
What if the aggregate contains an entity of which there can be millions of for eg. Aggregate A contains Entity B and Entity C. Now worst case scenario there can be upto 100 Entity B instances under the Aggregate A but there can be millions (if not billions) of Entity C under Aggregate A.
The Use Case:
The use case would be that I want to remove one particular instance of Entity C from Aggregate A using an Id. To do this in the DDD fashion I would have to first load up the Aggregate A from the database and load all it's Entities into memory. and then remove the item maybe by using a method like below:
public class AggregateA extends AbstractAggregateRoot<AggregateA>{
private String aggregateId;
private Map<String, EntityC> entityC;
public void removeEntityC(String idToRemove) {
this.entityC.remove(idToRemove);
registerEvent(new EntityCRemoved(aggregateId, idToRemove));
}
}
The question:
Loading up millions of entities into memory to perform any Write Operation (Command in CQRS) for a single request doesn't seem the right way.
Am I missing something here?