<?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: Kevin Abura</title>
    <description>The latest articles on DEV Community by Kevin Abura (@kevinabura).</description>
    <link>https://dev.to/kevinabura</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3772030%2F208190b4-5808-448d-9702-06c983e8d5c8.png</url>
      <title>DEV Community: Kevin Abura</title>
      <link>https://dev.to/kevinabura</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kevinabura"/>
    <language>en</language>
    <item>
      <title>Your Go Background Jobs Are Silently Failing. Here’s How to Fix It</title>
      <dc:creator>Kevin Abura</dc:creator>
      <pubDate>Wed, 18 Feb 2026 13:45:36 +0000</pubDate>
      <link>https://dev.to/kevinabura/your-go-background-jobs-are-silently-failing-heres-how-to-fix-it-2j1h</link>
      <guid>https://dev.to/kevinabura/your-go-background-jobs-are-silently-failing-heres-how-to-fix-it-2j1h</guid>
      <description>&lt;h1&gt;
  
  
  Why Go Worker Pools Fail in Production
&lt;/h1&gt;

&lt;p&gt;Most Go developers write their first worker pool like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;for&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;range&lt;/span&gt; &lt;span class="n"&gt;jobs&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="n"&gt;handle&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works perfectly in development.&lt;/p&gt;

&lt;p&gt;It survives QA.&lt;/p&gt;

&lt;p&gt;It passes load testing.&lt;/p&gt;

&lt;p&gt;And then production traffic arrives.&lt;/p&gt;

&lt;p&gt;Three weeks later someone is SSH-ing into the server at 3AM.&lt;/p&gt;

&lt;p&gt;This article is about why that happens.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Illusion of Simplicity
&lt;/h2&gt;

&lt;p&gt;Background jobs look simple because concurrency in Go is simple.&lt;/p&gt;

&lt;p&gt;Goroutines are cheap. Channels are elegant.&lt;/p&gt;

&lt;p&gt;So we build async systems quickly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;send emails&lt;/li&gt;
&lt;li&gt;process events&lt;/li&gt;
&lt;li&gt;call third-party APIs&lt;/li&gt;
&lt;li&gt;update caches&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything works — until failure starts happening repeatedly.&lt;/p&gt;

&lt;p&gt;The issue isn't concurrency.&lt;/p&gt;

&lt;p&gt;The issue is &lt;strong&gt;uncontrolled failure behavior&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Failure #1 — Retry Storms
&lt;/h2&gt;

&lt;p&gt;A typical retry implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;process&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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="no"&gt;nil&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks reasonable.&lt;/p&gt;

&lt;p&gt;But in production:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;downstream service slows&lt;/li&gt;
&lt;li&gt;latency increases&lt;/li&gt;
&lt;li&gt;every worker retries&lt;/li&gt;
&lt;li&gt;retries amplify traffic&lt;/li&gt;
&lt;li&gt;database collapses&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your retry mechanism becomes a traffic multiplier.&lt;/p&gt;

&lt;p&gt;You DDoS yourself.&lt;/p&gt;

&lt;h3&gt;
  
  
  What actually happens
&lt;/h3&gt;

&lt;p&gt;100 jobs × 5 retries = 500 operations&lt;br&gt;
But latency increased → workers overlap → concurrency spikes → 2000+ queries&lt;/p&gt;

&lt;p&gt;This is one of the most common real outages in async systems.&lt;/p&gt;


&lt;h2&gt;
  
  
  Failure #2 — Goroutine Leaks
&lt;/h2&gt;

&lt;p&gt;Consider a timeout:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;WithTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&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="n"&gt;Second&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;go&lt;/span&gt; &lt;span class="k"&gt;func&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;doWork&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&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 &lt;code&gt;doWork&lt;/code&gt; ignores context cancellation&lt;br&gt;
the goroutine lives forever.&lt;/p&gt;

&lt;p&gt;Under retries, leaks accumulate.&lt;/p&gt;

&lt;p&gt;Symptoms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;memory slowly rises&lt;/li&gt;
&lt;li&gt;CPU idle but process not healthy&lt;/li&gt;
&lt;li&gt;restart "fixes" it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You didn't fix it.&lt;br&gt;
You drained the leak.&lt;/p&gt;




&lt;h2&gt;
  
  
  Failure #3 — Duplicate Jobs
&lt;/h2&gt;

&lt;p&gt;Service restarts while processing:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;job picked&lt;/li&gt;
&lt;li&gt;process halfway&lt;/li&gt;
&lt;li&gt;server restarts&lt;/li&gt;
&lt;li&gt;job retried&lt;/li&gt;
&lt;li&gt;executed again&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;double charge&lt;/li&gt;
&lt;li&gt;duplicate email&lt;/li&gt;
&lt;li&gt;inconsistent state&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Async systems are not "exactly once"&lt;/p&gt;

&lt;p&gt;They are &lt;strong&gt;at least once&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If your handler is not idempotent, your system is incorrect.&lt;/p&gt;




&lt;h2&gt;
  
  
  Failure #4 — Shutdown Data Loss
&lt;/h2&gt;

&lt;p&gt;Kubernetes sends SIGTERM.&lt;/p&gt;

&lt;p&gt;Your service exits immediately.&lt;/p&gt;

&lt;p&gt;In-flight jobs disappear.&lt;/p&gt;

&lt;p&gt;No error.&lt;br&gt;
No retry.&lt;br&gt;
No log.&lt;/p&gt;

&lt;p&gt;Silent corruption.&lt;/p&gt;

&lt;p&gt;This one is especially dangerous because monitoring does not catch it.&lt;/p&gt;




&lt;h2&gt;
  
  
  Failure #5 — Cache Stampede
&lt;/h2&gt;

&lt;p&gt;Traffic spike:&lt;/p&gt;

&lt;p&gt;1 key expires&lt;br&gt;
1000 workers request same resource&lt;br&gt;
DB melts&lt;/p&gt;

&lt;p&gt;Worker pools amplify stampedes because they parallelize cache misses.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Real Problem
&lt;/h2&gt;

&lt;p&gt;Worker pools optimize throughput.&lt;/p&gt;

&lt;p&gt;Production systems require survival.&lt;/p&gt;

&lt;p&gt;We must design for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;retries without amplification&lt;/li&gt;
&lt;li&gt;bounded concurrency&lt;/li&gt;
&lt;li&gt;idempotent execution&lt;/li&gt;
&lt;li&gt;graceful shutdown&lt;/li&gt;
&lt;li&gt;failure containment&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This changes the architecture completely.&lt;/p&gt;




&lt;h2&gt;
  
  
  What We Changed
&lt;/h2&gt;

&lt;p&gt;After several production incidents, we stopped treating async jobs as "background tasks".&lt;/p&gt;

&lt;p&gt;We started treating them as &lt;strong&gt;state machines under failure&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Key principles:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A job may run multiple times — correctness must hold&lt;/li&gt;
&lt;li&gt;Failure is normal — retry must be controlled&lt;/li&gt;
&lt;li&gt;Shutdown is frequent — tasks must be recoverable&lt;/li&gt;
&lt;li&gt;Downstream is unreliable — backpressure is mandatory&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Reference Implementation
&lt;/h2&gt;

&lt;p&gt;We extracted these patterns into a small Go project:&lt;/p&gt;

&lt;p&gt;CSJD — a production-safe job dispatcher&lt;/p&gt;

&lt;p&gt;It demonstrates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;bounded workers&lt;/li&gt;
&lt;li&gt;duplicate suppression&lt;/li&gt;
&lt;li&gt;controlled retry&lt;/li&gt;
&lt;li&gt;panic recovery&lt;/li&gt;
&lt;li&gt;shutdown draining&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The goal is not performance.&lt;/p&gt;

&lt;p&gt;The goal is preventing 3AM debugging sessions.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thought
&lt;/h2&gt;

&lt;p&gt;Most backend outages are not caused by complex algorithms.&lt;/p&gt;

&lt;p&gt;They are caused by simple background jobs behaving badly under real conditions.&lt;/p&gt;

&lt;p&gt;Async systems fail slowly — and silently.&lt;/p&gt;

&lt;p&gt;Design them assuming failure is the default state.&lt;/p&gt;

</description>
      <category>go</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
