Cloudflare Queues logo
Cloudflare D1 logo

Workflow template

Record order events from a queue once

Keep one D1 journal entry per order event, even when the producer sends the event twice.

How it works

Record order events from a queue once

1 Trigger · 1 Action
Cloudflare Queues1 · Trigger

Message received in a queue

Start a workflow when the consumer receives a message from the selected queue.

Cloudflare D12 · Action

Record the order event once

Run a statement with bound values, or send a batch. Each row in the results uses the column names from your query.

Before activation

Set up your workflow

  1. Prepare the event journal

    In your destination D1 database, run CREATE TABLE IF NOT EXISTS order_events (event_id TEXT NOT NULL PRIMARY KEY, payload TEXT NOT NULL). The primary key enforces one row per event even when deliveries overlap.

  2. Connect the queue and database

    In the queue trigger, choose the account and enter the source queue name. Attach the FastHook relay as its consumer. In “Record the order event once”, select the D1 database that contains order_events.

  3. Choose a stable event ID

    Send a JSON object such as {"event_id":"order-1007-paid","order_id":"1007"}. Reuse that event_id when retrying payment confirmation. Give a later event, such as shipment, its own ID.

  4. Verify a repeat delivery

    Activate the workflow and enqueue that same object twice. Check both workflow runs, then run SELECT COUNT(*) FROM order_events WHERE event_id = 'order-1007-paid'. The expected count is 1.

Explore connected apps