Best practice for initiating Azure Function from another Azure Function

Question

I have a scenario where I have 2 functions, let's say Function A and Function B.

Currently, Function A and Function B both have the same logic for logging failed activity where metadata is logged to Table Storage and JSON to Blob Storage.

Edit --> Function A and Function B are in two different Function Apps (intended). Function A is on a Consumption plan and Function B is on an App Service plan.

First question - would it make sense to create a Function C and take the failed activity logging logic from both A and B and put it in C?

This removes code duplication and the logic is in one place which is easier to manage.

Second question - what would be the best way to call Function C from A and B?

I have read here that it is best to use a Storage Queue or Service Bus for cross communication between Functions. The problem I have is - the JSON I need to store will in most cases exceed 256KB so I can't put it on a queue to trigger a Function.

So, could Function C be a HTTP trigger and I send a request containing all of my relevant information needed to log via HTTP from Function A and B?

Is there any reason not to do this?

Many thanks.

Solution

For future reference (and for those who may find this question via web searching), we've built a new Durable Functions extension to Azure Functions which allows calling one function from another. Your specific problem could potentially be coded up as follows:

public static async Task<object> Run(DurableOrchestrationContext ctx)
{
    try
    {
        var result = await ctx.CallActivityAsync<object>("FunctionA");
        var y = await ctx.CallActivityAsync<object>("FunctionB", result);
        return y;
    }
    catch (Exception e)
    {
        // error handling/compensation goes here
        await ctx.CallActivityAsync<object>("FunctionC", e);
        return null;
    }
}

FunctionA and FunctionB are activity functions that can live in the same function app. The function above which schedules them is an orchestrator function. Both Consumption and App Service plans are supported.

Under the covers the CallActivityAsync method sends a message via a Azure Storage queue to trigger the specified function by name. Large messages are supported by automatically switching to a combination of queues and blobs to ensure they can be delivered reliably.

One important constraint, however, is that FunctionA and FunctionB must be defined in the same function app. For that reason, it's not an exact match for your question. It's a great solution for those who can keep their functions in the same function app, however.

Official Documentation: https://docs.microsoft.com/en-us/azure/azure-functions/durable-functions-overview

GitHub: https://github.com/Azure/azure-functions-durable-extension