<?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: Nilay</title>
    <description>The latest articles on DEV Community by Nilay (@nilay1999).</description>
    <link>https://dev.to/nilay1999</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%2F1260672%2Fa14e6a2a-5e3b-479d-a377-bb324105015d.jpg</url>
      <title>DEV Community: Nilay</title>
      <link>https://dev.to/nilay1999</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nilay1999"/>
    <language>en</language>
    <item>
      <title>ECS Deployment circuit breaker with Serverless Fargate</title>
      <dc:creator>Nilay</dc:creator>
      <pubDate>Fri, 19 Jan 2024 08:56:06 +0000</pubDate>
      <link>https://dev.to/nilay1999/ecs-deployment-circuit-breaker-with-serverless-fargate-38p</link>
      <guid>https://dev.to/nilay1999/ecs-deployment-circuit-breaker-with-serverless-fargate-38p</guid>
      <description>&lt;h1&gt;
  
  
  🚦 ECS Deployment Circuit Breaker with Serverless Fargate
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Stop Bad Deployments Before They Break Your App
&lt;/h3&gt;

&lt;p&gt;Deployments are exciting—until they fail in production. 😅 That’s where &lt;strong&gt;Amazon ECS Deployment Circuit Breaker&lt;/strong&gt; comes in.&lt;br&gt;
Think of it as a &lt;strong&gt;safety switch&lt;/strong&gt;: it catches failed deployments early, rolls back automatically, and keeps your app running smoothly.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 Why You Should Care
&lt;/h2&gt;

&lt;p&gt;Here’s what the circuit breaker does for you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🔄 &lt;strong&gt;Auto Rollback&lt;/strong&gt; – Bad deploy? ECS flips back to the last good version.&lt;/li&gt;
&lt;li&gt;⏱ &lt;strong&gt;Less Downtime&lt;/strong&gt; – Faulty tasks get stopped before they impact users.&lt;/li&gt;
&lt;li&gt;🛡 &lt;strong&gt;Safety Net&lt;/strong&gt; – ECS continuously checks health and cancels bad rollouts.&lt;/li&gt;
&lt;li&gt;😴 &lt;strong&gt;Sleep Easy&lt;/strong&gt; – No more 3 AM firefights over broken deployments.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  ⚙️ How It Works
&lt;/h2&gt;

&lt;p&gt;ECS tracks deployment failures in &lt;strong&gt;two stages&lt;/strong&gt;:&lt;/p&gt;
&lt;h3&gt;
  
  
  1️⃣ Task Startup
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✅ &lt;strong&gt;Success&lt;/strong&gt;: At least one task reaches &lt;code&gt;RUNNING&lt;/code&gt; → move to health checks.&lt;/li&gt;
&lt;li&gt;❌ &lt;strong&gt;Failure&lt;/strong&gt;: Multiple tasks fail to start → deployment may be marked as &lt;code&gt;FAILED&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  2️⃣ Health Checks
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;✅ &lt;strong&gt;Success&lt;/strong&gt;: At least one task passes ELB, Cloud Map, or container health checks.&lt;/li&gt;
&lt;li&gt;❌ &lt;strong&gt;Failure&lt;/strong&gt;: Health check failures exceed threshold → deployment fails → rollback triggered.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Failure Threshold Example:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Desired Task Count&lt;/th&gt;
&lt;th&gt;Threshold (min 3, max 200)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;25&lt;/td&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;400&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;800&lt;/td&gt;
&lt;td&gt;200 (capped)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;


&lt;h2&gt;
  
  
  🚀 Setup with Serverless + Fargate
&lt;/h2&gt;

&lt;p&gt;Enable circuit breaker in your &lt;code&gt;serverless.yml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;cloudFormationResource&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;DeploymentConfiguration&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;DeploymentCircuitBreaker&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;Enable&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
        &lt;span class="na"&gt;Rollback&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Done ✅ — your service now has a safety net.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧪 Test It Out
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Deploy a simple &lt;strong&gt;Express app&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ol&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="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;app&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&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="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Health Check!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&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="s2"&gt;`Running on :3000`&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Build &amp;amp; push Docker image.&lt;/li&gt;
&lt;li&gt;Simulate a &lt;strong&gt;bad deploy&lt;/strong&gt; by forcing an error in &lt;code&gt;Dockerfile&lt;/code&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["EXIT", "2"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 ECS &lt;strong&gt;rolls back automatically&lt;/strong&gt;, saving your users.&lt;/p&gt;




&lt;h2&gt;
  
  
  🎯 The Takeaway
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;ECS Deployment Circuit Breaker&lt;/strong&gt; is a simple switch with a huge payoff:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fewer outages&lt;/li&gt;
&lt;li&gt;Automatic rollbacks&lt;/li&gt;
&lt;li&gt;Stress-free deployments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you’re using &lt;strong&gt;Fargate + Serverless&lt;/strong&gt;, flipping it on is a no-brainer.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
