hanami / events

[Experimental] Events framework for Hanami
MIT License
43 stars 7 forks source link

Drop redis pub sub and use lists instead #30

Closed davydovanton closed 7 years ago

jodosha commented 7 years ago

@davydovanton Can you please explain the reason of this?

davydovanton commented 7 years ago

Of course!

I see two different problems with redis pub-sub.

The first: event persistence

Imagin situation: we have one instance with broadcaster and one with a subscriber. If an instance with subscriber will down, we lose all events which will broadcast at this time.

With redis list, we can save all events in one place and process it at any time

The second: call event only one time

Imagin situation: we have one instance with broadcaster and two with a subscriber. We broadcast user.created event and all instances get it and process. In this case, we'll send notifications to user two or more times. Other examples: we broadcast order.refund event and our order will refund two or more times, and we lost money or something else.

Redis list has atomic push and pull. It's mean that only one instance can get event and process it.

jodosha commented 7 years ago

@davydovanton Thanks for the quick reply.

  1. Is this somehow related to #32 ?
  2. Do you plan to use https://redis.io/commands/rpoplpush#pattern-reliable-queue ?
davydovanton commented 7 years ago

@jodosha

  1. yep
  2. you're right. Sidekiq use it for working with queue. And I think that we should use it too