# What Changed from Ledger 2.x

Source: https://docs.formance.com/v4.0/modules/ledger/migration/what-changed

Stack: v4.0

Stack v3.0, v3.1, and v3.2 ship Ledger 2.x (2.2, 2.3, and 2.4), which serves the `/v2` API, and Stack v4.0 ships Ledger 3.0, which serves the `/v3` API.

Ledger 3.0 keeps the accounting model: postings and Numscript, reversals, metadata, unique references, idempotency, and bulk writes. What changes is how you configure and call it. Each section below summarizes one change, gives the reason for it, and links to the migration page that covers it in full.

## Ledger Schema splits into four resources

In Ledger 2.x, one versioned schema carried the chart of accounts, metadata defaults, transaction templates, and query templates, and a write selected all of them at once by naming a schema version. Ledger 3.0 has no Ledger Schema. Each concern is its own resource, configured and read independently:

| Ledger 2.x schema part                   | Ledger 3.0 resource                                                                                                          |
| ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| Chart of accounts and address validation | [Account types](https://docs.formance.com/v4.0/modules/ledger/modeling/account-types) and their enforcement mode             |
| Metadata fields                          | [Typed metadata](https://docs.formance.com/v4.0/modules/ledger/modeling/metadata)                                            |
| Transaction templates                    | The [Numscript library](https://docs.formance.com/v4.0/modules/ledger/transactions/numscript-library), versioned per program |
| Query templates                          | [Prepared queries](https://docs.formance.com/v4.0/modules/ledger/querying/prepared-queries)                                  |

No version selects all four together. Only Numscript programs carry a version, and a caller pins it per request.

The Ledger 2.x schema existed to validate writes. Its types were not used for storage, and could change between schema versions: a metadata key could be a string in one version and an integer in the next. In Ledger 3.0 these resources configure the ledger, and the storage layer uses the declared types. They change at different rates and for different owners, so bundling them would force a new version for every small change. Numscript programs are the only part a caller runs as code, so they are the only part where pinning a version makes results reproducible. A Ledger 3.0 transaction does not record a schema version, because no single schema version exists.

- To move each part, see [Replace Ledger Schema workflows](https://docs.formance.com/v4.0/modules/ledger/migration/update-clients#replace-ledger-schema-workflows), which includes a [worked transaction template example](https://docs.formance.com/v4.0/modules/ledger/migration/update-clients#move-a-transaction-template-to-the-numscript-library).
- For the routes, see the [Ledger Schema rows of the Endpoint Map](https://docs.formance.com/v4.0/modules/ledger/migration/endpoint-map#ledger-schema-mapping-and-queries).

## Buckets are not available

A Ledger 2.x bucket was a separate storage namespace that held one or more ledgers and could be deleted or restored as a unit. Ledger 3.0 does not have buckets: every ledger in a cluster shares the cluster's storage, and a `bucket` value on ledger creation is ignored rather than rejected.

Ledger 2.x used buckets for performance, to separate data, and to drop a group of ledgers quickly. Ledger 3.0 performs well with every ledger in one shared store, and ledgers whose data sits in the same storage directory gain little from a namespace boundary. Dropping a group of ledgers as one unit has no Ledger 3.0 equivalent.

- To choose a replacement for what each bucket gave you, see [Buckets](https://docs.formance.com/v4.0/modules/ledger/migration/removed-capabilities#buckets).

## Idempotency keys share one cluster-wide namespace

Ledger 2.x scoped idempotency keys to a ledger. Ledger 3.0 scopes them to the cluster and applies them to more operations. A key reused anywhere in the cluster with different request content fails with `409` and `IDEMPOTENCY_KEY_CONFLICT`, and keys expire after the cluster's idempotency TTL.

Every write in Ledger 3.0 goes through the same apply path, including writes to objects that are not ledgers, such as Numscript programs, prepared queries, and indexes. Idempotency applies at that level, so it covers all of those writes. One apply batch can span several ledgers, so a per-ledger key scope would not be well defined.

- To rebuild keys and test the conflict cases, see [Redesign idempotency keys](https://docs.formance.com/v4.0/modules/ledger/migration/update-clients#redesign-idempotency-keys).

## Filters need declared types and indexes

Ledger 3.0 replaces the Ledger 2.x query body with a `filter` parameter in a textual or structured form. Metadata is compared as its declared type, so numeric keys accept range operators, and a filter on an indexed field works only once that index is ready. The `prefix=` and `reference=` parameters are ignored, so a call that still sends one returns the unfiltered list.

Ledger 3.0 stores its data in a key-value store, where every index costs write throughput and disk space. Indexes are therefore explicit, so you pay only for the filters you run. A metadata index stores values in the order of their declared type, which is what makes numeric range filters on metadata possible. Ledger 2.x one-segment address wildcards (`users:`, `order::pending`) and `$like` are dropped because a key-value index can scan a byte prefix cheaply, while a pattern in the middle of a key needs a scan of the whole range. Filtering on `balance[...]` is dropped because balances change on every write, and indexing them would slow every write.

- To check each read path, see [Update reads and filters](https://docs.formance.com/v4.0/modules/ledger/migration/update-clients#update-reads-and-filters).
- To rewrite each Ledger 2.x filter, see [Translate filters](https://docs.formance.com/v4.0/modules/ledger/migration/update-clients#translate-filters).

## Volume and balance reads move onto the account

Ledger 3.0 removes the per-account `balances` and `volumes` routes: the account read carries volumes and the balance for each asset and color. The `/volumes` point-in-time parameters are not accepted. Every transaction carries `postCommitVolumes`, an immutable snapshot taken when the transaction applied. `preCommitVolumes` is not returned because it follows from `postCommitVolumes` and the postings, so returning both would duplicate data. Both effective-volume fields are also removed. Point-in-time reads are dropped because Ledger 3.0 keeps current volumes, not a time-indexed history of moves, so a balance at a past date would mean replaying the log. The per-account routes would return the same data as the account read.

- For the reads that move to the account or to `postCommitVolumes`, see [Replaced in Ledger 3.0](https://docs.formance.com/v4.0/modules/ledger/migration/removed-capabilities#replaced-in-ledger-30).
- For the reads with no Ledger 3.0 equivalent, see [What does not carry over](https://docs.formance.com/v4.0/modules/ledger/migration/removed-capabilities#what-does-not-carry-over).
- For the response fields on writes, see [Update transaction writes](https://docs.formance.com/v4.0/modules/ledger/migration/update-clients#update-transaction-writes).

## Account date fields are not returned

Ledger 3.0 accounts have no `firstUsage`, `insertionDate`, or `updatedAt`, and no date condition is valid on the accounts query target. Typed `datetime` account metadata covers the filtering use cases. Date-ordered account pagination has no replacement.

- To stamp, filter, and carry the values across, see [Account date fields](https://docs.formance.com/v4.0/modules/ledger/migration/removed-capabilities#account-date-fields).

## Bulk has an explicit failure model

The bulk route moves from `_bulk` to `/v3/{ledgerName}/bulk`, and the `parallel` and schema version parameters are not accepted. Each request picks one failure model: stop at the first failure (the default), continue after business failures, or commit the whole array atomically under one batch-level `Idempotency-Key`. The response reports a result per element and separates business failures from infrastructure failures. An element can also list `skippableReasons`, such as a reference conflict, to record an expected business failure as a skip.

Ledger 3.0 applies writes in one fixed order through its Raft log, so a `parallel` option would have nothing to act on; batching provides the throughput instead. An atomic batch goes through as a single command and is replayed or rejected as one unit, so one key covers the whole batch and per-element `ik` values are ignored. Business and infrastructure failures get separate statuses so that `continueOnFailure` cannot hide an outage that the client should retry.

- To choose a failure model and test retries, see [Update bulk handling](https://docs.formance.com/v4.0/modules/ledger/migration/update-clients#update-bulk-handling).

## See also

- Check your workflows against [Replaced and Removed Capabilities](https://docs.formance.com/v4.0/modules/ledger/migration/removed-capabilities) before you plan client work.
- Look up the Ledger 3.0 path for every Ledger 2.x call in the [Endpoint Map](https://docs.formance.com/v4.0/modules/ledger/migration/endpoint-map).
- Start the migration with [Plan the Migration](https://docs.formance.com/v4.0/modules/ledger/migration/overview).
