Browse documentation

On this page

Webhooks, Idempotency, and Reliable Writes

Every financial API will eventually receive the same request twice. The only question is what happens next.

This document explains the reliability model behind Paprel's write path: why retries are assumed rather than treated as edge cases, how payment idempotency keys, document numbers and pre-ledger validation keep the books correct under them, what the signed webhook contract gives downstream systems, and what recovery looks like when a consumer loses events.

Retries are the normal case

Distributed systems retry. That's not a failure mode — it's how they achieve reliability at all. Your integration will see duplicates from at least three directions:

  • Timeouts. Your request reaches Paprel, the journal posts, and the response is lost on the way back. Your HTTP client sees a timeout and — correctly — retries.
  • Redeliveries. Webhook delivery is at-least-once by nature. A consumer that acknowledges slowly or restarts mid-handler will see the same event again.
  • Resubmits. A user double-clicks a button. A queue worker crashes after the API call but before marking the job done, and the job runs again. An agent re-executes a step.

Now consider what a naive accounting API does with the timeout case. The payment request arrives twice; two payment journals post. The invoice is double-paid, cash is overstated, and receivables go negative. Nobody notices until reconciliation — days or weeks later — and by then the bad entry is buried under everything posted since. In a ledger, a duplicate write isn't a duplicate row; it's an audit problem.

So the design constraint is simple: the write path must be safe to retry, because it will be retried.

The write model: safe retries, balanced or rejected

How a retry is handled depends on what you are writing:

  • Payments. POST /v1/invoices/{id}/payment and POST /v1/bills/{id}/payment accept an optional Idempotency-Key (1–128 characters, scoped to your company). Retrying with the same key and the same details returns the payment that was already recorded; the same key with different details returns 409. Without a key, every request is a new payment. The timeout scenario above resolves the way you'd want: the client retries with the same key, receives the result of the first write, and moves on.
  • Documents (invoices, bills, quotes, credit notes, purchase orders). Supply your own document_number on create. A second create with the same number, for the same document type in your company, is rejected with 400 and DUPLICATE_DOCUMENT_NUMBER instead of creating a duplicate. This makes a retry safe but not a replay: you get an error, not the original document, so read the document back. If you let Paprel assign the number, a retry creates a new document.
  • Journals and other writes. These are not deduplicated by key. If a journal post times out, check the ledger for the entry before retrying.

The second half of the model is what happens before anything reaches the ledger. Every journal — whether posted directly via POST /v1/accounting/journals or generated by an invoice, expense, payment, adjustment, or settlement — is validated for balance first. Debits must equal credits, or the write is rejected outright. There is no code path that lets an unbalanced entry through, and there is no "post now, fix later" mode.

Put together, the write path looks like this:

Reliable write pathFIG. 02
01 / Request

An accounting write

Check retry identity
02 / Retry guard

Seen before?

Payments: Idempotency-Key
Documents: document_number

New request · continue
03 / Balance validation

Debits = credits?

Balanced · continue
04 / Ledger write

The journal posts

Balanced, append-only records.

After the write
05 / Signed webhook

Notify downstream systems

HMAC-SHA256 over the timestamp and exact raw body.

PAPRELRetry guards apply when identities are supplied. Journals and other writes are not deduplicated by key: check the ledger before retrying.

The ordering matters. Validation happens before the ledger, so a rejected request leaves no partial state to clean up. The webhook fires after the write, so an event always describes something that actually happened in the books.

Webhooks: signed and verifiable

Webhook requests carry an HMAC-SHA256 signature in Webhook-Signature. Paprel signs the Unix timestamp, a period, and the exact raw request body with the endpoint secret. This lets downstream systems verify that the request came from a holder of that secret and that the payload was not altered in transit. An event that fails verification should be dropped, not processed.

Outgoing events carry their own timestamped signature, so the receiver checks integrity at the edge instead of assuming it. Writes into Paprel are authenticated by the bearer token, and payment recording accepts an Idempotency-Key so retries are safe. See Paprel Webhooks for Reliable Accounting Workflows for the complete receiver contract.

And because delivery is at-least-once, consumers should be idempotent too. The same property you rely on when writing to Paprel is the property your webhook handler owes its own database. The pattern is the standard one: process each event once by its identity — record the identity of every event you've handled, and when one arrives that you've already seen, acknowledge it and do nothing.

A useful litmus test: if every event arrived exactly twice, would your system's state be identical to receiving each one once? If yes, you've built it right.

Recovery beyond redelivery

What happens when a consumer is down for an hour and misses events?

Paprel retries failed deliveries automatically and lets operators resend a completed successful or failed delivery. A resend creates a new delivery record for the same immutable event and payload; it does not rewrite history. Paprel does not expose a public cursor-based historical event stream or silently backfill events missed while an endpoint was paused.

Webhooks remain a notification channel, not a source of truth. Treating delivery history as the authoritative record means correctness depends on perfect delivery bookkeeping—which is exactly the fragile dependency the ledger exists to make unnecessary.

The source of truth is the ledger, and it's fully readable:

  • GL export. The full general ledger is exportable as standard CSV / JSON — at any time, for any period, no engineering review. Every journal posted emits a signed webhook event, and the full history can be rebuilt any time from this export.
  • Journals read API. GET /v1/accounting/journals returns the journal list with filtering (date range, account, reference, and more — see the API reference), so a consumer can re-derive its state for any window programmatically.

So the recovery procedure after an outage is: note the window you were down, read the journals for that window (or pull the export for the period), and reconcile your local state against what the ledger says. Because your handler is idempotent by event identity, re-deriving state from the ledger and continuing to consume live webhooks can't conflict — anything you've already processed is a no-op. This is the same property auditors rely on: the books are reconstructible from the ledger itself, not from a log of notifications about it.

The contract, in one table

PropertyWhat it means for you
Safe retriesPayments: retry with the same Idempotency-Key to get the recorded payment. Documents: a repeated document_number is rejected as a duplicate. Journals: check the ledger before retrying
Balanced-or-rejectedUnbalanced journals never reach the ledger; rejections leave no partial state
Timestamped HMAC signaturesVerify origin and integrity over the exact raw request body before acting on any event
At-least-once deliveryBuild consumers that process each event once by identity
Automatic retries + operator resendRecover individual deliveries without changing the immutable event or payload
GL export + company-scoped APIsReconcile state from authoritative accounting data—the delivery log is not the source of truth

Where to go next:

Evaluate Paprel

Build in sandbox, launch with a production trial

Use sandbox for developer testing with no billing. When you are ready for real workflows, start production on a monthly plan with a 14-day free trial.

API-First Delivery
Audit-Ready Controls
Sandbox And Guided Rollout
We use cookies to improve your experience.

We use cookies and local storage for essential settings and, with your choices, analytics and advertising. Online identifiers and activity can be personal data. You can reject optional categories or change your choices.

These cookies are necessary for the basic functionality of the website, ensuring a seamless user experience. They cannot be disabled.