Back to Watermill

Example Golang CQRS application - ordered events with Kafka

_examples/basic/6-cqrs-ordered-events/README.md

1.5.11.4 KB
Original Source

Example Golang CQRS application - ordered events with Kafka

This application is using Watermill CQRS component.

Detailed documentation for CQRS can be found in Watermill's docs: http://watermill.io/docs/cqrs#usage.

This example, uses event groups to keep order for multiple events. You can read more about them in the Watermill documentation. We are also using Kafka's partitioning keys to increase processing throughput without losing order of events.

What does this application do?

This application manages an email subscription system where users can:

  1. Subscribe to receive emails by providing their email address
  2. Update their email address after subscribing
  3. Unsubscribe from the mailing list

The system maintains:

  • A current list of all active subscribers
  • A timeline of all subscription-related activities

In this example, keeping order of events is crucial. If events won't be ordered, and SubscriberSubscribed would arrive after SubscriberUnsubscribed event, the subscriber will be still subscribed.

Possible improvements

In this example, we are using global events and commands topics. You can consider splitting them into smaller topics, for example, per aggregate type.

Thanks to that, you can scale your application horizontally and increase the throughput and processing less events.

Running

bash
docker-compose up