Skip to content

Commit

Permalink
improve CQRS event groups docs
Browse files Browse the repository at this point in the history
  • Loading branch information
roblaszczak committed Dec 16, 2024
1 parent 9167362 commit e25e8b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion _examples/basic/6-cqrs-ordered-events/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This application is using [Watermill CQRS](http://watermill.io/docs/cqrs) compon

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

This example, uses event groups to maintain order of events. You can read more about them in the [Watermill documentation](https://watermill.io/docs/cqrs/).
This example, uses event groups to keep order for multiple events. You can read more about them in the [Watermill documentation](https://watermill.io/docs/cqrs/).
We are also using Kafka's partitioning keys to increase processing throughput without losing order of events.


Expand Down
15 changes: 8 additions & 7 deletions docs/content/docs/cqrs.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,14 @@ In the scenario, when we have multiple event types on one topic, you have two op
**Key differences between `EventProcessor` and `EventGroupProcessor`:**

1. `EventProcessor`:
- Each handler has its own subscriber
- Each handler has its own subscriber instance
- One handler per event type
- Simple one-to-one matching of events to handlers

2. `EventGroupProcessor`:
- Multiple handlers share a single subscriber
- Can have multiple handlers for the same event type
- Iterates through all handlers in the group
- Message is considered processed if at least one handler processes it
- All handlers in a group receive messages in the same order
- If one handler fails, the message is nacked and will be redelivered to all handlers
- Group of handlers share a single subscriber instance (and one consumer group, if such mechanism is supported)
- One handler group can support multiple event types,
- When message arrives to the topic, Watermill will match it to the handler in the group based on event type

```kroki {type=mermaid}
graph TD
Expand All @@ -166,6 +164,9 @@ graph TD
end
```

**Event Handler groups are helpful, when you have multiple event of different types, and you want to maintain order of events.**
Thanks to using one subscriber instance and consumer group, events will be processed in the order they were sent.

{{< callout context="note" title="Note" icon="outline/info-circle" >}}
It's allowed to have multiple handlers for the same event type in one group, but we recommend to not do that.

Expand Down

0 comments on commit e25e8b4

Please sign in to comment.