---
title: "Comment by Jam Yanh on \"When Our Database Got Too Fast\" | Hashnode"
description: "The queue bug is the part I'd love more detail on. What changed in the job-claiming step to stop two workers from reserving the same job? A small before-and-aft"
url: "https://hashnode.com/posts/when-our-database-got-too-fast/6aeaf0b0e6fe2f6082ca27d6/comment/6aeb369296b01eba2b0103f0"
---

[Discussion](https://hashnode.com/posts/when-our-database-got-too-fast/6aeaf0b0e6fe2f6082ca27d6)

Comment [When Our Database Got Too Fast](https://hashnode.com/posts/when-our-database-got-too-fast/6aeaf0b0e6fe2f6082ca27d6)

[Jam Yanh](https://hashnode.com/@danagua)

[Nov 4](https://hashnode.com/posts/when-our-database-got-too-fast/6aeaf0b0e6fe2f6082ca27d6/comment/6aeb369296b01eba2b0103f0)

The queue bug is the part I'd love more detail on. What changed in the job-claiming step to stop two workers from reserving the same job? A small before-and-after example would be useful.

[Guy Warner](https://hashnode.com/@GuyWarner)

[Nov 5](https://hashnode.com/posts/when-our-database-got-too-fast/6aeaf0b0e6fe2f6082ca27d6/comment/6aeb369296b01eba2b0103f0#reply-6aecf572b8b7cb134974590d)

Good question. Short version: atomic locks.

Before: we ran the stock database queue driver with the jobs table in a SingleStore rowstore table. Workers hit table locks, and nodes would lock different rows while only one got returned, so two workers could end up reserving the same job. We first tried loading jobs in random order inside a five minute window. It worked okay, not great.

After: we pulled the queue driver into our own class. When a worker finds the next available job, it takes a Laravel atomic cache lock keyed to that job, queue:worker-{job id} for ten minutes, and only gets the job if the lock succeeds. If another worker already holds it, the job is skipped. The lock releases when the job is deleted or released back.

Full code is in an older post of mine: [guywarner.dev/laravel-queues-simplifying-queue-ma…](https://www.guywarner.dev/laravel-queues-simplifying-queue-management-with-singlestore)
