# Ledger Module

Source: https://docs.formance.com/v3.2/deploy/self-hosted/modules/ledger

Stack: v3.2

Formance Ledger is a real-time money tracking microservice that lets you model and record complex financial transactions. It offers atomic, multi-posting transactions and is programmable using Numscript, a dedicated DSL (Domain Specific Language) to model and templatize such transactions.

## Requirements

Formance Ledger requires:

- **PostgreSQL**: See configuration guide [here](https://docs.formance.com/deploy/self-hosted/infrastructure/postgresql).
- (Optional) **Broker**: See configuration guide [here](https://docs.formance.com/deploy/self-hosted/infrastructure/message-broker).

## Ledger Object

You can find all the available parameters in [the comprehensive CRD documentation](https://docs.formance.com/stack-api-reference/introduction).

```yaml
apiVersion: formance.com/v1beta1
kind: Ledger
metadata:
  name: formance-dev
spec:
  stack: formance-dev
```

## Worker Settings (v2.3+)

Starting with Ledger v2.3, a separate worker process is deployed alongside the main Ledger API. Configure the worker using the Settings CRD.

### Async Block Hasher

Configure the async block hasher behavior:

```yaml
apiVersion: formance.com/v1beta1
kind: Settings
metadata:
  name: ledger-worker-async-block-hasher
spec:
  stacks: ["*"]
  key: ledger.worker.async-block-hasher
  value: max-block-size=500, schedule="0 */5 * * * *"
```

Available fields:

- `max-block-size`: Maximum block size for the async block hasher
- `schedule`: Cron schedule for the async block hasher

### Pipelines

Configure the worker pipelines behavior:

```yaml
apiVersion: formance.com/v1beta1
kind: Settings
metadata:
  name: ledger-worker-pipelines
spec:
  stacks: ["*"]
  key: ledger.worker.pipelines
  value: pull-interval=5s, push-retry-period=10s, sync-period=1m, logs-page-size=100
```

Available fields:

- `pull-interval`: Interval between pipeline pulls
- `push-retry-period`: Retry period for failed pushes
- `sync-period`: Synchronization period
- `logs-page-size`: Number of logs per page

### Bucket cleanup

Configure when the worker permanently removes [deleted buckets](https://docs.formance.com/v3.2/modules/ledger/working-with/data-isolation-buckets#deleting-and-restoring-buckets). Requires Ledger 2.4.0 and operator 3.8.2 or later.

```yaml
apiVersion: formance.com/v1beta1
kind: Settings
metadata:
  name: ledger-worker-bucket-cleanup
spec:
  stacks: ["*"]
  key: ledger.worker.bucket-cleanup
  value: retention-period=2160h, schedule="0 0 */6 * * *"
```

Available fields:

- `retention-period`: How long a deleted bucket is kept before the worker permanently removes it. Defaults to `720h` (30 days).
- `schedule`: Cron schedule, with a seconds field, for checking for expired buckets. Defaults to every hour.
