Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Su1999's avatar

Avoid concurrency in running tasks for each user in a laravel queue

Hello guys!

I get calls from a webhook that dispatches multiple tasks related to the same user, and 3 workers in total process those tasks. The problem is that a user's task cannot be processed while another task assigned to this same user is already running by one of the workers.

Scenario:

User A: task 1, task 2

User B: task 1, task 2

Task 2 of user A can only start when task 1 of this same user is completed. This is because task 1 performs several updates to Firebase and running it by different workers at the same time may overwrite the data. However, while this "wait" occurs, user B's tasks will be executed by another worker using the same concurrency limitation.

I even tried using uniqueId to assign a user to tasks, but at the time of dispatch if there is a task for the same ID the second one is deleted instead of being postponed or put on hold until the next one is finished. The dispatches of each task (independent of the user) are triggered by webhook calls, that is, at different times.

0 likes
2 replies
Su1999's avatar

@martinbean Thank you very much! This solution was the correct one for my problem.

1 like

Please or to participate in this conversation.