Microflow call in Nanoflow

0
Hi All,   In Mendix Academy I've encountered a piece of information described in the screenshot below, and it got me thinking.                          Question 1: If it is best practice to not use Nanoflows for server-side actions, why would you then at all consider calling a Microflow from a Nanoflow?   Question 2: According to documentation, the execution of Nanoflow actions is different from Microflow actions execution: Nanoflow actions are executed directly and don't wait for the end of the Nanoflow. Microflow actions are always executed at the end of the Microflow. Based on the above two given facts, what happens when a Sub-Microflow is called from a Nanoflow? Are all the Sub-Microflow actions executed directly like the actions inside the parent Nanoflow? Meaning that they are executed directly without waiting for the end of that Sub-Microflow. Or do the actions inside the Sub-Microflow still execute at the end of that Sub-Microflow? Meaning that the Sub-Microflow actions are processed first and completed at the end, after which the logic jumps back to the parent Nanoflow and considers the Sub-Microflow as a completed action without waiting for the Nanoflow to end as well?   Couldn't really find an answer to this anywhere, so I thought I share it here! Cheers!
asked
2 answers
1

Answer 1:

While it is best practice not to perform server actions at all in a nanoflow, the reality is that some server actions are required, and indeed they are supported. It then becomes a matter of finding the right balance. This is also where the option to call a microflow comes in, as it allows you to make one call to the server, which then performs a variety of server actions. This is better then having all the individual server actions in your nanoflow because each server action in a nanoflow is a separate call to the server.

 

Answer 2:

In the above answer, I've already alluded to the answer to this question but let me elaborate. Each microflow runs in something called a transaction. Any changes to your data will either be committed to the database at the end of the microflow or will be rolled back and essentially disappear if your microflow runs into errors. Since nanoflows do not run on the server, each server interaction runs in it's own transaction and is therefore committed to the database once the action completes, regardless of whether the nanoflow has completed or not.

 

Let me show you a simple example:

shoppingcartorder.png

 

If this is executed as a microflow, you would either get an order with an orderline per product in your shoppingcart, or nothing.

 

If however you execute this as a nanoflow, it would depend on when your flow runs into an error. If it would be at the third product, you would have one order and two order lines.

 

I hope this helps you understand the difference. Feel free to ask any additional questions.

answered
0

Hi Lennaert,

 

Thanks for the answer.

I understand the difference between a Microflow and Nanoflow in the way their transactions work, but my questions was really about how their transactions work when they are combined?

 

For instance: what would happen if the microflow in your example screenshot was executed as a SUB-Microflow from within a Nanoflow? Would this SUB-Microflow still adhere to its original transaction principles, or would this now suddenly be changed because the calling flow is a Nanoflow? :)

 

Cheers!

answered