laravelamazon-web-servicesamazon-sqs

Laravel multiple servers working with AWS queue


I have laravel application running in two servers (using a load balancer) and I'm wondering what happens if I put a job in a AWS SQS queue and both servers are subscribed to the queue.

Any experience/tips/advice with this kind of setup is appreciated.


Solution

  • Is there any chance that the job will be processed more than once?

    Yes, SQS only guarantees at-least once delivery. You should build your application to allow for multiple copies of a message to be delivered. http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/standard-queues.html#standard-queues-at-least-once-delivery

    Typically the way to solve this is to have a service that can lock on a unique identifier of the message. This way you can restrict the critical section.

    Is there any way to setup things so the same server that put the job in the queue handles the job (think file uploads where the file is stored in disk first).

    As suggested by Laurence, you can have separate queues for each of your instances.