How to reuse a SQL connection inside Azure Durable Functions?

Rosa Junior, Carlos 20 Reputation points
2025-06-03T14:19:24.64+00:00

I have a Function App in python and I need it to collect data from SAP HANA. I use hdbcli to establish connection. What I want to do is run multiple queries in parallel using the same connection, is it possible using fan-out/fan-in pattern?
Also, can I reuse the same connection throughout different executions of the function? How?

I thought of something like this:

@bp.activity_trigger(input_name="config")
def sap_hana_metrics(config):
    """
    Activity function to run a SAP HANA SQL query and return formatted metrics.
    :return: List of metrics extracted from the HANA query results.
    """
	hana_client = config["client"]
	query = config["query"]
    data = hana_client.fetch_all_dict(query)

    return data

Then I would call this activity with an orchestrator for different queries, but I know the activity cannot receive a non JSON-serializable object, and the connection object is one.

Any ideas?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,844 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Khadeer Ali 5,570 Reputation points Microsoft External Staff Moderator
    2025-06-03T14:58:24.4266667+00:00

    @Rosa Junior, Carlos
    Thanks for reaching out.
    In Azure Durable Functions, while you can implement the fan-out/fan-in pattern to run multiple queries in parallel using orchestrator and activity functions, reusing a hdbcli.Connection object across different activity executions is not supported.

    This is because:

    Durable Functions require all data passed between functions to be JSON-serializable, and database connections are not.

    Each activity function runs in isolation, potentially on different compute instances, and does not share memory or state.

    Azure Functions documentation recommends reusing static clients only when they are thread-safe and designed to manage connections internally (e.g., HttpClient, CosmosClient). Reference: Azure Functions best practices – Reuse client instances

    As hdbcli.Connection is not documented as thread-safe or connection-pooled, it is not suitable for reuse across multiple activity executions.

    Instead, we recommend establishing a new connection within each activity function invocation using the necessary credentials or config parameters. Hope this helps. Do let us know if you have any further queries.


    If this answers your query, do click Accept Answer and Yes for "Was this answer helpful." And if you have any further questions, let us know.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.