Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event handler concurrency #184

Open
slashdotdash opened this issue Jul 30, 2018 · 3 comments
Open

Event handler concurrency #184

slashdotdash opened this issue Jul 30, 2018 · 3 comments
Assignees

Comments

@slashdotdash
Copy link
Member

@slashdotdash slashdotdash commented Jul 30, 2018

Allow event handlers to specify how many processes are started to allow handling events concurrently.

The behaviour is similar to Greg's Event Store which uses the competing consumer pattern. Increasing the concurrency means the event ordering guarantee is lost since events will be handled out-of-order. To alleviate this issue an optional partitioning function may be provided to ensure events are processed in order where necessary (e.g. per aggregate identity).

defmodule ExampleHandler do
  use Commanded.Event.Handler, 
    name: "ExampleHandler", 
    concurrency: 10, 
    partition_by: fn _event, metadata -> metadata.stream_id end

  def handle(_event, _metadata) do
    :ok
  end
end

This feature depends upon Subscription concurrency (#124) to be implemented in the Elixir Event Store. Greg's Event Store already has support for concurrency.

@Aleksion
Copy link
Contributor

@Aleksion Aleksion commented Aug 12, 2018

This would be great - especially in situations where concurrency doesn't matter.

@Freyskeyd
Copy link
Collaborator

@Freyskeyd Freyskeyd commented Jan 28, 2019

The concurrency parameter can be obscure.

Does it represent the maximum of events handled at the same time?
Does it represent the maximum event handler count for this kind of event handler?
Does it represent the number of event handler started by default?

The partition_by function is called to dispatch the event to the right event handler instance ? What's the default behaviour?

@slashdotdash
Copy link
Member Author

@slashdotdash slashdotdash commented Jan 28, 2019

  • concurrency - How many event handler processes are started.
  • partition_by - How to distribute events to running event handler processes. By default events will be distributed using a round-robbin strategy for even load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants