<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jazz P</title>
    <description>The latest articles on DEV Community by Jazz P (@jazzp).</description>
    <link>https://dev.to/jazzp</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F606494%2Fab401bc6-184d-4f09-9eac-312b1da3d256.png</url>
      <title>DEV Community: Jazz P</title>
      <link>https://dev.to/jazzp</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jazzp"/>
    <language>en</language>
    <item>
      <title>Laravel queues in production: 7 mistakes that lose or duplicate jobs</title>
      <dc:creator>Jazz P</dc:creator>
      <pubDate>Wed, 02 Dec 2026 15:50:27 +0000</pubDate>
      <link>https://dev.to/jazzp/laravel-queues-in-production-7-mistakes-that-lose-or-duplicate-jobs-45d8</link>
      <guid>https://dev.to/jazzp/laravel-queues-in-production-7-mistakes-that-lose-or-duplicate-jobs-45d8</guid>
      <description>&lt;p&gt;Queues are one of the best parts of Laravel. You move slow work out of the request, users stop waiting, and the app feels fast. Then one day an invoice email goes out twice, a report never arrives, or a job runs against data that isn't there yet. Nothing in the logs looks wrong.&lt;/p&gt;

&lt;p&gt;Almost every queue problem we've had to untangle came from a short list of mistakes. Here they are, with the fix for each. Code follows the Laravel 13 queue docs; where Laravel 12 differs, it's noted.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The queue isn't actually a queue
&lt;/h2&gt;

&lt;p&gt;If &lt;code&gt;QUEUE_CONNECTION&lt;/code&gt; is &lt;code&gt;sync&lt;/code&gt;, Laravel runs every dispatched job immediately, inside the request. Nothing breaks, so nobody notices. Pages are just slow, and a failing job throws an error at the user.&lt;/p&gt;

&lt;p&gt;Check your production &lt;code&gt;.env&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;QUEUE_CONNECTION=redis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;sync&lt;/code&gt; is fine in local development and tests. In production, use &lt;code&gt;redis&lt;/code&gt;, &lt;code&gt;database&lt;/code&gt; or &lt;code&gt;sqs&lt;/code&gt;, and make sure a worker is running to process it.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Workers run old code after a deploy
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;queue:work&lt;/code&gt; boots your app once and keeps it in memory. After you deploy, the workers carry on with the code they started with until they restart. That's how a bug you fixed this morning keeps happening this afternoon.&lt;/p&gt;

&lt;p&gt;Add this to every deploy, after the new code is in place:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan queue:restart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It tells workers to exit after their current job. Something has to bring them back up, which is what Supervisor is for. This is the config from the Laravel docs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="k"&gt;[program:laravel-worker]&lt;/span&gt;
&lt;span class="na"&gt;process_name&lt;/span&gt;&lt;span class="o"&gt;=%&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;program_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;s_&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;process_num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="mi"&gt;02d&lt;/span&gt;
&lt;span class="na"&gt;command&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;home&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;forge&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;artisan&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;work&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;sleep&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;tries&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nb"&gt;max&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3600&lt;/span&gt;
&lt;span class="na"&gt;autostart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;autorestart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;stopasgroup&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;killasgroup&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;forge&lt;/span&gt;
&lt;span class="na"&gt;numprocs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;
&lt;span class="na"&gt;redirect_stderr&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;stdout_logfile&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="n"&gt;home&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;forge&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;worker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;
&lt;span class="na"&gt;stopwaitsecs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3600&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set &lt;code&gt;stopwaitsecs&lt;/code&gt; higher than your longest job takes. Otherwise Supervisor can kill a job halfway through when it stops a worker.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. &lt;code&gt;--timeout&lt;/code&gt; is longer than &lt;code&gt;retry_after&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;This one causes duplicate jobs, and it's easy to miss. Two different settings control time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--timeout&lt;/code&gt; on the worker (60 seconds by default): how long a job may run before the worker kills it.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;retry_after&lt;/code&gt; on the queue connection in &lt;code&gt;config/queue.php&lt;/code&gt; (90 by default): how long the queue waits before it assumes a job is lost and hands it to another worker.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If a job can run longer than &lt;code&gt;retry_after&lt;/code&gt;, a second worker picks it up while the first is still working. Both finish. The customer gets two emails.&lt;/p&gt;

&lt;p&gt;The docs put it plainly: &lt;code&gt;--timeout&lt;/code&gt; should always be at least several seconds shorter than &lt;code&gt;retry_after&lt;/code&gt;. If you have a job that needs five minutes, raise both, and keep the gap.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. The job runs before the data exists
&lt;/h2&gt;

&lt;p&gt;You create an order inside a database transaction and dispatch a job to process it. The worker is fast, picks up the job before the transaction commits, looks for the order, and can't find it.&lt;/p&gt;

&lt;p&gt;Tell Laravel to wait for the commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="no"&gt;DB&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;transaction&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nc"&gt;ProcessOrder&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;afterCommit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or set &lt;code&gt;'after_commit' =&amp;gt; true&lt;/code&gt; on the queue connection in &lt;code&gt;config/queue.php&lt;/code&gt; so every job dispatched inside a transaction waits by default. If the transaction rolls back, the job is never sent at all, which is usually what you want.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Jobs fail once and are gone
&lt;/h2&gt;

&lt;p&gt;A third-party API times out for ten seconds and every job that hit it in those ten seconds is marked failed. Give jobs room to retry, with a delay that grows each time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Contracts&lt;/span&gt;\&lt;span class="nc"&gt;Queue&lt;/span&gt;\&lt;span class="nc"&gt;ShouldQueue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Foundation&lt;/span&gt;\&lt;span class="nc"&gt;Queue&lt;/span&gt;\&lt;span class="nc"&gt;Queueable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Queue&lt;/span&gt;\&lt;span class="nc"&gt;Attributes&lt;/span&gt;\&lt;span class="nc"&gt;Backoff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Queue&lt;/span&gt;\&lt;span class="nc"&gt;Attributes&lt;/span&gt;\&lt;span class="nc"&gt;Tries&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Throwable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;#[Tries(3)]&lt;/span&gt;
&lt;span class="c1"&gt;#[Backoff([10, 60, 300])]&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SyncInvoiceToAccounting&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;ShouldQueue&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Queueable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Invoice&lt;/span&gt; &lt;span class="nv"&gt;$invoice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// call the accounting API&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;failed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="nc"&gt;Throwable&lt;/span&gt; &lt;span class="nv"&gt;$exception&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// tell someone: log it, alert the team, flag the invoice&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On Laravel 12, use the &lt;code&gt;public $tries = 3;&lt;/code&gt; and &lt;code&gt;public $backoff = [10, 60, 300];&lt;/code&gt; properties instead of the attributes.&lt;/p&gt;

&lt;p&gt;Failed jobs land in the &lt;code&gt;failed_jobs&lt;/code&gt; table. Look at them. &lt;code&gt;php artisan queue:failed&lt;/code&gt; lists them, and &lt;code&gt;php artisan queue:retry all&lt;/code&gt; sends them back once the cause is fixed. A failed-jobs table that nobody reads is the same as losing the work.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. The same job runs twice at the same time
&lt;/h2&gt;

&lt;p&gt;Retries, double-clicks and scheduled tasks all create duplicates. Two copies of "recalculate this account's balance" running at once is how numbers drift.&lt;/p&gt;

&lt;p&gt;Laravel gives you two tools. If only one copy of a job should ever be waiting in the queue, implement &lt;code&gt;ShouldBeUnique&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Contracts&lt;/span&gt;\&lt;span class="nc"&gt;Queue&lt;/span&gt;\&lt;span class="nc"&gt;ShouldBeUnique&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;RecalculateBalance&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;ShouldQueue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ShouldBeUnique&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Queueable&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Account&lt;/span&gt; &lt;span class="nv"&gt;$account&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;uniqueId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;account&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unique jobs need a cache driver that supports locks (Redis, Memcached, DynamoDB, database, file or array).&lt;/p&gt;

&lt;p&gt;If duplicates may queue up but must not run at the same moment, use the &lt;code&gt;WithoutOverlapping&lt;/code&gt; middleware instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate&lt;/span&gt;\&lt;span class="nc"&gt;Queue&lt;/span&gt;\&lt;span class="nc"&gt;Middleware&lt;/span&gt;\&lt;span class="nc"&gt;WithoutOverlapping&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;middleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;WithoutOverlapping&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;account&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Neither replaces writing jobs that are safe to run twice. Check whether the work is already done before doing it, and you're protected even when something slips through.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Nobody notices the queue is backing up
&lt;/h2&gt;

&lt;p&gt;Workers crash, Redis fills up, a slow job blocks everything behind it. Users notice before you do.&lt;/p&gt;

&lt;p&gt;Laravel can watch queue size for you. Schedule this to run every minute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan queue:monitor redis:default --max=100
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the queue holds more than 100 jobs, Laravel fires a &lt;code&gt;QueueBusy&lt;/code&gt; event. Listen for it and send yourself a message. If you run Redis queues, Laravel Horizon adds a dashboard with throughput, wait times and failed jobs, and it handles the worker processes too.&lt;/p&gt;

&lt;h2&gt;
  
  
  A short checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;QUEUE_CONNECTION&lt;/code&gt; isn't &lt;code&gt;sync&lt;/code&gt; in production&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;queue:restart&lt;/code&gt; runs on every deploy; Supervisor restarts workers&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--timeout&lt;/code&gt; is several seconds shorter than &lt;code&gt;retry_after&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Jobs dispatched inside transactions use &lt;code&gt;afterCommit()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Jobs have tries, backoff and a &lt;code&gt;failed()&lt;/code&gt; method; someone reads &lt;code&gt;failed_jobs&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Jobs that must not double up use &lt;code&gt;ShouldBeUnique&lt;/code&gt; or &lt;code&gt;WithoutOverlapping&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Queue size is monitored and alerts someone&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The full details are in the &lt;a href="https://laravel.com/docs/13.x/queues" rel="noopener noreferrer"&gt;Laravel queue documentation&lt;/a&gt;, which is one of the better-written parts of the docs.&lt;/p&gt;

&lt;p&gt;This is the list our team goes through whenever we take over a Laravel app with "random" queue problems. If you need help with that kind of work, you can &lt;a href="https://www.echoinnovateit.com/hire-laravel-developer" rel="noopener noreferrer"&gt;hire Laravel developers from our team&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclosure: I work at EchoInnovate IT, a software development company with teams in the USA and India.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Which of these has caught you out? I'd like to hear about it in the comments.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>webdev</category>
      <category>backend</category>
    </item>
    <item>
      <title>Why your Node.js API slows down under load (and the 6 fixes we reach for first)</title>
      <dc:creator>Jazz P</dc:creator>
      <pubDate>Tue, 01 Dec 2026 12:24:09 +0000</pubDate>
      <link>https://dev.to/jazzp/why-your-nodejs-api-slows-down-under-load-and-the-6-fixes-we-reach-for-first-19lg</link>
      <guid>https://dev.to/jazzp/why-your-nodejs-api-slows-down-under-load-and-the-6-fixes-we-reach-for-first-19lg</guid>
      <description>&lt;p&gt;Most Node.js APIs feel fast in development and on launch day. Then traffic grows, p95 latency creeps up, and somebody suggests "just add more servers". Sometimes that helps. Often it doesn't, because the problem is not the number of servers. It is one thing blocking the event loop, or one slow dependency that every request waits on.&lt;/p&gt;

&lt;p&gt;Here are the checks and fixes we use first when a Node.js API starts struggling. None of them need a rewrite.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Measure event loop delay before you guess
&lt;/h2&gt;

&lt;p&gt;Node runs your JavaScript on one main thread. If one request does heavy synchronous work, every other request waits. CPU charts won't always show this, so measure the event loop directly. Node ships a histogram for exactly this in &lt;code&gt;perf_hooks&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;monitorEventLoopDelay&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'node:perf_hooks'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;monitorEventLoopDelay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;resolution&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nb"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// values are in nanoseconds&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;p50ms&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;percentile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;1e6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;p99ms&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;percentile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;99&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;1e6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;maxms&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;max&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;1e6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10_000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If p99 delay sits in the tens or hundreds of milliseconds, something synchronous is hogging the thread. Typical culprits are large &lt;code&gt;JSON.parse&lt;/code&gt;/&lt;code&gt;JSON.stringify&lt;/code&gt; calls, synchronous crypto, big regexes, image work, and loops over thousands of records inside a request handler.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Move CPU-heavy work off the main thread
&lt;/h2&gt;

&lt;p&gt;Once you know what blocks, move it. For CPU-bound jobs inside the same process, &lt;code&gt;worker_threads&lt;/code&gt; keeps the event loop free:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Worker&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'node:worker_threads'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;runReport&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Worker&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'./report-worker.js'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;workerData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;once&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'message'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;once&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'error'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In production, use a small worker pool (for example Piscina) rather than creating a worker per request. If the work doesn't need to finish before you respond, the next fix is usually better.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Put slow work in a queue
&lt;/h2&gt;

&lt;p&gt;Sending emails, generating PDFs, calling a slow third-party API, resizing images: none of these need to happen while the user waits. Accept the request, put a job on a queue, return &lt;code&gt;202 Accepted&lt;/code&gt;, and let workers handle it.&lt;/p&gt;

&lt;p&gt;With &lt;a href="https://docs.bullmq.io/" rel="noopener noreferrer"&gt;BullMQ&lt;/a&gt; and Redis, the producer side is short:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;Queue&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'bullmq'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;reports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Queue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'reports'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'redis'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;6379&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/reports'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;reports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'build'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;attempts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;backoff&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'exponential'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;202&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;jobId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You also get retries and a clear view of what failed, instead of losing work when a request times out.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Size your database pool and set timeouts
&lt;/h2&gt;

&lt;p&gt;A very common cause of "random" slowness is requests queueing for a database connection. With &lt;a href="https://node-postgres.com/apis/pool" rel="noopener noreferrer"&gt;&lt;code&gt;pg&lt;/code&gt;&lt;/a&gt;, the default pool size is 10. Under load, request number 11 waits until a connection frees up. And if a query hangs, it holds that connection indefinitely.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pg&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'pg'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;pool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;pg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Pool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                       &lt;span class="c1"&gt;// match what your DB can actually handle&lt;/span&gt;
  &lt;span class="n"&gt;idleTimeoutMillis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30_000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;connectionTimeoutMillis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2_000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// fail fast instead of queueing forever&lt;/span&gt;
  &lt;span class="n"&gt;statement_timeout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5_000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;       &lt;span class="c1"&gt;// kill runaway queries&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Raise &lt;code&gt;max&lt;/code&gt; only after checking the database's own connection limit, and remember it is per process. Four instances with &lt;code&gt;max: 20&lt;/code&gt; means up to 80 connections.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Cache the reads that don't change every second
&lt;/h2&gt;

&lt;p&gt;Many APIs answer the same question thousands of times: a product list, a settings object, a user's permissions. A short-lived Redis cache in front of those reads takes load off the database and makes responses predictable (this example uses the ioredis client):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getProduct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`product:${id}`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;hit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'SELECT * FROM products WHERE id = $1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'EX'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep the TTL short at first and add explicit invalidation on writes. A stale cache is a worse bug than a slow endpoint.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Put timeouts on every outbound call
&lt;/h2&gt;

&lt;p&gt;If your API calls another service and that service hangs, your requests hang with it. They pile up until memory or connections run out. Node's built-in &lt;code&gt;fetch&lt;/code&gt; accepts an abort signal, so there is no excuse not to set a timeout:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'https://partner.example.com/rates'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;signal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;AbortSignal&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pair that with a sensible fallback (a cached value, a partial response, or a clear error), and one slow partner can no longer take your whole API down.&lt;/p&gt;

&lt;h2&gt;
  
  
  Then scale out
&lt;/h2&gt;

&lt;p&gt;After the event loop is clear, slow work is queued and the pools are sized, adding instances behind a load balancer, or using the &lt;code&gt;cluster&lt;/code&gt; module or your container platform's replicas, actually scales linearly. Before that, you are mostly multiplying the same bottleneck.&lt;/p&gt;

&lt;h2&gt;
  
  
  A short checklist
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Event loop delay p99 is measured and alerting&lt;/li&gt;
&lt;li&gt;No CPU-heavy work in request handlers&lt;/li&gt;
&lt;li&gt;Anything that can wait goes through a queue with retries&lt;/li&gt;
&lt;li&gt;DB pool sized against the database's real limit, with connection and statement timeouts&lt;/li&gt;
&lt;li&gt;Hot reads cached with a short TTL and invalidated on write&lt;/li&gt;
&lt;li&gt;Every outbound HTTP call has a timeout and a fallback&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the checklist our team starts with when we pick up a back end that is struggling under load. If you need extra hands for this kind of work, we have &lt;a href="https://www.echoinnovateit.com/hire-node-js-developer" rel="noopener noreferrer"&gt;Node.js developers available to join your team&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclosure: I work at EchoInnovate IT, a software development company with teams in the USA and India.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;What is the most surprising Node.js bottleneck you've tracked down? I'd like to hear it in the comments.&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>performance</category>
      <category>backend</category>
    </item>
    <item>
      <title>8 Questions to ask while hiring an app developer</title>
      <dc:creator>Jazz P</dc:creator>
      <pubDate>Wed, 31 Mar 2021 11:33:26 +0000</pubDate>
      <link>https://dev.to/jazzp/8-questions-to-ask-while-hiring-an-app-developer-4h59</link>
      <guid>https://dev.to/jazzp/8-questions-to-ask-while-hiring-an-app-developer-4h59</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DDg68yte--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q3v8ct1206sbj1ujcy32.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DDg68yte--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q3v8ct1206sbj1ujcy32.png" alt="Questions To Ask While Hiring An App Developer"&gt;&lt;/a&gt;&lt;br&gt;
With the rise of technology, there is a vast difference in many fields, business processes that have changed for a good reason. Most e-commerce businesses are fast-moving with the help of mobile apps and it is considered integral to the business.&lt;/p&gt;

&lt;p&gt;It is essential to build stronger relationships between the customers and stakeholders. Therefore, developing an app will enhance your business performance. &lt;/p&gt;

&lt;p&gt;For developing the app, you need investment, require enterprise, and finding the right app developer. You may feel frustrated and time-consuming in the process of hiring the right app developer but worth the hassle. &lt;/p&gt;

&lt;h2&gt;
  
  
  Questions To Ask While Hiring App Developer
&lt;/h2&gt;

&lt;p&gt;To &lt;a href="https://echoinnovateit.com/hire-app-developer/"&gt;hire app developer&lt;/a&gt;, it is essential to search and discuss among them. It is a challenging thing to ask what kind of question to be asked at the time of hiring the app developers so you can go by asking questions that revolve around app developers, experience, skills, portfolio, vision, and more. Here are some of the questions that will help you at the time of hiring an app developer.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. What are the app developer’s portfolios?
&lt;/h2&gt;

&lt;p&gt;The candidate you hire must be asked these questions so that you will get a better idea and will come to know about the candidate’s potential to deliver the right app. Thus, you will be able to know about the candidate's potential in-app development by knowing the previous work experience and ability. So, you can analyze the quality of the app.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. What are the past and current projects?
&lt;/h2&gt;

&lt;p&gt;You can ask about the list of current and past clients to whom they have developed the app before and their current ongoing projects. So that you will be able to know the working experience of the candidate and the field they have worked in before. If they are experienced then you can expect a good performing app for business. &lt;/p&gt;

&lt;h2&gt;
  
  
  3. What are the various features they create?
&lt;/h2&gt;

&lt;p&gt;It is essential to provide an app that must turn the customer's attention toward and purchasing of it. You can achieve the attention of the customers or clients by creating innovative and useful features. The features you give in the app must be easy to access by the user and it should be unique. &lt;/p&gt;

&lt;p&gt;The app you create must be of special features then only you can compete with your competitors. So, then it is essential to know whether the candidates can create an innovative app with unique features.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. How to test the app?
&lt;/h2&gt;

&lt;p&gt;Creating an app is generally fine but the crucial part is when it comes to testing the app for the candidate. So, including these kinds of questions while hiring a candidate will help you to understand the capability of the candidate. &lt;/p&gt;

&lt;p&gt;Asking this question will help you to know how the candidate is an expert in testing the app to provide the best and good performing app according to the client's or customer’s needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. How important are the terms and conditions of the app?
&lt;/h2&gt;

&lt;p&gt;This question is one of the mandatory ones to ask the client when they are hiring a candidate because every app has distinct features and processing. &lt;/p&gt;

&lt;p&gt;Before using the app, it is important to agree on the terms and conditions of the app, and the client or the user must be aware of it. The proper approval by the app is important because app submission is a long, multi-step process so that the developer must be able to give proper terms and conditions. &lt;/p&gt;

&lt;h2&gt;
  
  
  6. What is the minimum budget need?
&lt;/h2&gt;

&lt;p&gt;This question is one of the essential and important questions to be asked while hiring the candidate because every app differs from one another. &lt;/p&gt;

&lt;p&gt;Estimating an average budget for the app you create will decide the feature and performance of the app. The budgeting part is for the company but it is essential to ask about the average budget the app cost. Want to calculate approximate cost of your app? &lt;a href="https://echoinnovateit.com/app-cost-calculator/"&gt;App cost calculator&lt;/a&gt; can help you with a rough estimation of app development cost.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Have you launched an app by yourself before?
&lt;/h2&gt;

&lt;p&gt;Launching an app generally is a challenging thing because it consists of complex tasks. So, the experience gained in launching the app will help the developers to create the best app according to the client’s needs. Experience in &lt;a href="https://echoinnovateit.com/how-to-launch-an-app/"&gt;launching the app&lt;/a&gt; will have lots of benefits and be very easy to handle by the experienced app developer. &lt;/p&gt;

&lt;h2&gt;
  
  
  8. Who do they support outside?
&lt;/h2&gt;

&lt;p&gt;When it comes to supporting the app developer must provide the best support not only in creating the app but also to support it with the server, web design, marketing branding, and social media.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bottom lines
&lt;/h2&gt;

&lt;p&gt;Therefore, these are some of the questions to be asked while hiring an app developer. In an organization, it is essential to develop an app that will enhance the organization. You can ask these questions while hiring an app developer so you can save time and feel free out of frustration. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Jazz is a Digital Marketer at Echo Innovate IT, Minnesota-based IT solutions provider which is one of the leading software companies and mobile app development companies. She has been a great player in giving Echo innovate IT recognition as a top-notch trusted &lt;a href="https://echoinnovateit.com/iphone-app-development/"&gt;iPhone app development company&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>hireappdeveloper</category>
      <category>appdeveloperquestions</category>
      <category>mobile</category>
      <category>mobileappdevelopers</category>
    </item>
  </channel>
</rss>
