# Clustering

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);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://stricjs.gitbook.io/docs/basic/clustering.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
