Search code examples
design-patternsarchitecturecqrsevent-sourcing

What is the best way to find an event in an event sourcing?


What is the best way to find an event in an event sourcing? This was a question I had for an architect role recently. I said by event ID, but apparently the answer was wrong. Does anyone knows what is the best way or the most efficient way?


Solution

  • I don't think the interviewer was looking for a straight answer, but more on the analysis process involved executing such an operation. I believe he was expecting back some questions, like:

    • What is the information stored in an event? Does it have some sequence number attached on it, or a timestamp?
    • How are the events stored? They're stored in a multi-node NoSQL DB or in a single-instance relational DB? Are the events indexed by some key?
    • What information I have for the search operation? If I need to search events by their ID (only) and this property is not indexed, then I got no option but going through all of them serially. If I need to search for events in a particular timeframe, then the search area might be significantly reduced.

    Depending on the responses you get back, the discussion would evolve into classical search approaches, like indexing, or binary search, or other options that would reduce the search surface.