> For the complete documentation index, see [llms.txt](https://stricjs.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://stricjs.gitbook.io/docs/basic/clustering.md).

# Clustering

Run multiple instances to distribute workloads

Cluster can be used to run multiple instances that can distribute workloads among their application threads. When process isolation is not needed, use [`Worker`](https://bun.sh/docs/api/workers) instead, which allows running multiple application threads within a single instance.

Install the cluster module by:

```bash
bun add @stricjs/cluster
```

Here's an example of serving a web server with 4 threads.

```typescript
import { Router, macro } from '@stricjs/router';
import { spawn, worker } from '@stricjs/cluster';

if (worker) {
    const app = new Router().get('/', macro(
        () => new Response('Hi')
    ));
        
    Bun.serve(app);
} else spawn(4);
```
