Skip to main content

once

Run any side effect exactly once — even when 1,000 callers demand it at the same instant.

1,000 concurrent duplicate charges, one execution

⚡ once — STORM DEMO
1,000 concurrent attempts to charge order #777 ($49.00)

ACTUAL EXECUTIONS   :      1   ← the whole point
served same answer  :  1,000 / 1,000
elapsed             :   0.1s

💰 double-spend prevented this run: $48,951.00

That's not a mock — it's a live attack you can run right now:

git clone https://github.com/aurumflux20/once-kernel && cd once-kernel
pip install -e . && python -m once.demo
# (`pip install once-kernel` lands with the PyPI release this week)

The problem

Networks retry. Users double-click. Queues redeliver. AI agents re-fire tools at machine speed. Any of these turns one payment into two, one email into three, one server into two hundred.

Most teams hand-roll an idempotency table — and most of those are quietly broken under concurrent load: two identical requests both pass the "already done?" check, then both execute. The bugs are subtle, the failures are money.

once is that table done right, once, for everyone — a tiny idempotency kernel with the four defenses hand-rolled versions miss:

  1. Atomic leader election — concurrent duplicates can't all pass the check; exactly one executes, the rest coalesce onto its result.
  2. Payload fingerprinting (RFC 8785) — same key with a different body is a hard IdempotencyConflict, never someone else's cached answer.
  3. Fence tokens + generations — a crashed worker's lease can be taken over, and when the "dead" worker wakes up late, it is locked out of corrupting the record.
  4. Honest failure states — a failed attempt frees the key for retry; an unknown outcome never silently re-runs.

Use it

from once import Once

o = Once()

def charge():
    return gateway.charge(order_id="ord_1", amount_cents=4900)

# Retries, double submits, webhook redelivery, agent fan-out → runs ONCE
result = o.run("pay:ord_1", {"order": "ord_1", "amount_cents": 4900}, charge)

Multi-worker production — share state through the Postgres you already run:

from once import Once
from once.pg import PostgresStore

o = Once(PostgresStore("postgresql://user:pass@host/db"))  # table auto-created

Async (FastAPI, agents) — sync side effects go to a worker thread, waiters park on the event loop (no thread-pool starvation under duplicate storms; there's a test that proves it):

from once import AsyncOnce

ao = AsyncOnce()
result = await ao.run("pay:ord_1", payload, charge)

→ The full 5-minute guide

What you can rely on

If this happens You get
Same key + same payload, again The stored result — no second execution
Same key + different payload IdempotencyConflict — never a silent wrong answer
1,000 concurrent first requests One executor; everyone else coalesces (wait=True) or is told to wait
Executing worker dies Lease expires → another caller takes over
"Dead" worker wakes up late Fenced out — cannot complete, cannot fail, cannot corrupt
Long job outliving its lease heartbeat() keeps it protected
Your function raises Key freed — a later retry may execute

The honest model (put this on a poster): exactly-once execution + at-least-once result delivery. True network exactly-once is physically impossible — libraries claiming it are lying to you. We execute once and re-deliver the answer as many times as asked.

Tested like money depends on it

Because it does. Every claim above is enforced by the chaos suite — barrier-forced thread storms, dead-lease reclaim stampedes, zombie-writer fencing, frozen-clock timeout attacks, event-loop-starvation detection — run against both the in-memory store and real PostgreSQL on every commit (CI fails loudly if the Postgres bench is skipped). Silence in CI never means "untested."

And we run it on our own production mailer — a double-approved send replays instead of double-emailing a real prospect. Dogfood first.

Not this

  • Not a payment provider — it guards your calls to one
  • Not a workflow engine (no sagas, no multi-key transactions — by decision)
  • Not magic "exactly-once everywhere" — see the honest model above

Docs

Apache-2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

once_kernel-0.1.0.tar.gz (78.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

once_kernel-0.1.0-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file once_kernel-0.1.0.tar.gz.

File metadata

  • Download URL: once_kernel-0.1.0.tar.gz
  • Upload date:
  • Size: 78.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for once_kernel-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e62a47f48315ab0fc7fe920f0512b868ffaa7705e6f456e0896c8c306df7fe9f
MD5 c6d4811bd9d747e62cb6ff3866a44bba
BLAKE2b-256 114b6ac08fdfcf3ba237deb8742055b73c899cce3e3f59bbdd26e5fcef58f3f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for once_kernel-0.1.0.tar.gz:

Publisher: publish.yml on aurumflux20/once-kernel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file once_kernel-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: once_kernel-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for once_kernel-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8dbde6a0e1e2244ed5e37fe17b49379a996e4a364fa6abb2e3d36e921ba68887
MD5 4e7971cd0ddf74e289f3822c7944e0cf
BLAKE2b-256 adc40d0218e2418a63bde79376c3a52d96fbecd1165d66c70e2321ee21b17ea7

See more details on using hashes here.

Provenance

The following attestation bundles were made for once_kernel-0.1.0-py3-none-any.whl:

Publisher: publish.yml on aurumflux20/once-kernel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page