You're absolutely right that Azure Logic Apps does not support local variables inside loops that run concurrently, and this limitation can indeed complicate workflows that require concurrent processing with dynamic state per iteration.
Why This Happens
Azure Logic Apps does not have true "local variables" scoped to a specific loop iteration, especially when using concurrent execution (like with the Concurrency control set to a value > 1). This is primarily due to:
✅ 1. Statelessness and Asynchronous Execution
Azure Logic Apps is built on a stateless, asynchronous, and distributed architecture, especially when running in the multi-tenant (Consumption) plan.
- Each iteration of a concurrent loop runs independently and possibly on different nodes.
- There is no shared memory or local state preserved across iterations.
- Variables in Logic Apps are scoped to the entire workflow run, not to a specific loop iteration.
So, if you're using a For each loop with concurrency enabled, all iterations share the same variable namespace. This makes tracking per-iteration state difficult unless you manage it yourself (e.g., using arrays or dictionaries indexed by loop item).
✅ 2. Design Philosophy: Simplicity Over Complexity
Azure Logic Apps was designed to be a low-code/no-code platform for integration workflows.
- The goal was to abstract away complexity of distributed computing, not expose it.
- Introducing local variables per iteration would require:
- Scoping rules
- State management per iteration
- Possibly more complex debugging and logging
This would make the tool less approachable for non-developers.
✅ 3. Limitation of the Workflow Engine
The underlying workflow engine (called Azure Logic Apps Workflow Engine) does not support dynamic variable scoping per iteration.
- All variables are global to the workflow run.
- Even if you try to simulate local scope, you must manage it manually (e.g., using an object array or a dictionary keyed by some unique ID).
✅ 4. Concurrency vs. Sequential Execution
When you enable concurrency in a loop, Logic Apps uses parallel branches under the hood.
- Each branch runs independently.
- There's no guaranteed execution order.
- So, trying to mutate or read shared variables across these branches leads to race conditions.
This is why variables cannot be safely used in concurrent loops — there's no thread-safety or locking mechanism.
🛠️ Workarounds
While this is a known limitation, here are some common workarounds:
1. Use Append to an Array Variable
You can initialize an array variable before the loop and append results to it. Each iteration can process data independently and append its own result.
Initialize variable: resultsArray (Type: Array)
For each item in items:
- Do something with item
- Append result to resultsArray
2. Use a Dictionary with Unique Keys
Use a unique identifier (e.g., item ID) as a key in a dictionary to store per-iteration data.
Initialize variable: resultsDict (Type: Object)
For each item in items:
- Set resultsDict[item.id] = result
3. Call Child Logic Apps
Each loop iteration can trigger a separate Logic App (child), which can have its own variables scoped to that run.
- This allows full isolation of state.
- Adds latency and cost, but can scale well.
4. Use Azure Functions
Offload complex per-iteration logic with local state to an Azure Function, which can handle concurrency safely.
🧠 Summary
| Aspect | Why It Matters |
|---|
| Stateless Architecture | Loop iterations may run on different nodes |
| Shared Variables | All iterations share the same variable space |
| Concurrency Risks | Race conditions if variables are mutable |
| Design Philosophy | Simplicity over developer control |
| No Variable Scoping | No local variables per loop iteration |
✅ Conclusion
Yes, this is a deliberate design decision based on:
- Azure Logic Apps' low-code focus
- The distributed, asynchronous nature of the service
- The need to avoid race conditions and simplify debugging
While it complicates concurrent workflows, the workarounds (like arrays, dictionaries, child apps, or offloading to functions) allow you to manage per-iteration state manually.
If you're building complex, concurrent workflows with local state needs, consider whether Azure Durable Functions or Power Automate + custom code might be a better fit.
Let me know if you'd like examples of these workarounds in practice!