reliable webhook outbox

    by Karim Hoceine

    1

    Transactional outbox for Python/SQLite apps ensuring at-least-once webhook delivery with idempotency and signing.

    $5

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    reliable webhook outbox

    Example session with this skill installed

    Add a reliable outbox to my FastAPI app so that every new order in the 'orders' table triggers a webhook to my shipping provider without duplicates.

    • Read your context and instructions
    • Compiled the reliable webhook outbox

    I have integrated the transactional outbox pattern into your FastAPI application. The implementation ensures that order creation and webhook enqueueing occur within a single atomic transaction.

    Webhook Outbox Implementation

    I have added app/outbox.py, app/worker.py, and app/signing.py. The create_order endpoint now uses an idempotency key to prevent duplicate orders and enqueues the shipping notification as part of the database transaction.

    
    # app/main.py snippets
    from app import outbox, worker
    
    @app.on_event("startup")
    async def startup():
        # Initialize the outbox tables in your existing SQLite DB
        outbox.init(db_connection)
        # Start the background worker
        asyncio.create_task(worker.run_loop(db_connection, target_url=SHIPPING_API_URL))
    
    @app.post("/orders")
    async def create_order(order_data: OrderSchema, idempotency_key: str = Header(...)):
        async with outbox.tx(db_connection) as tx:
            # Check for existing idempotency key to prevent duplicates
            if not outbox.is_new_request(tx, idempotency_key, order_data.json()):
                raise HTTPException(status_code=409, detail="Duplicate request")
            
            # Save order and enqueue webhook in one transaction
            db.save_order(tx, order_data)
            outbox.enqueue(tx, event_type="order.created", payload=order_data.dict(), key=idempotency_key)
        
        return {"status": "accepted"}
    

    The worker is now configured to POST signed requests. It will only mark events as delivered if the shipping provider returns a JSON receipt containing {"processed": true, "event_id": <id>}.

    Next steps

    1. Update your .env with a WEBHOOK_SECRET for request signing.
    2. Run the newly created tests/test_outbox.py to verify the retry and lease logic.
    3. Configure your shipping provider endpoint to verify the X-Outbox-Signature header.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Reliable systems shouldn't require heavy infrastructure like RabbitMQ or Celery for simple lead intake or order flows. When a naive process dies between saving a record and calling a webhook, you lose data, or worse, you repeat actions when a client retries.

    This skill implements a transactional outbox pattern specifically for Python apps using FastAPI and SQLite. It ensures that business data and the notification event are committed in a single atomic transaction. It includes a worker implementation with leased delivery, exponential backoff, and dead-letter handling for failed events.

    What it does

    • Atomic Persistence ensures events are enqueued only if the business transaction succeeds.
    • Leased Delivery prevents multiple workers from claiming the same event via locking mechanisms.
    • Signed Envelopes secures communication using timestamped signatures to prevent tampering.
    • Idempotency Control rejects duplicate client requests and prevents re-running processed effects.
    • Dead Letter Management holds failed events for manual intervention after retries are exhausted.
    • Status Monitoring provides counts for pending, delivered, and dead-letter events.

    How it works

    1. Integration of reference files into the project and initialization of the outbox within the existing database.
    2. Transaction Wrapping of the business logic and event enqueueing inside an atomic block.
    3. Worker Deployment of an asyncio loop that claims, signs, and POSTs payloads to external endpoints.
    4. Receipt Validation to ensure deliveries are acknowledged by the receiver before marking as complete.
    5. Testing via an included test suite to verify the outbox under simulated failures.

    Frameworks & tools Python, FastAPI, SQLite, and httpx. The implementation relies on standard library asyncio for the worker and pytest for verification.

    Why this beats prompting it yourself Prompting often fails to handle the nuances of BEGIN IMMEDIATE locks in SQLite, leading to race conditions. This skill enforces strict transactional rules and signature verification that are difficult to prompt consistently from scratch.

    Use cases

    • Triggering n8n or Zapier workflows from a local database event.
    • Syncing new signups to a CRM without risking data loss during downtime.
    • Sending order confirmations where double-processing must be avoided.
    • Managing reliable API notifications in low-resource environments.

    Known limitations Does not guarantee strict global ordering during retries. Requires httpx and pytest dependencies. Designed for single-machine SQLite; Postgres requires specific locking modifications.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Frequently Asked Questions

    This skill provides a transactional outbox implementation that ensures webhooks are sent exactly when a database change is saved. It solves the 'dual-write' problem where an app might save a record but crash before the webhook is fired, or fire the webhook but fail to record the success.

    It is designed for Python applications using FastAPI and SQLite. While optimized for local or single-server environments, the code can be adapted for other Python frameworks that support asyncio and standard SQL transactions.

    You receive a complete reference implementation including the database schema, the transactional wrapper logic, the worker loop for processing events, and a comprehensive test suite to verify reliability in your environment.

    The skill includes a 'Leased Delivery' mechanism using SQLite's locking features to ensure that even if you run multiple worker instances, they won't clash or send the same webhook twice.

    The skill implements signed envelopes with timestamped signatures, allowing your destination (like n8n or a custom API) to verify that the payload came from your app and hasn't been tampered with or replayed.

    This implementation is specifically tuned for SQLite's 'BEGIN IMMEDIATE' locking behavior to prevent race conditions. While the logic is portable, it would require specific modifications to the locking syntax to work with Postgres or MySQL.

    New in APIs & Backend

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.