All articles

A Retry Limit Per Step Is Not a Retry Budget

Why "retry three times" can still mean twelve calls, and what I would bound instead.

Diagram in four zones: the key and the retry budget at intake, systems A and B where the reply is lost, a dashed after-a-timeout zone with the failed store and a reconcile step, and two results, complete or needs review.
Follow the red path after the timeout. The reconcile step decides between the two results, and the budget travels with the message the whole way.

Lately I have been reading through a legacy WSO2 Micro Integrator estate, file by file. It was a source audit only. I did not run anything on a Micro Integrator runtime, and I did not reproduce any incident. So, everything below is what the code says could happen, not what did happen.

One finding stayed with me. Failed messages were sent to a failed store, and a processor later returned them to the primary flow. Each visit had its own retry limit, and each limit looked fine. However, a limit per visit does not give you a limit for the whole request.

Simply put, a retry limit counts attempts inside one visit. A retry budget counts attempts for the whole life of one request, across every visit.

Where does the limit leak?

Here is a made-up order flow, so no real system is involved. The integration calls system A to reserve stock. Then it calls system B to create the invoice. System A answers in time. System B times out.

The flow retries system B three times, which is the limit per visit. All three fail, so the message goes to the failed store. A processor picks it up later and sends it back to the start of the primary flow. Now the counter is zero again. The flow calls system A again, then system B three more times.

Think of a shop assistant who is told "try the supplier three times, then put the order in the tray". Every morning someone moves the order from the tray back to the desk. The assistant starts counting from one again. Nobody is breaking the rule, and the order is still never closed.

So, in this example, three laps mean three calls to system A and nine to system B. If system B is slow because it is already busy, those extra calls add to the load. That extra load is the part that worries me most. Nobody has to change the flow for this to grow, because the loop only needs the message to keep coming back.

There is a second problem. The timeout does not tell you whether system B created the invoice or not. It only tells you that the answer did not arrive. If the flow sends the call again, you may get two invoices.

What does a budget look like?

You should bound two things, attempts and age. Both live on the message, not in the step.

  • A total attempt count that goes up on every call and is never reset when the message returns to the primary flow.
  • A first-seen time. After a set age, for example a few hours, the message stops retrying and waits for a person.
  • A clear final state, such as "needs review", so the message does not go back into the loop.

The numbers depend on your systems. You should start small and ask the people who own system B how much load it can take. Then you can change the numbers with a real answer in your hand.

The audit finding was that a per-visit limit does not establish a lifetime retry budget. The recommendation was to bound total attempts and age, and to reconcile an uncertain response before you resend. I think that is a fair rule for any platform, not only Micro Integrator.

Where does the idempotency key go?

An idempotency key is a label the caller makes once for the request and sends with every attempt. System B uses it to know that attempt two is the same order as attempt one.

You should create the key at intake, before the first call to either system. Do not create it inside the retry step, because then every retry gets a new key and the protection is gone. Store the key with the attempt count and the first-seen time.

Before a resend, ask system B what happened to that key. If it says the invoice exists, mark the request complete and do not send it again. If it says it knows nothing, then sending again is safe. If you cannot ask it, treat the answer as unknown and let a person decide.

The report also lists a gateway journey test on the new target. It checked authenticated intake, a retry that carries the same identity, a conflict when the same key comes with a changed request, a completed delivery, and no resend after that. These are early pilot checks. They do not prove a lifetime attempt count, and they do not make the pilot production-ready.

What should the records show?

After one timeout, you should see at most one invoice in system B, one stock reservation in system A, and a message with an attempt count above one. If the numbers do not match, the budget is not working yet.

I will test this with a small simulation of the worst case: system B creates the invoice, and then its reply is lost, so the caller only sees a timeout. I will also run a case where system B is simply down.

Run Calls to A Calls to B Invoices in B Final state
Limit per visit, 3 laps lab result needed lab result needed lab result needed lab result needed
Budget with key, max age lab result needed lab result needed lab result needed lab result needed
Budget, system B down lab result needed lab result needed lab result needed lab result needed

Lab result needed. I have not run this lab yet. I will run it later and fill in the table, so please read the empty cells as a plan, not a result.

The migration notes are in the public WSO2 Micro Integrator upgrade documentation, and the WSO2 migration assistant is on GitHub.

One thing to try this week

Pick one flow that calls two systems. Draw the path a failed message takes, from the first call to the failed store and back. Then write down where the attempt count lives and whether it survives the return trip. If it does not, you have found the same gap I found in the code.

In my earlier article, What Changes When You Move a WSO2 MI Flow to Ballerina?, I followed one event through the move. This article picks up the retry part of that story.

Next time I will read a WSO2 support table: Your WSO2 Version Has an End Date. How I Read the Support Table.