I have an event sourced system that is complemented with CQRS patterns. Every command that is issued to the server will re-hydrate my aggregate (a newly initialized aggregate) to the current state with an event stream, assuming the command is valid.
My question is - Why should I re-hydrate my aggregate state every command? Why can't I just keep an aggregate instance per aggregate Id and not worry about re-hydrating every command? In this scenario, I would only re-hydrate events while spinning up the server.
Is there anything wrong with doing this? It would still preserve history of state because events continue to be persisted.
Thanks!
edit: I am snapshotting my aggregate state every n events so I shouldn't have to re-hydrate more than n events every re-hydration. Additionally, I am caching the aggregate state every time a new snapshot is saved to save a request for the state. I am more wondering why even re-hydrate at all if I could just keep a running aggregate instance in memory (per aggregateId).
I agree with @voiceofunreason for almost all cases (speaking from personal experience) that storing\caching the "current" aggregate state is perfectly fine. However, you should be aware that there are some things that you may be missing by doing so:
Point 1 is more important than the others but there are ways around this witout actually rehydrating every time. It is just that rehydrating is a good option in many cases.
Using snapshots alongside events, and rehydrating using snapshots + newer events addresses these problems because: