3

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.

  • Is there any chance that the job will be processed more than once?
  • 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).

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

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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).

Just configure each server to use its own SQS queue - rather than sharing the same one. That way you know 100% that the server that pushed the job is the one that will process it.

You can do this via your .env config file on each server.

Comments

0

Not true, once the job has been removed (retreived) from any one of the servers, it is immediately removed from the aws sqs queue, therefor the job in the queue wouldnt run more than once.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.