Architecture & contracts

Keep retries
recoverable.

Stripe and your database cannot share a transaction. SafeStripe records identity, ownership and progress so your application can recover deliberately when one side succeeds and the other disappears.

The transaction boundaries

A little durable state
at each uncertain boundary.

  1. 1

    Authorize the intent

    Your app checks the user, tenant, customer and approved price.

    operationId + intent
  2. 2

    Record the operation

    Store its identity and terms before the supported Stripe mutation.

    stable Stripe key
  3. 3

    Admit the webhook

    Verify the original bytes and scope, then persist before acknowledgment.

    durable inbox
  4. 4

    Claim with a lease

    Workers hold expiring ownership tokens. Another worker can reclaim work.

    lease + token
  5. 5

    Commit the effect

    SafeStripe records, the business guard and outbox intent share a transaction.

    state + effect + outbox

Outbox delivery is at least once. The downstream receiver must deduplicate its stable delivery key. External services do not join the database transaction.

Five contracts

What the library protects.
Where the protection ends.

01

One operation keeps its identity.

A lost response must not turn the same business request into a new mutation. Caller-supplied operation IDs bind the scope, kind and parameter fingerprint; completed retries reuse the recorded resource.

Boundary: keep local history and retry before the configured cutoff. Restored or missing history requires reconciliation.

Mechanism, tests and limits →
02

Admission precedes acknowledgment.

Verified, supported webhook work is saved before the receiver returns success. A persistence failure reaches the HTTP adapter so Stripe can retry.

Boundary: this relies on the durability of your database. It cannot preserve work erased by a restore or destructive retention.

Mechanism, tests and limits →
03

A crashed worker does not own work forever.

Expiring leases allow recovery. Ownership tokens prevent a stale worker from committing after the job has been reclaimed.

Boundary: a worker and available storage must return. Tokens fence database completion, not arbitrary external calls already in progress.

Mechanism, tests and limits →
04

One committed effect per business key.

Different Stripe events can describe the same outcome. effectOnce guards a business key inside the serializable state transaction, beyond event-ID deduplication.

Boundary: handlers can execute again. Do not send email, mutate Stripe or call another service inside the retried transaction callback.

Mechanism, tests and limits →
05

State and downstream intent commit together.

The outbox intent shares the state and effect transaction. A dispatcher can resume delivery after a process disappears.

Boundary: delivery may repeat. The recipient needs its own guard. Unrelated application tables do not automatically join SafeStripe's portable transaction.

Mechanism, tests and limits →

Failure testing

The worker actually disappears.

The chaos suite starts child processes, kills a worker after claim or during the effect transaction, and recovers with another process. PostgreSQL CI also runs twenty competing workers. These tests use synthetic events; Stripe sandbox verification is recorded separately.

Inspect the process tests ↗
Process recovery · asserted state
Worker A claims the job
SIGKILL ends the process
Lease expires
Worker B recovers and commits

completed jobs     1
business effects   1
outbox intents     1

Illustrated sequence; see the test source and CI for execution evidence.