By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
The support agent clicks Approve in the Harbor Supply console, and the refund graph pauses nowhere new — it is already paused, waiting for that decision. What the click produces is an event. The approval endpoint must not resume the graph inline: the customer's agent should not wait on graph execution, and an HTTP request that dies halfway through a resume leaves both the request and the refund in an unknown state. The endpoint publishes a command and returns; a worker consumes it and resumes the thread.
A queue changes the durability story without changing the state story. The checkpoint still holds the channel values and the pending node; the queue holds the instruction to continue. Each has a failure mode the other cannot fix: a durable checkpoint with a lost command sits paused forever, and a redelivered command without an idempotent resume can approve twice. Event-driven graphs are therefore an exercise in at-least-once delivery plus exactly-once command handling.
Keep the message small and the state authoritative. A resume command needs the thread id, the interrupt it answers, the decision, who made it and when, plus a message id from the transport. The message must not carry a copy of the graph state: a stale copy would compete with the checkpoint, and the consumer would have to decide which one wins. The consumer reads the checkpoint, validates the command against it, and resumes.
from collections import deque
# The queue delivers at least once, so a consumer must survive a redelivery.
QUEUE = deque(
[
{"id": "msg-1", "thread": "thread-c91", "cmd": "resume:approved"},
{"id": "msg-1", "thread": "thread-c91", "cmd": "resume:approved"},
{"id": "msg-2", "thread": "thread-c91", "cmd": "resume:approved"},
]
)
SEEN_DELIVERIES: set[str] = set()
RESUMED: set[str] = set()
def consume(message: dict[str, str]) -> str:
"""Acknowledge only after the resume command is recorded once."""
if message["id"] in SEEN_DELIVERIES:
return "ignore: duplicate delivery"
SEEN_DELIVERIES.add(message["id"])
intent_key = f"{message['thread']}:{message['cmd']}"
if intent_key in RESUMED:
return "ignore: duplicate command"
RESUMED.add(intent_key)
return "resume graph"
for message in QUEUE:
print(message["id"], "->", consume(message))
print("resumes:", len(RESUMED))Two different duplicates are being handled, and both matter. The first is transport-level: the same message id arrives twice because the consumer did not acknowledge before it crashed. The second is business-level: msg-2 is a new delivery with a new message id, but it requests the same approval for the same interrupt, because the agent double-clicked and the endpoint published twice. Deduplication on the message id alone would let the double click through; deduplication on the command key alone would reprocess a redelivery as if it were new work. A durable consumer records both keys before acknowledging.
Ordering deserves one more sentence, because it is where event systems quietly break graphs. If an approval for thread thread-c91 and a cancellation for the same thread are delivered to different workers, the final state depends on which finished last. Partitioning by thread id turns that race into a queue with one consumer per key. The graph still needs its own guard — a resume that finds the thread no longer paused records the command as stale instead of forcing it — but the queue does the cheap part first.
Not every event should start a graph. Events that answer a pause resume a thread; events that begin new work start a fresh run on a fresh thread. Mixing the two is how a webhook creates a duplicate conversation, so decide the mapping explicitly and give each row a dedupe key.
| Event | Graph action | Dedupe key |
|---|---|---|
| New customer message | Start a new run on a new thread | Message id |
| Approval or rejection | Resume the paused thread with the decision | Thread id plus interrupt id plus decision |
| Vendor callback (charge settled) | Resume, or update_state if the graph is between nodes | Callback event id |
| Deadline timer | Resume with an explicit timeout decision | Thread id plus deadline id |
Key takeaways
The queue carries commands and the checkpoint carries state; the consumer reads the thread, validates the command and resumes instead of copying state into the message.
At-least-once delivery plus exactly-once handling means two dedupe layers: the transport message id for redeliveries and the business command key for genuine duplicates.
Partition by thread id so commands for one conversation are ordered and never processed concurrently, and let the graph record stale commands rather than forcing them.
Acknowledge only after the resume is durably recorded, keep the visibility timeout above the longest resume, and dead-letter commands that keep failing.
Decide explicitly which events start a new run and which resume a paused one; that mapping plus its dedupe key is the event contract.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.