---
title: Best practices for using subflows
description: Follow these best practices when using subflows.
component: davinci
page_id: davinci:davinci_best_practices:davinci_best_practices_subflows_using
canonical_url: http://docs.pingidentity.com/davinci/davinci_best_practices/davinci_best_practices_subflows_using.html
revdate: May 22, 2024
section_ids:
  send-a-json-response-for-the-subflows-end-state: Send a JSON Response for the subflow's end state
  use-styling-rules-from-the-parent-flow: Use styling rules from the parent flow
  use-the-appropriate-capability-for-the-subflow: Use the appropriate capability for the subflow
  minimize-the-number-of-layers-subflows-calling-other-subflows: Minimize the number of layers (subflows calling other subflows)
  avoid-multiple-branches-leading-to-a-single-subflow: Avoid multiple branches leading to a single subflow
  dont-loop-subflows: Don't loop subflows
---

# Best practices for using subflows

Follow these best practices when using subflows.

## Send a JSON Response for the subflow's end state

If the subflow completes successfully, end the subflow with an HTTP node set to the **Send Success JSON Response** capability. In the parent flow, the flow conductor node that launched the subflow then evaluates to true.

If the subflow completes unsuccessfully, end the subflow with an HTTP node set to the **Send Error JSON Response** capability. In the parent flow, the flow conductor node that launched the subflow then evaluates to false.

The **Send Custom JSON Response** capability isn't recommended for use in subflows. If a subflow ends with a node that uses this capability, the flow conductor node that launched the subflow always evaluates to true.

If you plan to use a custom JSON response to conclude a subflow and you need to return a success or error condition, use a variable to store the condition, then use an evaluation node in the parent flow if you need to make branching decisions based on the variable's value.

For example, to use a custom variable in that HTTP node to indicate that the use case is an error response, use `IS_MFA_Required_Response=false`.

Redirect-based nodes, such as the **Return Success Response (Redirect)** capability of the **PingOne Authentication** connector, aren't recommended as terminal nodes in subflows. Redirect-based nodes redirect the browser, so the parent flow doesn't receive a response from the subflow if the subflow ends with a redirect-based node. You should put redirect-based nodes in the parent flow instead.

## Use styling rules from the parent flow

Avoid defining CSS in a subflow. Instead, set the styles in the flow settings of the parent flow. You can override the flow-level CSS by defining CSS for individual nodes if you need those nodes to have a different appearance.

## Use the appropriate capability for the subflow

When you invoke a subflow, use the appropriate capacity for the type of subflow:

* Use the **Invoke UI Subflow** capability if the subflow contains user interface nodes. Verify that every possible user path includes at least one user interface node.

* Use the **Invoke Subflow** capability if the subflow doesn't contain user interface nodes.

## Minimize the number of layers (subflows calling other subflows)

Because each subflow has a performance cost, avoid solutions that require subflows to reference other subflows. Don't exceed five levels of depth. Instead, design a single parent flow that references multiple subflows in sequence.

## Avoid multiple branches leading to a single subflow

If more than one branch leads to a single subflow node, the subflow might not consistently launch the correct number of times. If each branch must conclude with a subflow invocation, include a separate node for each invocation.

## Don't loop subflows

If your flow invokes a subflow, make sure that the subflow doesn't invoke the parent flow.
