<?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: Xar Hang</title>
    <description>The latest articles on DEV Community by Xar Hang (@xar_hang_07e16c25c5028c89).</description>
    <link>https://dev.to/xar_hang_07e16c25c5028c89</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%2F2808595%2F4baee58b-bf30-40d8-b831-bb0b8d8240e3.jpg</url>
      <title>DEV Community: Xar Hang</title>
      <link>https://dev.to/xar_hang_07e16c25c5028c89</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/xar_hang_07e16c25c5028c89"/>
    <language>en</language>
    <item>
      <title>Why i Built BS9: A Self-Healing Process Manager for Bun</title>
      <dc:creator>Xar Hang</dc:creator>
      <pubDate>Thu, 17 Sep 2026 17:10:32 +0000</pubDate>
      <link>https://dev.to/xar_hang_07e16c25c5028c89/running-bun-in-production-zero-downtime-reloads-clustering-with-bs9-12hn</link>
      <guid>https://dev.to/xar_hang_07e16c25c5028c89/running-bun-in-production-zero-downtime-reloads-clustering-with-bs9-12hn</guid>
      <description>&lt;p&gt;&lt;strong&gt;Bun is fast. Extremely fast.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;However, running Bun HTTP services in long-running production environments introduces familiar operational challenges:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Zero-Downtime Reloads&lt;/strong&gt;: How do you reload workers when shipping code without dropping in-flight traffic?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fault Tolerance&lt;/strong&gt;: How do you recover cleanly if an unhandled exception or &lt;code&gt;SIGKILL&lt;/code&gt; crashes a process?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cross-Platform Daemons&lt;/strong&gt;: How do you manage persistent daemons cleanly across Linux (&lt;code&gt;systemd&lt;/code&gt;), macOS (&lt;code&gt;launchd&lt;/code&gt;), and Windows?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While legacy tools like PM2 exist, they were architected around Node.js multi-process clustering paradigms and often hit friction when managing Bun native features.&lt;/p&gt;

&lt;p&gt;Enter &lt;strong&gt;BS9 (Bun Sentinel 9)&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚡ What is BS9?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/xarhang/bs9" rel="noopener noreferrer"&gt;BS9&lt;/a&gt; is an open-source process supervisor and high-availability clustering manager tailored specifically for &lt;strong&gt;Bun&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;It is designed to be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🚀 &lt;strong&gt;Lightweight&lt;/strong&gt; with near-zero overhead&lt;/li&gt;
&lt;li&gt;🔒 &lt;strong&gt;Secure&lt;/strong&gt; (non-root by design)&lt;/li&gt;
&lt;li&gt;🛡️ &lt;strong&gt;Resilient&lt;/strong&gt; against unexpected worker failures and memory spikes&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🎯 What Makes BS9 Different?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Replace-First Rolling Reloads
&lt;/h3&gt;

&lt;p&gt;Traditional process managers often terminate the old process &lt;em&gt;before&lt;/em&gt; the new one is fully initialized and bound to the socket. BS9 uses a &lt;strong&gt;Replace-First&lt;/strong&gt; strategy:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Spawns generation &lt;code&gt;g(n+1)&lt;/code&gt; in an isolated slot.&lt;/li&gt;
&lt;li&gt;Waits for genuine HTTP / IPC readiness checks to pass.&lt;/li&gt;
&lt;li&gt;Safely drains in-flight requests on generation &lt;code&gt;g(n)&lt;/code&gt; with a configurable drain timeout.&lt;/li&gt;
&lt;li&gt;Decommissions the old worker only after the traffic handoff succeeds.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  2. Same-Host State Hub
&lt;/h3&gt;

&lt;p&gt;Need atomic locks, distributed leases with fencing tokens, or state persistence across worker restarts without setting up an external Redis cluster?&lt;/p&gt;

&lt;p&gt;BS9 includes a built-in &lt;strong&gt;State Hub&lt;/strong&gt; with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write-Ahead Logging (WAL)&lt;/li&gt;
&lt;li&gt;Compare-And-Swap (CAS) primitives&lt;/li&gt;
&lt;li&gt;Zero external infrastructure required&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Built-in Chaos &amp;amp; Verification CLI
&lt;/h3&gt;

&lt;p&gt;BS9 comes with &lt;code&gt;verify-ha&lt;/code&gt; out of the box. You can test your application scripts against automated chaos experiments and rolling reloads:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bs9 verify-ha ./server.ts &lt;span class="nt"&gt;--concurrency&lt;/span&gt; 20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It bombards your application with continuous HTTP traffic while simultaneously injecting rolling reloads and violent &lt;code&gt;SIGKILL&lt;/code&gt; crashes, returning an actionable latency and availability report.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 Getting Started
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;You can install BS9 via the verified installer script or directly with Bun:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Via curl&lt;/span&gt;
curl &lt;span class="nt"&gt;-fsSLO&lt;/span&gt; https://github.com/xarhang/bs9/releases/download/v1.6.6/setup.sh
&lt;span class="nb"&gt;sha256sum &lt;/span&gt;setup.sh &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; bash setup.sh

&lt;span class="c"&gt;# Or via package manager&lt;/span&gt;
bun &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; bs9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Starting a Clustered Service
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Start your service with all available CPU cores&lt;/span&gt;
bs9 start app.ts &lt;span class="nt"&gt;--name&lt;/span&gt; my-api &lt;span class="nt"&gt;-i&lt;/span&gt; max

&lt;span class="c"&gt;# Check process cluster status&lt;/span&gt;
bs9 status

&lt;span class="c"&gt;# Open the real-time terminal dashboard&lt;/span&gt;
bs9 monit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔗 Links &amp;amp; Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repository&lt;/strong&gt;: &lt;a href="https://github.com/xarhang/bs9" rel="noopener noreferrer"&gt;github.com/xarhang/bs9&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Official Documentation&lt;/strong&gt;: &lt;a href="https://xarhang.github.io/bs9/" rel="noopener noreferrer"&gt;xarhang.github.io/bs9&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Give it a spin on your Bun projects! If you find it helpful, feel free to drop a star ⭐ on GitHub or leave your feedback and feature requests in the comments below.&lt;/p&gt;

</description>
      <category>bunjs</category>
      <category>javascript</category>
      <category>devops</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
