Recursive Workflow Failing at 4th Iteration

As stated in the title. I have used this same recursive workflow technique multiple times in other apps before. The use case is when you need to iterate over a list inside of a workflow, and want to ensure the operation has been completed before continuing on within that workflow.

To accomplish this, I follow these steps:

  1. Set up internal API call to my own backend, within which I pass through a JSON array of children objects.

  2. Call the same workflow recursively using the iteration < total children condition.

What’s odd in this app is that if I pass in 3 or fewer children, it works great. As soon as I pass in a 4th, it fails the recursive call, giving error Request too deep.

I have recorded a loom on this here: Loom | Free Screen & Video Recording Software | Loom

Note: when I call the exact same API from Postman, it works with 4. So this seems to be a bubble problem.

Bubble generally discourages that way of recursion, though I don’t know if there’s an official depth limit stated in documentation.
What bubble suggests is to use Schedule Workflow or Schedule Workflow on a List actions instead of recursive calls. Here is the doc: Recursive API workflows - Bubble Docs
This limitation is the result of the fact that each action in a workflow runs in an AWS Lambda environment. When you run into a true recursion, each previous call keeps its environment running until all subsequent calls complete. Scheduling works differently allowing previous lambda instance to release resources before the next will start. This approach lacks control over potential delays that may appear between subsequent calls, but that’s what we have at the moment, if I don’t miss anything.

P.S.: And what you’ve missed in your video is to watch server logs. They might put some light on your problem.

Right, but that entire approach fails if I need to use the result of that entire operation in the subsequent step in a workflow. It’s fine if we don’t care that it’s async. But in this case, I need to know that the operation has concluded before moving forward.

By the way, and I know this doesn’t directly address your question, what’s the reason for wanting this recursion to happen? It looks like you’re just creating a new thing for each call - is it definitely not possible in one go with the bulk data creation API?

1 Like

You know what, I’ve totally forgotten about the bulk creation API. This is perfect. Thanks George!

1 Like