Search code examples
c#azureazure-functionsclass-libraryasp.net-core-6.0

Is it ok to use Azure Function App to perform multiple functionalities?


I have created a Azure function with QueueTrigger. Here I am planning to perform few functionalities whenever an entry is made to Azure queue via ASP.NET Core WebAPI Controller.

public void Run([QueueTrigger(QUEUE_NAME, Connection = "StorageConnectionString")] string queueMessage)
{
    _log.LogInformation($"Azure Function App call started...: {queueMessage}");
    
    // Connect to the database and fetch the data via Stored Procedure
    
    // Bind the data to Excel spreadsheet
    
    // Upload the spreadsheet to Azure Blob Storage and get the filename
    
    // Send a mail to the recepient including link to the filename
    
    _log.LogInformation($"Azure Function App call completed...: {queueMessage}");
}

I created a separate classlibrary project which contains functionalities required for this above Azure Function App. I added reference to classlibrary project to the Azure Function App and did a validation with one functionality to send mails.

I wanted to know is it a good practice to accomplish a list of functions within a single Azure Function App or are there any other good options.

Can anyone provide their guidance regarding this scenario?


Solution

  • I don't think it is a good practice, I think functions should be kept simple and repeatable in case something goes wrong. You can stretch the Single-responsibility principle a bit but in this case I think you have gone too far. Imagine the mail server is down for some reason and sending mails fail every time. Your function will be requeued and will have to fetch the data, bind the excel and upload the spreadsheet over and over just to fail again when sending the mail. There is a lot of compute and storage lost, possibly orphaned files even if you don't account for it. So I would at least split it up in two and create another trigger when the file is posted to the blob storage and let another function handle the email sending in this case. My two cents.