A mirror can be FOLLOWING and still contain an unacceptable business result. Ledger does not compare source and target balances or state hashes for you.
Use the same validation specification for the rehearsal, the live-following period, and the final frozen-source check. Only the final check runs against a source that can no longer move.
Define materiality before comparing#
For each ledger, record:
- accounts and account groups whose balances must match exactly;
- assets, precisions, and colors to compare;
- transaction and reference samples, including boundaries and high-value cases;
- reverted and backdated transactions;
- metadata keys, expected types, deleted keys, and null behavior;
- transformations and drops that deliberately change the target;
- query, index, authentication, event, and performance requirements;
- who approves each check and what constitutes a blocking difference.
Do not decide that a difference is immaterial during the production cutover without the validation owner.
Enforce the final comparison boundary#
Run this gate after every Ledger v2 writer is frozen. During rehearsal, use it only against a quiesced source; otherwise the source can advance between the two reads.
Set every prerequisite explicitly. The configured ledgerctl profile must point to the candidate target cluster and have read access to $TARGET_LEDGER. Choose the source transport used by the mirror; do not configure HTTP credentials for a PostgreSQL source.
Save these blocks as one script
The three shell blocks on this page are one program, not independent snippets. set -euo pipefail, the V2_* exports, the helper functions, and FINAL_SOURCE_LOG_ID are defined in earlier blocks and consumed by later ones, and the gate exits with exit 1 on every failure.
Append them in order to a single file and run that file. Pasting them into an interactive shell works until something fails, at which point exit 1 closes the session — taking the exported source configuration and the helper functions with it, at the moment a frozen-source window is open and you most need them.
For a PostgreSQL source, the reader needs CONNECT on the database, USAGE on _system and the selected bucket schema, SELECT on _system.ledgers, and SELECT on the selected bucket's logs table. It does not need write access. Protect credentials as secrets, keep shell tracing disabled, and use the same hostname, database, TLS policy, and identity that the mirror uses.
Define the PostgreSQL authentication helpers and one source-head function, then use them for this gate. V2_PG_HOST must be the exact RDS endpoint used in the DSN, not a different alias. The RDS IAM helper generates a fresh 15-minute token for every psql process. When an assume-role ARN is set, it also obtains fresh role credentials for that invocation. Neither the token nor the temporary AWS credentials enter command-line arguments, global environment variables, or evidence files.
The two paths do not rest on the same guarantee. The PostgreSQL query takes MAX(id), so it is order-independent. The HTTP path reads the first element of a one-item page and treats it as the newest log, which assumes the endpoint returns logs newest-first — an ordering the v2 API contract does not state. Confirm it holds on the Ledger v2 version you are migrating from before you trust the recorded finalSourceLogId: if the endpoint ever returns oldest-first, the gate still fails closed, but the evidence file records the wrong boundary while appearing complete.
Read the target once, capture the complete progress tuple, and stop unless the target is a mirror at the same frozen boundary with no active error:
The failure dump reports only whether an error is present. The persisted mirror error is the raw source, translation or apply error, so it can echo the source endpoint or a PostgreSQL DSN, and it must stay out of CI logs and transcripts. Since the gate exits on failure, the error cannot be left in a shell variable for the operator to inspect: it is written to mirror-error.json with mode 0600 instead. set -o noclobber is deliberate. umask only applies when a file is created, so a plain redirect into an existing path would keep that file's mode while claiming 0600, or follow a symlink left there. Under noclobber the shell opens with O_EXCL, so an existing path — regular file or symlink — makes the write fail rather than succeed somewhere unintended. That is one atomic operation, unlike removing the path first and then creating it, which leaves a window for a symlink to be planted in between. If the write is refused, inspect or remove the existing file and rerun. Read that file, then delete it with the rest of the credential-bearing artifacts.
Two details of the wire format shape those reads, and a gate written without both rejects the one state it exists to accept. The counters are 64-bit integers, so they arrive as JSON strings rather than numbers — assert on their digits, not on type == "number". And a field sitting at its default value is omitted from the response entirely, which is exactly what happens to remainingLogs on a fully caught-up mirror and to mode on a normal ledger.
Absent and present-but-wrong are not the same thing, which is why the check tests has() rather than defaulting with //. An omitted counter is a protobuf default and is accepted as zero; a counter that is present as null, false, or a non-integer is a contract violation and fails the gate. // 0 alone cannot tell those apart, because jq treats null and false as absent — so a malformed response would have been read as a legitimately empty source. Once the check has established that every present counter is digits, the reads below can default with // safely.
Keep the two filtered evidence files with the migration record. Do not save the complete structured ledger response. This ledger read redacts the OAuth2 client secret and any password in the source configuration, but the response still names the source endpoint, database host and user, and OAuth2 client ID. Other surfaces, such as the creation log entry, audit entries, and backups, return the credentials without redaction; see Create a Mirror for the complete list.
Run the technical checks#
| Check | Evidence | Pass condition |
|---|---|---|
| Log coverage | Final source log ID, cursor, observed source head, and remaining logs. | Cursor equals the recorded source ID; remaining logs are zero; no error is present. |
| Ledger identity | Source worksheet and target ledger info. | Source and target names map as planned; target remains in mirror mode before approval. |
| Transaction coverage | Counts by agreed range plus sampled IDs and references. | Matches after documented drops and transformations. |
| Reversions | Source transaction, reversion, and resulting target state. | Original and compensating effects are represented as expected. |
| Account coverage | Counts by material prefix and selected boundary accounts. | All required accounts exist at their expected target addresses. |
| Balances and volumes | Per account/group, asset, and color comparison. | Exact equality except for pre-approved transformation effects. |
| Metadata | Account and transaction key/value/type samples. | Values, deletions, typed nulls, and conversions match the specification. |
| Rewrite evidence | Rule-file hash and fixture results. | Every expected match, non-match, collision, and drop is explained. |
| Indexes | Index status from every target replica. | Every index required by a production query is ready. |
| Mirror health | Time series of cursor/head/error. | The target follows normally and has no unresolved error. |
Counts are useful for coverage but do not prove accounting equality. Pair them with balance, volume, and representative transaction checks.
Compare business invariants#
Translate each domain invariant into a repeatable source query and target query. Examples include:
- customer liabilities equal the corresponding safeguarding or settlement accounts;
- clearing account balances remain within an approved range;
- the sum of wallet balances per asset matches the source result;
- a payout transaction preserves principal, fee, and destination totals;
- every settled business reference remains unique;
- no account moved into an unintended prefix after address rewriting.
For each invariant, save:
- query or command version;
- exact source and target parameters;
- source log boundary;
- normalized result;
- expected transformation adjustment;
- pass/fail result and reviewer.
Do not compare formatted monetary values with floating-point arithmetic. Compare Ledger integer amounts at the declared asset precision.
Validate transformed data#
For each rewrite rule, reconcile the fixture register against the target:
| Rule effect | Required proof |
|---|---|
| Address rewrite | Positive and negative fixtures, collision analysis, and account-group balance comparison. |
| Metadata set/delete | Original value, expected target value/type, missing-field behavior, and deletion result. |
| Typed coercion | Valid conversion and invalid value represented as the expected typed null. |
| Derived account metadata | Captured segments, target account, type, and non-matching address. |
| Drop | Source log ID, reason, transaction ID when present, and accounting impact. |
An unexplained difference is a failed validation, even if it appears to match the intent of a rule.
Validate application workflows#
Connect a non-production application instance to the target. A mirror rejects writes, so split the test:
- run read, filter, pagination, metadata-read, and reporting workflows against the production-shaped mirror;
- run create, retry, revert, metadata-write, and bulk workflows against a disposable normal target built from the same release;
- test the final endpoint and authentication switch in the cutover rehearsal;
- verify every target identity has the intended scope and no broader one;
- test timeout, conflict, unavailable, and rate-limit handling where relevant.
The application must use the target contract. A correct data copy does not make a Ledger v2 client compatible.
Validate event consumers#
Mirrored Ledger v2 entries are ordinary target logs. Every supported imported change produces a standard target event, and a newly created sink starts at cursor 0 and replays all supported retained history. The current sink configuration does not provide a start cursor that opts out of that replay.
Treat historical replay as part of the migration, not as an optional event mode. Keep the target destination or consumer quarantined while Ledger v2 remains the production authority: it may durably receive and inspect target events, but it must not repeat business effects already produced from the Ledger v2 pipeline.
For every downstream consumer:
- confirm the target sink configuration;
- verify the standard target event type and payload for imported transactions, reversions, and metadata changes;
- persist and deduplicate target at-least-once delivery using a stable target source identity plus
logSequence; - deduplicate business effects across versions with a key that survives the Ledger v2-to-target translation;
- run the full retained replay through quarantine and prove that no historical message produces a second effect;
- after the mirror reaches the frozen source boundary, record the target sink cursor and destination or consumer checkpoint that prove replay has drained through the corresponding target event history;
- verify recovery and redelivery after temporarily interrupting the destination;
- activate effects only for events after the approved cutover boundary, then test the first post-boundary event.
Do not use only the target logSequence as the cross-version business key: it belongs to the target cluster and does not match the identity used by an existing Ledger v2 pipeline. Document the business key for every effecting event type. If one cannot be defined, the consumer is not ready for cutover.
The mirror cursor is a Ledger v2 log ID; the sink cursor is a target global log sequence. They are different sequence spaces and must not be compared numerically.
Record the point at which the Ledger v2 consumer stops, the replay checkpoint reached in quarantine, and the point at which target effects become active. The activation boundary is migration evidence enforced by your consumer workflow; it is not a configurable sink start cursor.
Validate operational readiness#
- target cluster has a stable leader and quorum;
- disk, WAL, memory, and compaction headroom remain within the approved budget;
- replay and query latency meet the migration objectives;
- required indexes are ready on every replica;
- authentication, TLS, monitoring, alerts, backup, and incident ownership are active;
- administrators can read mirror progress and promotion status without exposing source credentials.
Store the evidence#
Use a durable record rather than a chat transcript. One check can be represented as:
Keep secrets and access tokens out of the record.
Final approval gate#
- The source is frozen and the final source log ID is recorded.
- Target cursor equals that final ID, remaining logs are zero, and no error is present.
- Transactions, references, accounts, balances, volumes, and reversions pass.
- Metadata, typed nulls, transformations, and drops pass.
- Required indexes and queries pass.
- Client authentication and production workflows pass.
- Target event replay has drained through the event boundary captured after the final frozen-source check.
- Historical target events cannot repeat Ledger v2 business effects.
- Sink and consumer checkpoints, stable deduplication keys, and the activation boundary are recorded.
- Recovery, redelivery, and the rehearsal's first post-boundary event pass.
- Performance and operational readiness pass.
- Every difference has an owner-approved explanation.
- The validation and migration owners sign the evidence.
Do not promote because the maintenance window is ending. If a material check fails or lacks evidence, keep Ledger v2 frozen only as long as the approved window allows, then resume it and schedule another cutover.
Continue with Cut Over and Promote only after the final approval gate passes.