For parallel execution in Node, should i use the functional API?

in graph api

# Parallel processing of multiple data sources
workflow.add_node("fetch_news", fetch_news)
workflow.add_node("fetch_weather", fetch_weather)
workflow.add_node("fetch_stocks", fetch_stocks)
workflow.add_node("combine_data", combine_all_data)

# All fetch operations run in parallel
workflow.add_edge(START, "fetch_news")
workflow.add_edge(START, "fetch_weather")
workflow.add_edge(START, "fetch_stocks")

# Combine waits for all parallel operations to complete
workflow.add_edge("fetch_news", "combine_data")
workflow.add_edge("fetch_weather", "combine_data")
workflow.add_edge("fetch_stocks", "combine_data")

in this example,Different nodes fetch different data sources.

my question is

if i have some items to fetch news,What should I do?

I have two ideas:

  1. in one node,use ThreadPoolExecutor Control concurrency

2 like this pic, use functional api

Which method is better? or others ?

Any help would be greatly appreciated.

1 Like