# Environment Variables

All environment variables are **required** at startup. If any is missing, the binary exits immediately — no silent defaults, no fallback configuration.

## Runtime Variables

These variables must be set when starting the ledger binary.

### Server

| Variable      | Description              | Example |
| ------------- | ------------------------ | ------- |
| `LEDGER_PORT` | HTTP port for the server | `8080`  |

### License

| Variable              | Description                                          | Example                   |
| --------------------- | ---------------------------------------------------- | ------------------------- |
| `LEDGER_LICENSE_PATH` | Path to the `license.jwt` file — verified at startup | `/etc/ledger/license.jwt` |

### Database

| Variable                | Description                                          | Example                                        |
| ----------------------- | ---------------------------------------------------- | ---------------------------------------------- |
| `LEDGER_DB_MASTER_URL`  | PostgreSQL connection string for the master (writes) | `postgres://user:pass@master.rds:5432/ledger`  |
| `LEDGER_DB_REPLICA_URL` | PostgreSQL connection string for the replica (reads) | `postgres://user:pass@replica.rds:5432/ledger` |
| `LEDGER_DB_POOL_SIZE`   | Maximum connections per pool (master and replica)    | `10`                                           |
| `LEDGER_DB_TLS`         | Enable TLS for database connections                  | `true` (must be `true` in production)          |

{% hint style="danger" %}
`LEDGER_DB_TLS` must be set to `true` in production. TLS certificates are included in the container image's system trust store by default (Amazon Linux).
{% endhint %}

### Batch Engine

| Variable                  | Description                                    | Example |
| ------------------------- | ---------------------------------------------- | ------- |
| `LEDGER_BATCH_SIZE`       | Maximum transactions per batch before flushing | `150`   |
| `LEDGER_BATCH_TIMEOUT_MS` | Maximum wait time (ms) before flushing a batch | `15`    |

The batch engine flushes when either condition is met — whichever comes first.

### Idempotency

| Variable                                  | Description                                   | Example |
| ----------------------------------------- | --------------------------------------------- | ------- |
| `LEDGER_IDEMPOTENCY_TTL_HOURS`            | How long idempotency records are kept (hours) | `1`     |
| `LEDGER_IDEMPOTENCY_CLEANUP_INTERVAL_MIN` | How often the cleanup job runs (minutes)      | `5`     |

**Recommended values:** TTL of 1 hour with cleanup every 5 minutes. The first cleanup run is delayed by the configured interval after startup.

### Console

| Variable             | Description                                          | Example                           |
| -------------------- | ---------------------------------------------------- | --------------------------------- |
| `LEDGER_CONSOLE_URL` | Base URL for the vendor Console (heartbeat endpoint) | `https://console.entrytarget.com` |

### Logging

| Variable   | Description          | Example         |
| ---------- | -------------------- | --------------- |
| `RUST_LOG` | Log level (optional) | `info`, `debug` |

This is the only optional variable. If not set, default logging is used.

## Production Configuration Example

```bash
LEDGER_LICENSE_PATH="/etc/ledger/license.jwt"
LEDGER_PORT=8080
LEDGER_DB_MASTER_URL="postgres://ledger:password@master.cluster.us-east-1.rds.amazonaws.com:5432/ledger"
LEDGER_DB_REPLICA_URL="postgres://ledger:password@replica.cluster.us-east-1.rds.amazonaws.com:5432/ledger"
LEDGER_DB_POOL_SIZE=20
LEDGER_DB_TLS=true
LEDGER_BATCH_SIZE=200
LEDGER_BATCH_TIMEOUT_MS=15
LEDGER_IDEMPOTENCY_TTL_HOURS=1
LEDGER_IDEMPOTENCY_CLEANUP_INTERVAL_MIN=5
LEDGER_CONSOLE_URL="https://console.entrytarget.com"
```

## Tuning Recommendations

See the [Tuning Guide](/docs/performance/tuning.md) for detailed recommendations on batch size, timeout, and pool size settings based on your workload.

| Workload      | `BATCH_SIZE` | `BATCH_TIMEOUT_MS` | `DB_POOL_SIZE` |
| ------------- | ------------ | ------------------ | -------------- |
| Low volume    | 150          | 20                 | 10             |
| Medium volume | 200          | 15                 | 20             |
| High volume   | 300          | 10                 | 40             |


---

# 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://entrytarget.gitbook.io/docs/operations/environment-variables.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.
