CQRS in the event sourced world
We know from our work in Chapter 4, Making History with Event Sourcing, that an event-sourced app is all about commands (actions) and events (reactions to those commands). The events that are generated from these commands are used to represent the state of a given entity over time, with the past events being replayed whenever the current state of an entity is needed. The storage model itself does not store the current state, only the occurrences that lead to a current state for a particular entity.
Given this model, what can I do if I want to query for a particular entity that has the current state with a field matching a specified value? If I don't store the current state, how can I answer this question? Will I have to read every entity in the system, replay its event stream to get its current state, and then see if it's a match? An approach like that will not be tenable, so let's not even consider it.
One answer to this question is to consider commands and...