> ## Documentation Index
> Fetch the complete documentation index at: https://www.activepieces.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Separate Workers

Benefits of separating workers from the main application (APP):

* **Availability**: The application remains lightweight, allowing workers to be scaled independently.
* **Security**: Workers lack direct access to Redis and the database, minimizing impact in case of a security breach.

<Steps>
  <Step title="Create Worker Token">
    To create a worker token, use the local CLI command to generate the JWT and sign it with your `AP_JWT_SECRET` used for the app server. Follow these steps:

    1. Open your terminal and navigate to the root of the repository.
    2. Run the command: `npm run workers token`.
    3. When prompted, enter the JWT secret (this should be the same as the `AP_JWT_SECRET` used for the app server).
    4. The generated token will be displayed in your terminal, copy it and use it in the next step.
           <img src="https://mintcdn.com/activepieces/htEDiTsZNK_UML_C/resources/worker-token.png?fit=max&auto=format&n=htEDiTsZNK_UML_C&q=85&s=7d8f5c27a14fea432cd609425a90b88d" alt="Workers Token" width="1596" height="186" data-path="resources/worker-token.png" />
  </Step>

  <Step title="Configure Environment Variables">
    Define the following environment variables in the `.env` file on the worker machine:

    * Set `AP_CONTAINER_TYPE` to `WORKER`
    * Specify `AP_FRONTEND_URL`
    * Provide `AP_WORKER_TOKEN`
  </Step>

  <Step title="(Optional) Configure Persistent Volume">
    A persistent volume is **not required**. Each worker fills its execution cache lazily on first use and stays warm for the life of the replica, so long-lived workers reach steady-state speed on their own.

    A volume only helps if your workers restart frequently and you want to skip the first-run cache fill after each restart. If you want it, map one volume **per worker** (it cannot be shared across workers):

    ```yaml theme={null}
    volumes:
      - <your path>:/usr/src/app/cache
    ```
  </Step>

  <Step title="Launch Worker Machine">
    Launch the worker machine and supply it with the generated token.
  </Step>

  <Step title="Verify Worker Operation">
    Verify that the workers are visible in the Platform Admin Console under Infra -> Workers.

    <img src="https://mintcdn.com/activepieces/htEDiTsZNK_UML_C/resources/workers.png?fit=max&auto=format&n=htEDiTsZNK_UML_C&q=85&s=cd152896f3be11a1d7f8e6b118102172" alt="Workers Infrastructure" width="1846" height="1002" data-path="resources/workers.png" />
  </Step>

  <Step title="Configure App Container Type">
    On the APP machine, set `AP_CONTAINER_TYPE` to `APP`.
  </Step>
</Steps>
