title: Does Laravel Queue prevent duplicate records inserted by concurrent requests?
body: <p>We have a Laravel API with a MariaDB database where we are having the issue of duplicate records in the database that are created by concurrent requests. </p>
  
  <p>We assumed that implementing a queue would solve this, by handling one request at a time. 
  But we still have the same issue of duplicate records. </p>
  
  <p>In the application we have a check that looks for duplicates, but of course that won't work for concurrent requests that will create the same record at the same time. </p>
  
  <p>We are unable to use a unique constraint at database level, partially because of Laravel's soft delete mechanism, and partially because of complex business logic that should allow duplicates if the value of one of the fields matches a certain set of values. </p>
  
  <p>We use Redis as the queue driver. </p>
  
  <p>Are we wrong by thinking that the queue should prevent these issues? 
  Or did we somehow made a mistake somewhere implementing the queue? </p>
  
  <p>This is a simplified version of the controller: </p>
  
  <pre><code>class CreateRecordJob extends Job implements SelfHandling
  {
  
      public function __construct(array $data)
      {
          $this-&gt;data = $data;
      }
  
      public function handle()
      {
          $data = $this-&gt;data;
  
          // check if we have this record in the database already
          if(!$this-&gt;hasDuplicate($data)) {
              $this-&gt;createRecord();
          }
      }
  }
  </code></pre>
  
  <p>In config/queue.php we have set Redis as the default queue driver: </p>
  
  <pre><code>'default' =&gt; env('QUEUE_DRIVER', 'redis'),
  </code></pre>
  
  <p>And also in config/queue.php we have this for the redis connection: </p>
  
  <pre><code>'redis' =&gt; [
      'driver'     =&gt; 'redis',
      'connection' =&gt; 'default',
      'queue'      =&gt; 'default',
      'expire'     =&gt; 60,
  ],
  </code></pre>