I've got a function app (say FunctionA, and expected to be a single instance) which writes into a queue. This queue is bound as the trigger for another function App (say FuntionB) which is expected to consume from this queue.
I do not expect for queue messages to be written in bursts of more than 10 or 20 (in the worst case). Given this, if FunctionB is scaled/auto-scaled, is it guaranteed for each instance to handle just one message each? TL;DR: Is it possible for more than one instance to have been fed the same message from the queue?
CodePudding user response:
if FunctionB is scaled/auto-scaled, is it guaranteed for each instance to handle just one message each
Guaranteed? NO.
If you have 10 instances of functionB, the function app will be processing 10 messages from the queue concurrently, and the instances are independent of each other. Now assuming you have 20 messages in the queue at the time the auto-scale was applied, it doesn't necessary mean that each of the function app will process 2 messages each. It's possible and very likely that one instance from the function can process 3 message while another instance process only 1 message.
It all depends on how long it takes an instance to process a message it consumed. So it's non-deterministic as far as I know.
CodePudding user response:
TL;DR: Is it possible for more than one instance to have been fed the same message from the queue?
What queue are we talking about, azure storage queues or azure service bus queues? Both offer at-least-once delivery guarantees. but azure service bus also offers at-most-once delivery. See the docs for more details.
Anyway, at-least-once delivery means messages can be delivered more than once and doesn't necessarily only occur on scale out. Also, it could be that, in case of duplicate messages, one instance will handle both but it can also be that another instance will handle the message.
To be on the safe side always write idempotent message handling.