# Transactions & Postings

Source: https://docs.formance.com/v3.2/modules/ledger/core-concepts/transactions

Stack: v3.2

The Formance Ledger represents financial activity using two primitives: **postings** and **transactions**. Postings are the basic unit of movement; transactions are timestamped containers that group one or more postings together.

A committed transaction's financial content is immutable: its postings, amounts, assets, and timestamp can never change. To correct an error, see [Reverting Transactions](https://docs.formance.com/v3.2/modules/ledger/working-with/reverting-transactions). Metadata is the exception — it can be added or removed at any time after commit, as described in [Metadata](#metadata) below.

## Postings

A posting records the movement of an amount of an asset from a source account to a destination account.

```json
{
  "source": "alice",
  "destination": "bob",
  "asset": "COIN",
  "amount": 100
}
```

![A posting moving 100 COIN from alice to bob](https://docs.formance.com/assets/images/ledger/core-concepts/posting.svg)

Each posting has exactly one source and one destination. The Formance Ledger records the full history of postings; account balances are derived from that history rather than stored directly.

The `asset` field must match the ledger's asset pattern — an uppercase identifier, optionally with an `_SUFFIX` and an optional `/precision` — but beyond that shape the ledger attaches no meaning to it: there is no currency registry. By convention the name follows the ISO 4217 three-letter currency code (e.g. `USD`, `EUR`, `GBP`), suffixed with a precision indicator where the asset has decimals (`USD/2` means amounts are expressed in cents). Custom asset names like `COIN` or `REWARD_POINT` are equally valid. See [Assets](https://docs.formance.com/v3.2/modules/ledger/core-concepts/assets) for the exact pattern.

## Transactions

A transaction is a timestamped, permanently recorded grouping of one or more postings. For example, Alice trading coins for gems at a teller involves two postings in one transaction:

```json
{
  "postings": [
    {
      "source": "alice",
      "destination": "teller",
      "amount": 100,
      "asset": "COIN"
    },
    {
      "source": "teller",
      "destination": "alice",
      "amount": 5,
      "asset": "GEM"
    }
  ]
}
```

![A transaction grouping two postings between alice and teller](https://docs.formance.com/assets/images/ledger/core-concepts/transaction.svg)

### Atomicity

Transactions are **atomic**: all of their postings are applied together, or none are. There is no intermediate state in which some postings have been committed and others have not.

![Atomicity: a transaction either applies all postings or rolls back entirely](https://docs.formance.com/assets/images/ledger/core-concepts/atomicity.svg)

The diagram above shows a customer payment split between a merchant and the platform. If the posting to `platform:fees` fails, atomicity means the posting to `merchant:account` is not applied either: the customer is not charged and the merchant receives nothing. There is no intermediate state where the merchant was paid but the platform was not.

## Single source and destination postings

Every posting in the Formance Ledger has exactly one source and one destination. When a split or fan-out is needed, use a transient intermediary account: funds move into it in one posting and out to each destination in separate postings, all within the same atomic transaction:

![A split payment via a transient order:hold account](https://docs.formance.com/assets/images/ledger/core-concepts/split-payment.svg)

```json
{
  "postings": [
    {
      "source": "customer:wallet",
      "destination": "order:hold",
      "asset": "USD/2",
      "amount": 2000
    },
    {
      "source": "order:hold",
      "destination": "merchant:account",
      "asset": "USD/2",
      "amount": 1800
    },
    {
      "source": "order:hold",
      "destination": "rider:earnings",
      "asset": "USD/2",
      "amount": 100
    },
    {
      "source": "order:hold",
      "destination": "platform:fees",
      "asset": "USD/2",
      "amount": 100
    }
  ]
}
```

`order:hold` is the transient intermediary. It receives the full amount in the first posting and distributes it in the three that follow. All four postings commit atomically: either the full split happens, or nothing does.

The split logic ("5% to fees, 5% to the rider, the rest to the merchant") belongs in [Numscript](https://docs.formance.com/modules/numscript), which compiles your intent into unambiguous single-destination postings automatically.

Numscript runs on the `machine` interpreter by default. Experimental language features require the new interpreter — set `runtime: experimental-interpreter` on the transaction request. See [Selecting an Interpreter](https://docs.formance.com/v3.2/modules/numscript/interpreter).

### Why not a single posting with multiple destinations?

An alternative design would allow one posting to fan out to multiple destinations directly:

![A multi-destination posting where amounts are ambiguous](https://docs.formance.com/assets/images/ledger/core-concepts/multi-destination.svg)

This is mathematically valid, but consider the questions you need a ledger to answer. Looking at alice's account: _how much did alice pay in this transaction?_ Looking at the fees account: _how much of this transaction went to fees?_ With a multi-destination posting, neither question has a clean answer; the `amount` field on the posting is ambiguous, and reconstructing per-destination flows requires parsing the posting's structure rather than reading a single number.

With single-destination postings, every question resolves to one posting with one unambiguous amount: alice moved exactly `2000 USD/2` to `order:hold`, and `platform:fees` received exactly `100 USD/2`.

Multi-posting transactions reduce coordination complexity

Crediting a user from multiple source accounts, for example, can be expressed as a single transaction rather than a series of independent operations that must succeed or fail together.

Single source/destination postings improve auditability

Each posting has one source, one destination, and one unambiguous amount. Every account balance question resolves to a single number on a single line.

## Volumes and Balances

When a transaction commits, the ledger records the running totals (called **volumes**) on every account involved. The Ledger distinguishes between volumes and balances:

| Concept      | Description                                                                                                    |
| ------------ | -------------------------------------------------------------------------------------------------------------- |
| **Volumes**  | The total input and output amounts processed for an account. Stored as unsigned integers, always non-negative. |
| **Balances** | The available amount in an account. Can be positive, negative, or zero.                                        |

The ledger does not store balances directly. Instead, it records cumulative volumes. Balances are derived by subtracting output from input.

### Terminology across the API

The Formance Ledger uses different terms depending on context:

| Concept                      | Account component     | API (postings)      | API (volumes)  |
| ---------------------------- | --------------------- | ------------------- | -------------- |
| Value arriving in an account | Destination component | `destination` field | `input` field  |
| Value leaving an account     | Source component      | `source` field      | `output` field |

Postings (`source`/`destination` fields) describe movement between accounts. Volumes (`input`/`output` in `preCommitVolumes` and `postCommitVolumes`) are the running totals on each account before and after the transaction commits.

```json
{
  "preCommitVolumes": {
    "world": { "USD/2": { "input": 0, "output": 0 } },
    "bank":  { "USD/2": { "input": 0, "output": 0 } }
  },
  "postCommitVolumes": {
    "world": { "USD/2": { "input": 0,   "output": 100 } },
    "bank":  { "USD/2": { "input": 100, "output": 0   } }
  }
}
```

## Metadata

Transactions support metadata: key-value pairs you can attach at creation time or update later.

### Setting transaction metadata

Use `set_tx_meta()` in Numscript to attach metadata to a transaction at creation time:

```numscript
set_tx_meta("reference", "order-12345")
set_tx_meta("type", "payment")

send [USD/2 1000] (
  source = @customers:123
  destination = @merchants:456
)
```

### Setting account metadata in a transaction

Use `set_account_meta()` in Numscript to set or update account metadata as part of a transaction:

```numscript
set_account_meta(@users:alice, "tier", "premium")
```

For managing account metadata outside of transactions, see [Accounts](https://docs.formance.com/v3.2/modules/ledger/core-concepts/accounts#using-metadata).
