0

Let's say I have a system to which I can upload documents via an API. There are three services:

  • the UploadService - responsible for providing a HTTP endpoint
  • the StorageService - responsible for storing uploaded documents
  • the FileCabinet - responsible for managing a file cabinet (e.g. categories, hierarchy, etc.)

I'm trying to learn more about event-driven architecture, and now I am trying to come up with one.

The UploadService can receive a command UploadCommand and emits a DocumentUploaded event once it created a unique identifier for the uploaded document.

The StorageService listens for the DocumentUploaded event. Once it receives such an event, it creates a StoreDocument command and handles it. The outcome is a DocumentStoredEvent.

The FileCabinet listens also for DocumentUploaded. Once it receives such an event, it updates its state to include the uploaded document. The outcome is a DocumentFiledEvent.

What I don't get is, that when I would try to replay the events of the system, I would get duplicate events, since the services themselves trigger events. Am I missing some concepts here?

3
  • 1
    The concept you’re missing is that event handlers should be idempotent.
    – Rik D
    Mar 19, 2022 at 11:44
  • So events should be idempotent and commands do not have this property? Mar 19, 2022 at 22:00
  • Can you make an example for what you precisely mean by "getting duplicate events" and why that is an issue?
    – Doc Brown
    Mar 26, 2022 at 13:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy