# How Connectivity Works

Source: https://docs.formance.com/v4.0/modules/connectivity/how-it-works

Stack: v4.0

A connection runs the same loop for as long as it is installed. It reads new activity from the provider, turns each record into Ledger accounts, transactions, and metadata, writes them, and saves how far it got. If anything fails, it starts again from the last saved point, so nothing is skipped or recorded twice.

```mermaid
flowchart TB
  Provider["External provider<br/>objects, events, files, and snapshots"] --> Observe["Observe<br/>from the last confirmed point"]
  Observe --> Match["Match and transform<br/>through the connector profile"]
  Match --> Record["Record<br/>accounts, transactions, and metadata"]
  Record --> Confirm["Confirm progress<br/>in Ledger"]
  Confirm -. "continue from the confirmed checkpoint" .-> Observe
```

[From Provider to Ledger](https://docs.formance.com/v4.0/modules/connectivity/from-provider-to-ledger) animates the same loop with a fictional payment.

## One record through the loop

The steps below follow one real record: a Stripe processing fee read by the [Stripe Payments](https://docs.formance.com/v4.0/modules/connectivity/connectors/stripecore) connector. Every connector runs the same steps with its own provider records.

Observe

The connection reads the provider's activity from its last saved checkpoint. Stripe Payments reads the account's balance transactions and finds a new `stripe_fee` entry with status `pending`.

Match and transform

The connector's profile (its rules for turning provider records into Ledger entries) picks the rule for this kind of record. A pending Stripe fee matches the rule that holds the fee in Stripe's pending balance. The rule computes the amount, the accounts, and a unique reference, such as `stripe:bt:<account>:<id>:pending`.

Record

Ledger writes a balanced transaction under that reference and attaches the Stripe IDs, status, and timestamps as metadata. Records that do not move money, such as a charge changing state, go to a separate lifecycle account, so they never change a money balance.

Confirm progress

Connectivity saves the checkpoint in the same write as the records. When Stripe later reports the fee as `available`, a second rule books it to the processing-fees account under a reference ending in `:available`.

The connector's catalog entry lists which records it reads (**Coverage**), the accounts and rules it uses (**Ledger Model**), and the access it needs (**Config**).

## What happens when a write fails

Reading from the provider and writing to Ledger are separate steps, and either can fail. The checkpoint advances only when Ledger accepts the records it covers. If the write fails, the connection reads the same records again and retries.

```mermaid
sequenceDiagram
  participant P as Provider
  participant C as Connection
  participant L as Ledger
  C->>P: read from checkpoint 41
  P-->>C: new records
  C->>L: write records + checkpoint 42
  L--xC: write fails
  Note over C: checkpoint stays at 41
  C->>P: read again from checkpoint 41
  C->>L: write records + checkpoint 42
  L-->>C: ok (no duplicates)
```

The retry cannot create duplicates because each transaction carries the unique reference from its rule. If an earlier attempt did reach Ledger, Ledger does not record the same reference twice.

What a checkpoint tells you

The checkpoint shows how far the connection has delivered what it reads. It says nothing about history that the provider no longer exposes, or about activity outside the connector's coverage. Check both in the connector's **Coverage** tab.

## Restarting and changing a connection

Restarting a connection with the same settings resumes from its checkpoint.

Some changes alter the accounts, references, or checkpoint format, such as a major connector upgrade or a different provider scope. The connector's release notes say when a change is incompatible. For an incompatible change, install a new connection on a separate ledger and keep the old one for its history. The protection against duplicates relies on references staying the same, so it does not carry across an incompatible change.

## What differs between connectors

You can skip this section if you only want to set up a connection. Read it before you compare connectors, or before you rely on a connector's balances for reporting. Every connector runs the same loop, but providers behave differently. Each catalog entry documents how:

| Topic                   | What the catalog entry tells you                                                                                                                                                                               |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Timing and finality** | Which provider states the connector records, such as pending, booked, or settled.                                                                                                                              |
| **History**             | How far back the connector reads, and how it establishes an opening position.                                                                                                                                  |
| **Corrections**         | How refunds, reversals, and late or repeated records are recorded.                                                                                                                                             |
| **Balances**            | Whether the provider's own balances are recorded, and how they compare with Ledger's. See [Two views of a balance](https://docs.formance.com/v4.0/modules/connectivity/what-it-models#two-views-of-a-balance). |
| **Delivery**            | Whether the connector polls, receives notifications, or reads scheduled files.                                                                                                                                 |

Open the [Connector Catalog](https://docs.formance.com/v4.0/modules/connectivity/connectors) to check these for a specific provider, or [set up a connection](https://docs.formance.com/v4.0/modules/connectivity/get-started).
