Hello Vaibhav Gupta
Azure Event Grid is a fully-managed event routing service that enables you to build event-driven applications with ease. You can use Azure Event Grid to route events from any source to any destination, and you can use it to build reactive applications that respond to events in real-time.
Regarding your question, Azure Event Grid can be used to receive VM events such as termination or Spot VM evictions events. You can create an Event Grid subscription to listen to these events and take appropriate actions based on the events received**.**
However, unlike AWS, Azure does not have a built-in mechanism to deliver VM events to Event Grid in real-time. You can use Azure Monitor to collect VM events and send them to Event Grid, but this is not a real-time solution.
Regarding your concern about polling inside the VM each second to know the events, you can use Azure Event Grid's retry policy to ensure that events are not lost in case of abrupt machine failure. Azure Event Grid will retry sending the event to the subscriber for a configurable amount of time before giving up.
Regarding your use case of launching multiple VMs in an availability zone, you can create an Event Grid subscription to listen to events from all the VMs in the availability zone. You can use the same approach as you would for a scale set placement group.
Hope this helps.