Having N application servers will result in N comments for "Reply by email" messages
The main discussion has moved to https://github.com/tpitale/mail_room/issues/46.
If we have N application servers, we have N mail_room processes watching the single IMAP mailbox, 1 message received N times, N jobs pushed onto the Sidekiq Redis queue, N Sidekiq workers processing the message, and N comments being created.
I don't think it's possible to make it so that a specific message is only handled by one mail_room, since the IMAP inbox isn't a (threadsafe) queue, and doesn't have the locking/atomicity tools to allow it to be coerced into behaving like one.
Solving this on the GitLab side would be doable, if we save the email's Message-ID for a created comment, and add a unique index on the combination of Message-ID and the author, so we don't create two comments for the same message. This would result in a high load on the DB server though, if 48 workers all try to insert the same comment.
@jacobvosmaer and I spent a little while trying to think of ways to solve this using a Redis queue or set, but couldn't come up with a solution that wasn't still likely to have race conditions.
We could of course use Redis to go from 48 messages to be processed to a minimal amount of them (in which case some race conditions would be okay), to greatly diminish the load on Postgres which would still have the unicity constraint in place as a final check, but I wonder if this adds too much complexity for too little gain.