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

# Deployment

> Deploy Hyrex applications to production environments

Deploy your Hyrex applications reliably to production with proper environment setup and containerization.

<Tabs>
  <Tab title="Hyrex Cloud">
    ## Production on Hyrex Cloud

    Hyrex Cloud handles infrastructure, scaling, and monitoring automatically.

    ### Environment Setup

    1. **Set Your API Key**

    ```bash theme={null}
    # Production API key
    export HYREX_API_KEY="prod_hx_..."
    ```

    2. **Configure App for Workers**

    ```python theme={null}
    # hyrex_app.py
    from hyrex import HyrexApp

    app = HyrexApp("production-app")
    ```

    ### Docker Deployment

    Deploy workers using Docker:

    ```dockerfile theme={null}
    FROM python:3.11-slim

    WORKDIR /app
    COPY requirements.txt .
    RUN pip install -r requirements.txt

    COPY . .

    CMD ["hyrex", "run-worker", "hyrex_app:app"]
    ```

    Run with your API key:

    ```bash theme={null}
    docker run -e HYREX_API_KEY=$HYREX_API_KEY myapp:latest
    ```

    ### Configuration

    1. **Use separate API keys** for dev/staging/prod
    2. **Set num\_processes** based on task type
    3. **Use queues** to separate workload types
  </Tab>

  <Tab title="FOSS">
    ## Production with FOSS

    Deploy Hyrex on your infrastructure with PostgreSQL.

    ### Database Setup

    Configure PostgreSQL for production:

    ```bash theme={null}
    # Set connection URL
    export HYREX_DATABASE_URL="postgresql://user:pass@host:5432/hyrex_prod"
    ```

    ### High Availability

    1. **Database HA**

    * Use PostgreSQL streaming replication
    * Configure automatic failover with Patroni
    * Regular backups with pg\_dump or WAL-G

    2. **Worker HA**

    * Deploy workers across multiple nodes
    * Use different queues for critical tasks
    * Configure health checks and auto-restart

    ### Docker Compose Example

    ```yaml theme={null}
    version: '3.8'
    services:
      postgres:
        image: postgres:15
        environment:
          POSTGRES_DB: hyrex_prod
          POSTGRES_USER: hyrex
          POSTGRES_PASSWORD: ${DB_PASSWORD}
        volumes:
          - postgres_data:/var/lib/postgresql/data
        ports:
          - "5432:5432"
      
      worker:
        build: .
        environment:
          HYREX_DATABASE_URL: postgresql://hyrex:${DB_PASSWORD}@postgres:5432/hyrex_prod
        depends_on:
          - postgres
        deploy:
          replicas: 3

    volumes:
      postgres_data:
    ```
  </Tab>
</Tabs>

## Deployment Checklist

### Pre-Deployment

* [ ] Load test your tasks to determine resource needs
* [ ] Configure appropriate task timeouts
* [ ] Set up error tracking (Sentry, etc.)
* [ ] Plan queue structure for workload separation
* [ ] Document task dependencies

### Deployment

* [ ] Use environment variables for configuration
* [ ] Set up secrets management
* [ ] Configure resource limits
* [ ] Enable health checks
* [ ] Set up log aggregation

### Environment Variables

```bash theme={null}
# Required
export HYREX_API_KEY="prod_hx_..."              # For Cloud
export HYREX_DATABASE_URL="postgresql://..."   # For FOSS

# Optional
export HYREX_LOG_LEVEL="INFO"
export HYREX_MAX_CONCURRENCY="100"
export HYREX_WORKER_TIMEOUT="3600"
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Monitoring & Scaling" href="/production/monitoring-scaling" icon="chart-line">
    Set up monitoring and scaling strategies
  </Card>

  <Card title="Best Practices" href="/production/best-practices" icon="check-circle">
    Production checklist and maintenance
  </Card>
</CardGroup>
