C
CanxJS
v1.6.2
  • Learn
  • Blog
  • Showcase
C
CanxJS

Ultra-fast async MVC backend framework for Bun. Build production-ready APIs with elegance and speed.

Resources

  • Documentation
  • Learn
  • Blog
  • Showcase

Documentation

  • Introduction
  • Installation
  • Core Concepts
  • CLI Commands
  • API Reference

Legal

  • Privacy Policy
  • Terms of Service

© 2026 CanxJS. All rights reserved.

Built with ❤️ for Candra Kirana

  • Cluster Mode
  • Microservices
  • Observability
  • Security Layers
  • Universal Signals
  • Canx Flow
  • Maintenance
Enterprise

Cluster Mode

Scale your application across multiple CPU cores with zero-downtime reloads CanxJS's cluster mode is built on top of the Node.js cluster module, but adds significant power:

Automatic Load Balancing

Traffic is distributed round-robin across all worker processes.

Zero-Downtime Reload

Update code without dropping a single connection.

Crash Recovery

Dead workers are instantly replaced to maintain availability.

Multi-Core Utilization

Utilize all available CPU cores for maximum performance.

Enabling Cluster Mode

Use the initCluster() function Typically, you want one worker per CPU core. CanxJS defaults to os.cpus().length. Set workers: 'auto' to automatically detect CPU cores.

app.ts
1import { initCluster, CanxServer } from 'canxjs';
2
3// Initialize Cluster
4initCluster({
5 enabled: true,
6 workers: 'auto', // Auto-detect CPU cores
7});
8
9const app = new CanxServer();
10app.start();

Advanced Configuration

Customize cluster behavior with lifecycle hooks and environment-based settings.

app.ts
1initCluster({
2 enabled: process.env.NODE_ENV === 'production',
3 workers: 4, // Force 4 workers
4 wrapper: (app) => {
5 console.log(`Worker ${process.pid} started`);
6 },
7 onWorkerExit: (worker, code, signal) => {
8 console.log(`Worker ${worker.process.pid} died`);
9 }
10});

Configuration Options

OptionTypeDescription
enabledbooleanEnable/disable cluster mode
workers'auto' | numberNumber of workers or auto-detect
wrapperfunctionCalled when worker starts
onWorkerExitfunctionCalled when worker dies

Zero-Downtime Reload

Gracefully reload all workers without dropping connections. Workers are replaced one-by-one.

deployment.sh
1// Send SIGUSR2 to master process for graceful reload
2// All workers are replaced one-by-one
3
4// In your deployment script:
5// kill -SIGUSR2 $(cat /var/run/canx.pid)
6
7// Or use the CLI:
8// node canx cluster:reload

Next Steps

Explore other enterprise features for building production-ready systems.