DEV Community

Xar Hang
Xar Hang

Posted on

Why i Built BS9: A Self-Healing Process Manager for Bun

Bun is fast. Extremely fast.

However, running Bun HTTP services in long-running production environments introduces familiar operational challenges:

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

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.

Enter BS9 (Bun Sentinel 9).


⚡ What is BS9?

BS9 is an open-source process supervisor and high-availability clustering manager tailored specifically for Bun.

It is designed to be:

  • 🚀 Lightweight with near-zero overhead
  • 🔒 Secure (non-root by design)
  • 🛡️ Resilient against unexpected worker failures and memory spikes

🎯 What Makes BS9 Different?

1. Replace-First Rolling Reloads

Traditional process managers often terminate the old process before the new one is fully initialized and bound to the socket. BS9 uses a Replace-First strategy:

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

2. Same-Host State Hub

Need atomic locks, distributed leases with fencing tokens, or state persistence across worker restarts without setting up an external Redis cluster?

BS9 includes a built-in State Hub with:

  • Write-Ahead Logging (WAL)
  • Compare-And-Swap (CAS) primitives
  • Zero external infrastructure required

3. Built-in Chaos & Verification CLI

BS9 comes with verify-ha out of the box. You can test your application scripts against automated chaos experiments and rolling reloads:

bs9 verify-ha ./server.ts --concurrency 20
Enter fullscreen mode Exit fullscreen mode

It bombards your application with continuous HTTP traffic while simultaneously injecting rolling reloads and violent SIGKILL crashes, returning an actionable latency and availability report.


🚀 Getting Started

Installation

You can install BS9 via the verified installer script or directly with Bun:

# Via curl
curl -fsSLO https://github.com/xarhang/bs9/releases/download/v1.6.6/setup.sh
sha256sum setup.sh && bash setup.sh

# Or via package manager
bun install -g bs9
Enter fullscreen mode Exit fullscreen mode

Starting a Clustered Service

# Start your service with all available CPU cores
bs9 start app.ts --name my-api -i max

# Check process cluster status
bs9 status

# Open the real-time terminal dashboard
bs9 monit
Enter fullscreen mode Exit fullscreen mode

🔗 Links & Resources

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.

Top comments (0)