Log inBook a Demo
BuildMidBackendAuto-graded

Stop a redelivered message from being handled twice

Redelivered messages trigger the side effect again; handle each id once and still retry a delivery that failed.The message queue delivers at least once. When the broker doesn't get an ack in time, it sends the same message again with the same id. Today every redelivery runs the side effect again, so customers get charged twice. Make consume() handle each message id once and give every redelivery the original result. A delivery whose handler raised was never processed, so a later redelivery has to run it again.
30 min
python

You're done when

  • The handler runs once for a message, however many times it is redelivered.
  • Every redelivery returns the same response as the first delivery.
  • That response is the stored result of the first run, not a freshly computed one.
  • Two messages with different ids are each handled once, even when their payloads are identical.
  • Two messages with different ids get their own results, and a redelivery of either returns its own original.
  • When the handler fails, the error reaches the caller.
  • A delivery whose handler failed is not counted as processed, so the next redelivery runs the handler again.
  • Once a message that failed succeeds on a later delivery, further redeliveries are deduplicated as usual.

What it measures

Event-driven architectureStaying correct when the broker sends the same message more than once.
Resilience engineeringWhether a failed delivery stays retryable while a completed one is never repeated.
State designRecording only work that actually finished.

Your environment

Terminal + editorA full shell in the browser
Claude CodePre-authenticated, no key setup
Isolated microVMYours alone, wiped afterwards

Start this lab

30 min
Start labYou'll sign in to Anthropos to start. The lab opens in a private cloud workspace with Claude Code ready to use.
AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo