TL;DR - Azure Event Grid is here - In this first article we'll have a look at what it is, dive into the details and have a look at certain new scenarios.
Last week Microsoft announced Azure Event Grid (Preview), an event-driven service that allows you to stitch together all your components and design event-driven architectures.
Next to the built-in support for several Azure services you can also provide your own custom topics & custom webhooks that fix your needs.
By using a combination of filters & multicasting, you can create a flexible event routing mechanism that fits your needs by for example sending event A to one handler, while event B is being multicasted to multiple handlers. You can read more about this here.
Azure resources can act as Event Publishers where they send a variety of events to Event Grid. By using Event Subscriptions you can then subscribe to those events and send them to an Event Handler.
The main scenarios for Azure Event Grid are serverless architectures, automation for IT/operations and integration:
- Serverless Architectures - Trigger a Logic App when a new blob is uploaded
- Operations - Listen & react on what happens in your subscription by subscribing to Azure Subscription changes
- Integration - Extend existing workflows by triggering a Logic App once there is a new record in your database
- Custom - Create your own by using application topics (aka custom topics)
The pricing for Azure Event Grid is fairly simple - You pay $0.60 per million operations and you get the first 100k operations per month for free. Operations are defined as event ingress, advanced match, delivery attempt, and management calls. Currently you only pay $0.30 since it's in public preview, more information on the pricing page.
Basically you can see Azure Event Grid as an extension service that allows you to integrate Azure Services with each other more closely while you also have the flexibility to plug in your own custom topics.
Let's have a closer look at what it has to offer.
Diving into Azure Event Grid
Event Handling at Scale
Azure Event Grid is designed as an high scalable eventing backplane which comes with some serious performance targets:
- Guaranteed sub-second end-to-end latency (99th percentile)
- 99.99% availability
- 10 million events per second, per region
- 100 million subscriptions per region
- 50 ms publisher latency for batches of 1M
These are very big numbers which also indirectly have impact on the way we design our custom event handlers. They will need to be scalable and protect them selves from being overwhelmed and should come with a throttling mechanism.
But then again, designing for the cloud typically means that each component should be highly scalable & resilient so this should not be an exception.
Durable Message Delivery
Every event will be pushed to the required Event Handler based on the configured routing. For this, Azure Event Grid provides durable message delivery with an at-least-once delivery.
By using retries with exponential backoff, Event Grid keeps on sending events to the Event Handler until it acknowledges the request with either an HTTP 200 OK or HTTP 202 Accepted.
The Event Handler needs to be capable of processing the event in less than one minute, otherwise Event Grid will consider it as failed and retry it. This means that all Event Handlers should be idempotent to avoid creating invalid state in your system.
However, if your Event Handler is unable to process the event in time and Event Grid has been retrying for up to 24h, 2h in public preview, it will expire the event and stop retrying.
In summary, Event Grid guarantees an at-least-once delivery for all your events but you as an Event Handler are still in charge of being capable of processing the event in time. This also means that it should be able to preserve performance when they are dealing with load spikes.
It is also interesting to see what really happens with the expired events. Do they really just go away or will there be a fallback event stream to which they are forwarded for later processing? In general, I think expiration of events will work but in certain scenarios I see a case where having the fallback event stream being valuable for mission critical eventing flows.
You can read more on durable message delivery here.
How about security?
Azure Event Grid offers a variety of security controls on all levels:
- Managing security on the Event Grid resource itself is done with Role-based Access Control (RBAC). It allows you to define granular control to the correct people. It's a good practice to use the least-priviledge principle, but that is applicable to all Azure resources. More information here.
- Webhook Validation - Each newly registered webhook needs to be validated by Azure Event Grid first. This is to prove that you have ownership over the endpoint. The service will send a validation token to the webhook, which the webhook implementer needs to send back as a validation. Important to note that only HTTPS webhooks are supported. More information here.
- Event Subscription uses Role-based Access Control (RBAC) on the Event Grid resource where the person creating a new subscription needs to have the Microsoft.EventGrid/EventSubscriptions/Write permissions.
- Publishers need to use SAS Tokens or key authentication when they want to publish an event to a topic. SAS tokens allow you to scope the access you grant to a certain resource in Event Grid for a certain amount of time. This is similar to the approach Azure Storage & Azure Service Bus use.
The current security model looks fine to me, although it would be nice if there would be a concept of SAS tokens with a stored access policy, similar to Azure Storage. This would allow us to issue tokens for a certain entity, while still having the capability to revoke access in case we need this, ie when a token was compromised.
An alternative to SAS stored access policies would be to be able to create multiple authorization rules, similar to Azure Service Bus, where we can use the key-approach for authentication while still having the capability to have more granular control over whom uses what key and being able to revoke it for one publisher only, instead of revoking it for all publishers.
You can read more on security & authentication here.
Imagine the possibilities
Integration with other Azure services
As of today there are only a few Azure services that integrate with Azure Event Grid but there are a lot of them coming.
Here are a couple of them that I would love to use:
- Use API Management as a public-facing endpoint where all events are transformed and sent over to Azure Event Grid. This would allow us to use API Management as a webhook proxy between the 3rd party and Azure Event Grid. More on this later in the post.
- Streamlined event processing for Application Insights custom events where it acts as an Event Publisher. By doing this we can push them to our data store so that we can use it in our Power BI reporting, instead of having to export all telemetry and setting up a processing pipeline for that, as described here.
- Real-time auditing & change notifications for Azure Key Vault
- Publish events when a new version of a Key or Secret was added to notify dependent processes about this so they can fetch the latest version.
- Real-time auditing by subscribing to changes on the access policies
- Sending events when alerts in Azure Monitor are triggered would be very useful. In the past I've written about how using webhooks for processing alerts instead of emails are more interesting as you can trigger an automation workflow such as Logic Apps. If an alert would send an event to Azure Event Grid we can take it even a step further and create dedicated handlers per alert or alert group. You can already achieve this with Logic Apps & Service Bus Topics as of today but with Event Grid this comes out of the box and makes it more easy to create certain routings.
- Trigger a Azure Data Factory when an event occurs, ie. when a blob was added to an Azure Storage container.
- Send an event when Azure Traffic Manager detects a probe that is unhealthy
New way of handling webhook events?
When we want to provide 3rd parties to send notifications to a webhook we need to provide a public endpoint that which they can call. Typically, these just take the event and queue them for later processing allowing the 3rd party to move on as we handle the event at our own pace.
The "problem" here is that we still need to host an API middleware somewhere; be it an Azure Function, Web App, Api App, etc; that just takes handles this message. Even if you use Azure API Management, you still need to have the middleware running behind the API Management proxy since you can't push directly to a topic.
Wouldn't it be nice if we can get rid of that host and let API Management push the requests directly to Azure Event Grid so that it can fan-out all the external notifications to the required processors?
That said, this assumes that you don't do any validation or other business logic before the webhook middleware pushes to the topic for processing. If you need this capability, you will have to stick with hosting your own middleware I'm afraid.
Unified integration between APIs
Currently when you are using webhooks inside your infrastructure the Event Publishers are often calling webhooks directly creating a spaghetti infrastructure. This is not manageable since each Event Publisher needs to have the routing logic inside their own component.
By using Azure Event Grid we can route all the events through Azure Event Grid and use it as an event broker, or routing hub if you will, and thus decoupling Event Publisher from the corresponding Event Handlers.
By doing this we can easily change the way we route events to new Event Handlers by simply changing the routing, not the logic in the Event Publishers.
Depending on the monitoring Azure Event Grid will provide, it can also provide a more generic approach in how we monitor all the event handling instead of using the monitoring on each component. More on this later on.
Depending on the load, you can of course also use Azure Service Bus Topics but all depends on the load you are expecting. As always, it depends on the scenario to pick which technology is best for the scenario.
Azure Event Grid is a unique service that has been added to Microsoft Azure that brings a lot to the table. It promises big performance targets and will enable new scenarios, certainly in the serverless landscape.
I'm curious to see how the service will evolve and what publishers & handlers will be coming soon. Personally, I think it's a big announcement and will give it some more thinking on how we can use it when building platforms on Microsoft Azure.
Want to learn more yourself? Here's a good Cloud Cover episode that will give you a high-level overview of Azure Event Grid or read about the concepts of Event Grid.
What features would you like to see being added to the service? In what scenarios do you see Event Grid as a good fit? Feel free to mention them in the comments!
Thanks for reading,