chirag04 / mail-listener2

Mail listener library for node.js. Get notification when new email arrived.
MIT License
245 stars 116 forks source link

Multiple Instances #11

Closed ghost closed 10 years ago

ghost commented 10 years ago

This is off topic but still little help would be appreciated.

We are running multiple Beanstalk instances of our app and the imap listener(of all instances) fire when a new mail arrives.

This is resulting in a race condition.

Ideally, we want load balancing to get in action.

Any thoughts ?

pwldp commented 10 years ago

I think one of imap-listener should be active. Switch to another instance when active is deactivated. Establish some communications between imap-listeners to determine which should handle new message from imap server.

chirag04 commented 10 years ago

Do you really want multiple instances of mail listener? Are the volumes so high?

Anyways, I see the problem. Below are few approaches which you can use:

1) Use redis as load balancer Maintain a list of mails to be processed in redis. Use BRPOPLPUSH to load balance between instances of mail-listener. Use LREM to avoid duplicates in the list of mails.

2) Use some database: Maintain a list of mails to be processed in db. Query db periodically and process them one by one. Change the status of processed mails or delete the mail from the list.

Let me know how you go about this.

chirag04 commented 10 years ago

closing for inactivity.