I have a service-based application that uses Amazon SQS with multiple queues and multiple consumers. I am doing this so that I can implement an event-based architecture and decouple all the services, where the different services react to changes in state of other systems. For example:
- Registration Service:
- Emits event 'registration-new' when a new user registers.
- User Service:
- Emits event 'user-updated' when user is updated.
- Search Service:
- Reads from queue 'registration-new' and indexes user in search.
- Reads from queue 'user-updated' and updates user in search.
- Metrics Service:
- Reads from 'registration-new' queue and sends to Mixpanel.
- Reads from queue 'user-updated' and sends to Mixpanel.
I'm having a number of issues:
- A message can be received multiple times when doing polling. I can design a lot of the systems to be idempotent, but for some services (such as the metrics service) that would be much more difficult.
- A message needs to be manually deleted from the queue in SQS. I have thought of implementing a "message-handling-service" that handles the deletion of messages when all the services have received them (each service would emit a 'message-acknowledged' event after handling a message).
I guess my question is this: what patterns should I use to ensure that I can have multiple consumers for a single queue in SQS, while ensuring that the messages also get delivered and deleted reliably. Thank you for your help.