Malik Kashmiri
Malik Kashmiri

Reputation: 5851

Azure Function Best Practices

Detail

I am new to azure function. I am trying to create azure Function to send (email,sms and notifications). I firstly create 3 different functions Http triggered for this. My question is there is a good way to create a generic function for all of the above mentioned function as one function and is it a good way to do this.

Upvotes: 1

Views: 1297

Answers (1)

Paul Batum
Paul Batum

Reputation: 8415

It is hard to provide an answer for this because it will usually depend on the details of your application but I can provide this general guidance:

  1. You'll end up with a more reliable system if you make each function do the smallest amount of work possible. So to take your example, having separate functions for sending email, sms and push notifications is a good approach as a failure in any one of those paths will not prevent the others from working.

  2. Where possible, connect multiple functions together with queues. Try to only use HTTP when you have a client that requires a response of some sort.

I'm going to make some assumptions about your scenario so that I can illustrate an example. Lets say you need to expose a HTTP triggered function to send a notification. A design that maximizes reliability might look something like this:

  1. A HTTP triggered function recieves a payload with a target user and message and writes this to a notify queue then returns OK to client
  2. A queue triggered function reading from the notify queue then looks up notification addresses from db/cache, writes messages to sms queue, email queue, push queue as appropriate.
  3. Separate queue triggered functions for sms, email and push each read from their queue and then make the call to the appropriate service, using the address details written into the message.

Upvotes: 5

Related Questions