Flexible spacing provides automatic variation of line spacing and/or paragraph spacing in the selected part of text. This topic explains on an example how these two types of spacing interact one with each other.
1- On the figure, the first column show four paragraphs of text with line spacing of 10pt and no paragraph spacing. As you can see, the text is aligned on the 10pt grid. No flexible spacing is applied in the first column, and the text flows in natural way. It is too short for the frame height, thus the frame border is red - text is not fitting.
2- On all four paragraph in the second column, we applied the flexible paragraph spacing of 10pt. See Fit text by setting flexible paragraph spacing for the step-by-step procedure. Since the column is too high for the amount of text, all 10pt were applied between paragraphs, but the value was not enough - text is still not fitting. Note: since the spacing is equal to the grid, the lines are still aligned to it. But, if there will be more text, or if the column would be shorter, the effective paragraph spacing could take any value between 0 and 10pt, thus, the lines would not "sit" on the grid anymore.
3-In the third column, we increased the fitting "power", by enabling also a 10pt flexible line spacing. See Fit text by setting flexible leading for the step-by-step procedure. Now, the text is fitting, and the frame border turned to blue. But, perhaps we're still not satisfied. Since by design the line spacing has the priority over paragraph spacing, GN4 first applied the line spacing up to the maximum allowed amount (10pt), and then it added some paragraph spacing. Note that it is not possible to invert the priority - the line spacing is always applied first.
4-In the fourth column, we used a small trick as a work-around for the problem, found in the third column. We have set the line spacing to 1pt, while keeping the paragraph spacing on 10pt. in that way, the space added between lines was 1/10 of the space added between paragraphs, so it looked like GN4 first applied the paragraph spacing. But, unfortunately, the total allowed amount was not enough to fit the text.
5-In the fifth column, we set InfA for the paragraph spacing, and kept 1pt for the line spacing. in that way, the space added between lines could not be more than 1pt, while between paragraphs GN4 added as much as it was needed.
Note: when you set both variable line spacing, and variable paragraph spacing, line spacing has a priority over paragraph spacing. It is not possible to change that priority explicitly, but you can use a simple trick instead: set the line spacing to smaller value than the paragraph spacing, e.g. 1/10: in that way, the space added between lines will be 1/10 of the space added between paragraphs.
See also Distribute flexible spacing evenly.