<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Azure Event Grid on Jeppe Spanggaard - Software Developer | .NET, Azure &amp; Microsoft 365</title><link>https://jeppe-spanggaard.dk/tags/event-grid/</link><description>Recent content in Azure Event Grid on Jeppe Spanggaard - Software Developer | .NET, Azure &amp; Microsoft 365</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Wed, 25 Nov 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://jeppe-spanggaard.dk/tags/event-grid/index.xml" rel="self" type="application/rss+xml"/><item><title>Alerting on Event Grid Dead-Letters When the Portal Says No</title><link>https://jeppe-spanggaard.dk/blogs/event-grid-dead-letter-alerts/</link><pubDate>Wed, 25 Nov 2026 00:00:00 +0000</pubDate><guid>https://jeppe-spanggaard.dk/blogs/event-grid-dead-letter-alerts/</guid><description>Learn how to get alerts on dead-lettered Event Grid events from a partner topic using diagnostic settings, Log Analytics, and a log search alert.</description><content:encoded><![CDATA[<p>My mail pipeline had been running for a while: Graph notifications flowing through an <a href="https://jeppe-spanggaard.dk/blogs/graph-mail-events-event-grid-partner-topic/">Event Grid partner topic</a> into an Azure Function, <a href="https://jeppe-spanggaard.dk/blogs/event-grid-dead-letter-blob-setup/">dead-lettering enabled to a blob container</a>. Solid setup, one missing piece. If delivery ever failed for 24 hours straight and events started dead-lettering, nobody would know. The blobs would just sit there, quietly, being lost mail.</p>
<p>So, easy fix. Partner topics expose a <code>DeadLetteredCount</code> metric, and Azure has metric alerts. Metric, alert, action group, done in five minutes.</p>
<p>Except the topic&rsquo;s menu has no Alerts entry at all. Every other Azure resource has one; this one goes straight from Metrics to Diagnostic settings. Trying through Azure Monitor instead just spells out why: &ldquo;Event Grid Partner Topic isn&rsquo;t supported for metric alerts.&rdquo;</p>
<p>The metric exists. You can chart it. You just can&rsquo;t alert on it. Yeah. About that.</p>
<p><img src="https://jeppe-spanggaard.dk/images/event-grid-dead-letter-alerts-1_hu_d9e3ff8254ae3e32.webp" srcset="/images/event-grid-dead-letter-alerts-1_hu_d9e3ff8254ae3e32.webp 271w" sizes="(max-width: 760px) 100vw, 720px"
    width="271" height="486"
    alt="Partner topic menu with no Alerts entry under Monitoring" loading="lazy" decoding="async"></p>
<h2 id="route-the-metric-to-log-analytics-instead">Route the Metric to Log Analytics Instead</h2>
<p>If the alert can&rsquo;t come to the metric, the metric can go somewhere alerts work: a Log Analytics workspace.</p>
<p>On the partner topic, add a diagnostic setting: check <strong>AllMetrics</strong>, destination <strong>Send to Log Analytics workspace</strong>, and pick the same workspace your Application Insights already writes to. That last part is deliberate - one workspace means one place to query, and the companion alert later in this post lives in the same workspace for free.</p>
<p><img src="https://jeppe-spanggaard.dk/images/event-grid-dead-letter-alerts-2_hu_500dc5badc542135.webp" srcset="/images/event-grid-dead-letter-alerts-2_hu_ec956d077d5cb595.webp 480w, /images/event-grid-dead-letter-alerts-2_hu_500dc5badc542135.webp 720w" sizes="(max-width: 760px) 100vw, 720px"
    width="720" height="399"
    alt="Diagnostic settings exporting AllMetrics" style="background:url(data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAABwAwCdASoYAA0AP1mMt0upJKKYBACTFYT0gAAzImcSC6MFngAA/tMaYiE8EvgA) center/cover no-repeat" loading="lazy" decoding="async"></p>
<p>From then on, every metric on the topic lands as rows in a table called <code>AzureMetrics</code>, and log search alerts can chew on that.</p>
<h2 id="the-azuremetrics-table-that-isnt-there-yet">The AzureMetrics Table That Isn&rsquo;t There Yet</h2>
<p>Here&rsquo;s the gotcha that cost me a confused half hour: <code>AzureMetrics</code> doesn&rsquo;t exist until the first exported row arrives. The table is created lazily, around 15 minutes after the diagnostic setting starts producing data. And it only produces data if the topic has traffic.</p>
<p>The failure mode is a loop: you can&rsquo;t create the alert rule because the table doesn&rsquo;t exist, and the table doesn&rsquo;t exist because nothing has happened yet. If your topic is quiet, send a test event through it (a test mail, in my case), wait for the export, and confirm with:</p>
<pre tabindex="0"><code class="language-kusto" data-lang="kusto">AzureMetrics
| take 10
</code></pre><p>Once that returns rows, you&rsquo;re in business.</p>
<h2 id="the-dead-letter-alert-that-matters">The Dead-Letter Alert That Matters</h2>
<p>New alert rule on the workspace, with this query:</p>
<pre tabindex="0"><code class="language-kusto" data-lang="kusto">AzureMetrics
| where MetricName == &#34;DeadLetteredCount&#34;
| where Total &gt; 0
</code></pre><p><strong>What&rsquo;s happening here?</strong></p>
<ol>
<li>The exported metric rows carry the metric name and its aggregations as columns. <code>Total</code> is the sum for the time grain, so any row with <code>Total &gt; 0</code> means at least one event was dead-lettered in that slice.</li>
<li>The condition is &ldquo;any rows at all&rdquo;: measure <strong>Table rows</strong>, aggregation <strong>Count</strong>, granularity <strong>10 minutes</strong>, operator <strong>Greater than</strong>, threshold <strong>0</strong>, evaluated every <strong>5 minutes</strong>. The 10-minute window with 5-minute evaluation overlaps on purpose, so nothing falls between checks.</li>
<li>The threshold is <strong>static</strong>, and it should be. The portal offers a Dynamic option right next to it, and it&rsquo;s the wrong choice here: dynamic thresholds learn a baseline and alert on deviation, which makes sense for metrics with a natural rhythm. The natural rhythm of dead-letters is zero. Any dead-letter is an incident, not an anomaly.</li>
</ol>
<p>For the rule details: severity 1 (a dead-letter means mail was lost after every retry Event Grid had), auto-resolve on so the alert closes itself when the query goes quiet, and 30 to 60 minutes of mute time - one poison batch can dead-letter a burst of events, and one email carries the same information as twelve. Wire it to an action group that emails whoever should care.</p>
<p>One more tip: put the runbook in the alert description. Mine says where the dead-letter container is and how to replay from it, because the person reading the alert email at 2 AM is future me, and future me does not want to do archeology. The blobs contain the full original event plus a <code>deadLetterReason</code>, and since Event Grid is <a href="https://jeppe-spanggaard.dk/blogs/what-is-azure-event-grid/">a router, not a queue</a>, replay is a DIY script that reads the blob and feeds it back through the handler&rsquo;s service class.</p>
<p><img src="https://jeppe-spanggaard.dk/images/event-grid-dead-letter-alerts-3_hu_e0a5cde4a313712.webp" srcset="/images/event-grid-dead-letter-alerts-3_hu_d7a892092639554f.webp 480w, /images/event-grid-dead-letter-alerts-3_hu_e0a5cde4a313712.webp 720w" sizes="(max-width: 760px) 100vw, 720px"
    width="720" height="595"
    alt="Alert condition with the KQL query and threshold" style="background:url(data:image/webp;base64,UklGRjwAAABXRUJQVlA4IDAAAAAwAwCdASoYABQAP1mgwlYpJaOhqAgBJisJ6QAAM6PR4nWAAP7eQbbQ&#43;GnGS1oAAAA=) center/cover no-repeat" loading="lazy" decoding="async"></p>
<h2 id="the-early-warning-alert-that-fires-first">The Early-Warning Alert That Fires First</h2>
<p>The dead-letter alert has a built-in flaw: it&rsquo;s the fire alarm that goes off after the house burnt down. Event Grid retries for roughly 24 hours before dead-lettering, which means by the time <code>DeadLetteredCount</code> ticks up, the problem is a day old.</p>
<p>The early warning lives in Application Insights, which is already recording every failed function invocation:</p>
<pre tabindex="0"><code class="language-kusto" data-lang="kusto">AppRequests
| where Name == &#34;MailEventHandler&#34;
| where Success == false
</code></pre><p>Condition: count of rows over a 1-hour window, threshold greater than 5, evaluated every 15 minutes. Severity 2, same action group.</p>
<p>If the handler starts failing - bad deploy, expired certificate, downstream outage - this fires within the hour, while Event Grid is still patiently retrying and no mail has been lost yet. The dead-letter alert becomes what it should be: the confirmation that you ignored the first alert for a day.</p>
<p>The threshold of 5 per hour instead of &ldquo;any failure&rdquo; is deliberate. The occasional transient failure is exactly what Event Grid retries exist to absorb; a failure a minute is a pattern. Tune it to your traffic.</p>
<h2 id="what-the-alerts-cost">What the Alerts Cost</h2>
<p>Nearly nothing, but not literally nothing:</p>
<ul>
<li>The dead-letter rule at 5-minute frequency is about $1.50 a month; the early-warning rule at 15-minute frequency about $0.50.</li>
<li>The exported metrics are a trickle - well under half a GB a month for one topic - and ingestion has a free tier that mine disappears into. Even billed, it&rsquo;s pennies at ~$2.30/GB.</li>
<li>Emails from the action group: first 1,000 a month free, and if you&rsquo;re sending more than that you have bigger problems than the bill.</li>
</ul>
<p>Call it $2-3 a month for not silently losing mail. I&rsquo;ve spent worse.</p>
<h2 id="gotchas">Gotchas</h2>
<ul>
<li><strong>The metric existing doesn&rsquo;t mean you can alert on it.</strong> Chart works, alert doesn&rsquo;t. Check resource type support before designing your monitoring around a metric.</li>
<li><strong><code>AzureMetrics</code> appears lazily.</strong> No traffic, no table, no alert rule. Seed the topic with a test event and wait ~15 minutes before creating the rule.</li>
<li><strong>Overlap your windows.</strong> A 10-minute window checked every 5 minutes double-covers; a 5-minute window checked every 10 leaves holes exactly where your incident will land.</li>
<li><strong>Auto-resolve is not the default mindset.</strong> Without it, someone has to close every fired alert by hand, and alerts nobody closes become alerts nobody reads.</li>
<li><strong>The dead-letter alert alone is not monitoring.</strong> It tells you about mail that&rsquo;s already lost. Pair it with a failure alert upstream so you get a 23-hour head start.</li>
</ul>
<h2 id="wrapping-up">Wrapping Up</h2>
<p>Partner topics won&rsquo;t do metric alerts, so export the metrics to where alerts do work: diagnostic settings into Log Analytics, a static-threshold log search alert on <code>DeadLetteredCount &gt; 0</code>, and an early-warning alert on handler failures that fires while Event Grid is still retrying. Rule of thumb: alert on the failure while it&rsquo;s still retryable, and treat the dead-letter alert as the postmortem bell.</p>
]]></content:encoded></item><item><title>Where Events Go to Die: Dead-Lettering Event Grid to Blob Storage</title><link>https://jeppe-spanggaard.dk/blogs/event-grid-dead-letter-blob-setup/</link><pubDate>Fri, 20 Nov 2026 00:00:00 +0000</pubDate><guid>https://jeppe-spanggaard.dk/blogs/event-grid-dead-letter-blob-setup/</guid><description>Learn how to set up dead-lettering for Azure Event Grid to a blob container, what the dead-letter blobs contain, and how to replay lost events.</description><content:encoded><![CDATA[<p>When I wired up <a href="https://jeppe-spanggaard.dk/blogs/graph-mail-events-event-grid-partner-topic/">Graph mail notifications through an Event Grid partner topic</a>, enabling dead-lettering was one sentence and one checkbox, and I moved on. Storage account, container, done. A safety net I&rsquo;d hopefully never look at.</p>
<p>Then I asked myself an uncomfortable question: what exactly happens to a mail event when my function is broken for a day? I knew the headline answer - &ldquo;Event Grid retries for 24 hours, then dead-letters&rdquo; - but not the details. Which failures retry and which don&rsquo;t? What&rsquo;s actually in the container? How do I get an event <em>out</em> again?</p>
<p>Turns out the details matter, because the default answer to &ldquo;what happens to undeliverable events&rdquo; is not &ldquo;they wait in the dead-letter container&rdquo;. It&rsquo;s &ldquo;they&rsquo;re gone&rdquo;.</p>
<h2 id="the-last-stop-before-gone">The Last Stop Before Gone</h2>
<p>Recall the mental model from <a href="https://jeppe-spanggaard.dk/blogs/what-is-azure-event-grid/">the intro post</a>: Event Grid is a router, not a queue. Events aren&rsquo;t stored; they&rsquo;re either delivered or they&rsquo;re not. When a delivery fails, Event Grid retries on a backoff schedule - 10 seconds, 30 seconds, 1 minute, 5, 10, 30, then hourly stretches up to the 24-hour mark.</p>
<p>When the retries run out, one of two things happens:</p>
<ul>
<li><strong>Dead-lettering configured</strong>: the event is written to your blob container, with diagnostics attached.</li>
<li><strong>No dead-lettering</strong>: the event is dropped. No log, no trace, no recovery.</li>
</ul>
<p>That second bullet is the whole argument for this post. Dead-lettering is off by default, and a pipeline without it treats every prolonged outage as silent data loss. The container is the lost-and-found box for your events - and if you don&rsquo;t put the box out, Azure throws lost items straight in the bin.</p>
<h2 id="turning-it-on">Turning It On</h2>
<p>Two prerequisites: a storage account and a container in it (mine is named <code>mail-events-deadletter</code>). Then, on the event subscription - not the topic - enable dead-lettering and point it at the container. In the portal it lives on the event subscription&rsquo;s configuration page under <strong>Additional Features</strong> → Dead-lettering.</p>
<p><img src="https://jeppe-spanggaard.dk/images/event-grid-dead-letter-blob-setup-1_hu_f8e4a21eac078374.webp" srcset="/images/event-grid-dead-letter-blob-setup-1_hu_fb977a402c7fcc7d.webp 480w, /images/event-grid-dead-letter-blob-setup-1_hu_f8e4a21eac078374.webp 720w" sizes="(max-width: 760px) 100vw, 720px"
    width="720" height="201"
    alt="Dead-letter settings on an event subscription pointing at a blob container" style="background:url(data:image/webp;base64,UklGRjwAAABXRUJQVlA4IDAAAAAQAwCdASoYAAcAP1mKtkspJKKYBACTFYT0gAAzJP3R5gAA/tM/KqUYYHSXBLWgAAA=) center/cover no-repeat" loading="lazy" decoding="async"></p>
<p>Via CLI it&rsquo;s the <code>--deadletter-endpoint</code> parameter, which takes the container&rsquo;s resource path:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>az eventgrid partner topic event-subscription update <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span>  --name es-mail <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span>  --partner-topic-name &lt;partner-topic-name&gt; <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span>  --resource-group rg-my-app <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span>  --deadletter-endpoint <span style="color:#e6db74">&#34;/subscriptions/&lt;subscription-id&gt;/resourceGroups/rg-my-app/providers/Microsoft.Storage/storageAccounts/&lt;storage-account&gt;/blobServices/default/containers/mail-events-deadletter&#34;</span>
</span></span></code></pre></div><p>Do it per subscription: I have two (mail handler + reauthorization handler), and both dead-letter to the same container. If you use a managed identity for dead-lettering, the identity needs a blob data role on the storage account, or the writes silently fail.</p>
<p>While you&rsquo;re on that blade, the retry policy knobs live next door: <strong>maximum delivery attempts</strong> (1-30, default 30) and <strong>event time-to-live</strong> (1-1440 minutes, default the full 24 hours). Whichever limit hits first wins. I left both at default - for mail, I want every minute of retrying I can get.</p>
<h2 id="not-everything-waits-24-hours">Not Everything Waits 24 Hours</h2>
<p>Here&rsquo;s the detail that changed how I think about the container. The 24-hour schedule only applies to failures that are worth retrying. Some HTTP responses tell Event Grid the delivery will <em>never</em> succeed, and those skip the queue:</p>
<ul>
<li><strong>400 Bad Request</strong> and <strong>413 Request Entity Too Large</strong> are never retried - the event is scheduled for dead-lettering immediately.</li>
<li><strong>403 Forbidden</strong> isn&rsquo;t retried either.</li>
<li>For plain webhook endpoints, <strong>401 Unauthorized</strong> also means no retries. For Azure resource endpoints (like a Function), 401 gets retried on a slow schedule - which once saved my mail pipeline from an auth misconfiguration, but that&rsquo;s a story for a later post.</li>
</ul>
<p>So the dead-letter container isn&rsquo;t only a &ldquo;24 hours later&rdquo; archive. A poison event - one your handler rejects with a 400 every time - can be sitting in blobs within minutes of publishing. Which is great news for debugging: the evidence arrives while the incident is still warm.</p>
<p>One more wrinkle: an endpoint that keeps failing gets put in <em>probation</em>, where Event Grid pauses deliveries entirely for a cooldown. During probation, events can be dead-lettered or dropped without a delivery attempt. The system protects itself; your container catches the fallout.</p>
<h2 id="anatomy-of-a-dead-letter-blob">Anatomy of a Dead-Letter Blob</h2>
<p>The blobs land in your container under a path that includes the topic and subscription names, batched into JSON arrays. Each event is the original CloudEvent, untouched, plus four diagnostic fields bolted on:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-json" data-lang="json"><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;specversion&#34;</span>: <span style="color:#e6db74">&#34;1.0&#34;</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;id&#34;</span>: <span style="color:#e6db74">&#34;8f0f0e58-2c5e-4c4a-9f5e-4a1b2c3d4e5f&#34;</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;source&#34;</span>: <span style="color:#e6db74">&#34;/tenants/&lt;tenant-id&gt;/applications/&lt;app-id&gt;&#34;</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;type&#34;</span>: <span style="color:#e6db74">&#34;Microsoft.Graph.MessageCreated&#34;</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;data&#34;</span>: { <span style="color:#f92672">&#34;subscriptionId&#34;</span>: <span style="color:#e6db74">&#34;&lt;graph-subscription-id&gt;&#34;</span>, <span style="color:#f92672">&#34;...&#34;</span>: <span style="color:#e6db74">&#34;...&#34;</span> },
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;deadletterreason&#34;</span>: <span style="color:#e6db74">&#34;MaxDeliveryAttemptsExceeded&#34;</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;deliveryattempts&#34;</span>: <span style="color:#ae81ff">18</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;lastdeliveryoutcome&#34;</span>: <span style="color:#e6db74">&#34;TimedOut&#34;</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;publishtime&#34;</span>: <span style="color:#e6db74">&#34;2026-11-18T09:14:32.4018726Z&#34;</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p><strong>What&rsquo;s happening here?</strong></p>
<ol>
<li>The original event is intact - envelope, payload, everything. Replay needs nothing else.</li>
<li><code>deadletterreason</code> says why it ended up here: <code>MaxDeliveryAttemptsExceeded</code> or <code>TimeToLiveExceeded</code> for exhausted retries, and client-error reasons for the immediate cases.</li>
<li><code>lastdeliveryoutcome</code> is the last thing your endpoint said (or didn&rsquo;t): <code>TimedOut</code>, <code>BadRequest</code>, <code>Unauthorized</code>, <code>SocketError</code>, and a dozen more. This field usually points straight at the root cause.</li>
<li><code>deliveryattempts</code> tells you whether this was a slow 24-hour death (high number) or an instant rejection (1). Two very different bugs.</li>
</ol>
<p>Two timing facts to save you a confused debugging session: there&rsquo;s a <strong>five-minute delay</strong> between the last failed attempt and the blob appearing (Event Grid batches the writes), so don&rsquo;t panic when it&rsquo;s not there instantly. And if the dead-letter storage itself is unreachable for <strong>four hours</strong>, the event is dropped after all - the safety net has its own safety limit.</p>
<h2 id="getting-events-back-out">Getting Events Back Out</h2>
<p>There&rsquo;s no replay button. The container is storage, not a queue, so getting an event back into your pipeline is a do-it-yourself exercise - by design, since only you know whether replaying is safe.</p>
<p>My approach: a small dev endpoint that takes a dead-lettered blob, strips the four diagnostic fields, deserializes the CloudEvent, and calls the same service class the real trigger uses. The handler can&rsquo;t tell the difference, and every validation (clientState, decryption, dedupe) runs exactly as it would have the first time. That last part matters - because delivery is at-least-once, the handler was already built to survive seeing an event twice, and replay leans on the same idempotency.</p>
<p>If you&rsquo;d rather not build anything: for low volumes, reading the blob and POSTing its event to the local trigger endpoint (the <code>aeg-event-type: Notification</code> trick from <a href="https://jeppe-spanggaard.dk/blogs/graph-mail-events-event-grid-partner-topic/">the setup post</a>) works fine as a manual rescue.</p>
<h2 id="gotchas">Gotchas</h2>
<ul>
<li><strong>Off by default means dropped by default.</strong> No dead-letter destination, no second chances. This is the first thing to configure after the subscription itself, not a hardening task for later.</li>
<li><strong>The blob takes five minutes to appear.</strong> Testing dead-lettering and staring at an empty container is normal for the first few minutes. Wait before concluding it&rsquo;s broken.</li>
<li><strong>The container holds real payloads.</strong> My events carry encrypted mail content, but the envelope metadata is still there in plaintext. Lock the container down like production data, and put a lifecycle policy on it so blobs expire after a sensible retention window instead of accumulating forever.</li>
<li><strong>A poison event dead-letters fast and repeatedly.</strong> If your handler 400s on a malformed payload, every occurrence of that payload lands in the container within minutes. A suddenly busy container can mean one bug, not one outage.</li>
<li><strong>Storage can fail too.</strong> Four hours of unreachable dead-letter storage and events are gone anyway. One more reason the storage account should be boring, local, and free of clever networking.</li>
</ul>
<h2 id="wrapping-up">Wrapping Up</h2>
<p>Dead-lettering is the difference between &ldquo;Event Grid gave up&rdquo; and &ldquo;Event Grid gave up, and here&rsquo;s the event, the reason, and the last response your endpoint sent&rdquo;. One container, one checkbox per subscription, five minutes of setup. Rule of thumb: a router doesn&rsquo;t store anything for you, so give every event subscription a place to put the events it couldn&rsquo;t deliver - before the first outage, not after.</p>
<p>Next question: how do you find out the container is filling up without staring at it? That&rsquo;s the alerting post, coming up next.</p>
]]></content:encoded></item><item><title>Graph Mail via Event Grid Partner Topics: No Webhook Needed</title><link>https://jeppe-spanggaard.dk/blogs/graph-mail-events-event-grid-partner-topic/</link><pubDate>Sun, 15 Nov 2026 00:00:00 +0000</pubDate><guid>https://jeppe-spanggaard.dk/blogs/graph-mail-events-event-grid-partner-topic/</guid><description>Learn how to deliver Microsoft Graph mail notifications to an Azure Function through an Event Grid partner topic, with no public webhook or handshake.</description><content:encoded><![CDATA[<p>I had a working proof of concept for Graph mail notifications the classic way: a public HTTPS endpoint, the validation handshake where Graph POSTs you a token and you echo it back within ten seconds, retry handling, the lot. It worked. It also meant my function app had to expose a public webhook and I owned every piece of delivery plumbing myself.</p>
<p>Then I found out Graph can publish change notifications straight into an Event Grid partner topic in my own subscription. No public endpoint. No handshake. Retries and dead-lettering handled by Event Grid instead of by me.</p>
<p>Credit where it&rsquo;s due: <a href="https://julieturner.net/post/setting-up-azure-event-grid/">Julie Turner&rsquo;s post on setting up Azure Event Grid</a> is what got me unstuck on the partner configuration dance. She does it for SharePoint list events; this is the same wiring pointed at mailboxes.</p>
<p>If Event Grid itself is new to you, start with my intro to <a href="https://jeppe-spanggaard.dk/blogs/what-is-azure-event-grid/">what Event Grid is and when to use it</a> - this post builds on it.</p>
<h2 id="the-magic-notificationurl">The Magic notificationUrl</h2>
<p>Everything hangs on one trick. A Graph subscription normally takes a <code>notificationUrl</code> like <code>https://your-app/api/notifications</code>. Point it at Event Grid instead:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-csharp" data-lang="csharp"><span style="display:flex;"><span><span style="color:#66d9ef">private</span> <span style="color:#66d9ef">string</span> NotificationUrl =&gt;
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">$&#34;EventGrid:?azuresubscriptionid={_settings.AzureSubscriptionId}&#34;</span> +
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">$&#34;&amp;resourcegroup={_settings.ResourceGroup}&#34;</span> +
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">$&#34;&amp;partnertopic={_settings.PartnerTopicName}&#34;</span> +
</span></span><span style="display:flex;"><span>    <span style="color:#e6db74">$&#34;&amp;location={_settings.Location}&#34;</span>;
</span></span></code></pre></div><p><strong>What&rsquo;s happening here?</strong></p>
<ol>
<li>The <code>EventGrid:</code> scheme tells Graph not to POST to a webhook at all, but to publish into Event Grid as a partner.</li>
<li>The query parameters say where: your Azure subscription, resource group, a partner topic name of your choosing, and the region.</li>
<li>The topic doesn&rsquo;t have to exist yet. Graph creates it on first use, which is a step in the setup order below.</li>
<li>The <code>partnertopic</code> name is what routes. All my Graph subscriptions (hundreds of mailboxes, two folders each) use the same name and land on one shared topic. You do not create a topic per mailbox.</li>
</ol>
<h2 id="the-partner-configuration-dance-one-time-setup">The Partner Configuration Dance (One-Time Setup)</h2>
<p>The order matters, and half my confusion came from not knowing it. Four steps:</p>
<p><strong>1. Register the resource provider.</strong> <code>Microsoft.EventGrid</code> must show Registered under your subscription&rsquo;s resource providers. While you&rsquo;re in there, ignore <code>Microsoft.ResourceGraph</code> and <code>Microsoft.GraphServices</code> - the names are misleading and they&rsquo;re unrelated.</p>
<p><strong>2. Create a partner configuration.</strong> In the resource group where your functions live, create an Event Grid Partner Configuration (there&rsquo;s exactly one per resource group, named &ldquo;default&rdquo;) and add <strong>Microsoft Graph API</strong> as an authorized partner. The authorization has an expiration window, and here&rsquo;s the part that isn&rsquo;t obvious: the window only limits when Graph may <em>create</em> partner topics. Existing topics and subscriptions keep working after it lapses. Set it to something like 30 days to cover your setup period and forget about it until you need a new topic.</p>
<p><img src="https://jeppe-spanggaard.dk/images/graph-mail-events-event-grid-partner-topic-1_hu_d8c31d2b2a31803b.webp" srcset="/images/graph-mail-events-event-grid-partner-topic-1_hu_660d6dc62551ed6a.webp 480w, /images/graph-mail-events-event-grid-partner-topic-1_hu_8e278158f42777ad.webp 720w, /images/graph-mail-events-event-grid-partner-topic-1_hu_d8c31d2b2a31803b.webp 1200w" sizes="(max-width: 760px) 100vw, 720px"
    width="1200" height="129"
    alt="Partner configuration with Microsoft Graph API authorized" style="background:url(data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAABQAwCdASoYAAMAP1mMtkspJKKYBACTFYT0gAAzI9HjJBUMgAD&#43;3kFh6tWGQAAA) center/cover no-repeat" loading="lazy" decoding="async"></p>
<p><strong>3. Create the first Graph subscription.</strong> With the magic URL from above:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-csharp" data-lang="csharp"><span style="display:flex;"><span><span style="color:#66d9ef">var</span> request = <span style="color:#66d9ef">new</span> Subscription {
</span></span><span style="display:flex;"><span>    ChangeType = <span style="color:#e6db74">&#34;created&#34;</span>,
</span></span><span style="display:flex;"><span>    NotificationUrl = NotificationUrl,
</span></span><span style="display:flex;"><span>    LifecycleNotificationUrl = NotificationUrl,
</span></span><span style="display:flex;"><span>    Resource = <span style="color:#e6db74">$&#34;users/{mailbox}/mailFolders(&#39;Inbox&#39;)/messages&#34;</span>,
</span></span><span style="display:flex;"><span>    ClientState = _settings.ClientState,
</span></span><span style="display:flex;"><span>    ExpirationDateTime = DateTimeOffset.UtcNow.AddMinutes(<span style="color:#ae81ff">1380</span>),
</span></span><span style="display:flex;"><span>};
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">var</span> created = <span style="color:#66d9ef">await</span> graph.Subscriptions.PostAsync(request);
</span></span></code></pre></div><p><strong>What&rsquo;s happening here?</strong></p>
<ol>
<li><code>NotificationUrl</code> and <code>LifecycleNotificationUrl</code> both point at the partner topic. Lifecycle events (like reauthorization requests) arrive on the same topic as mail events, distinguished by event type.</li>
<li><code>ChangeType = &quot;created&quot;</code> covers both incoming and outgoing mail - sending a message produces a <code>created</code> in SentItems, so subscribe to both folders per mailbox.</li>
<li><code>ClientState</code> is a secret Graph echoes back in every notification. The handler verifies it on every event.</li>
<li>The short expiration isn&rsquo;t an accident. My setup uses rich notifications (<code>IncludeResourceData = true</code> plus an encryption certificate), where the encrypted message payload rides along with the event so the handler makes zero Graph read calls on the hot path. The trade-off: max subscription lifetime drops to 1,440 minutes, so renewal becomes a daily chore that a timer function owns. Worth it, but it&rsquo;s a real operational duty you&rsquo;re signing up for.</li>
</ol>
<p><strong>4. Activate the topic and wire it up.</strong> After that first subscription call, the partner topic materializes in your resource group in a &ldquo;Pending activation&rdquo; state. Activate it, then create event subscriptions on it pointing at your functions - I have two: one to the mail handler, one to a reauthorization handler that renews Graph subscriptions when a <code>Microsoft.Graph.SubscriptionReauthorizationRequired</code> event arrives. The portal lets you filter each subscription by event type; I skipped the filters and let each function check the event type in code instead. Both functions receive everything, each drops what isn&rsquo;t for it, and the routing decision is code I can read instead of portal config I have to remember exists.</p>
<p><img src="https://jeppe-spanggaard.dk/images/graph-mail-events-event-grid-partner-topic-2_hu_314e825463544baf.webp" srcset="/images/graph-mail-events-event-grid-partner-topic-2_hu_314e825463544baf.webp 480w" sizes="(max-width: 760px) 100vw, 720px"
    width="480" height="440"
    alt="Creating an event subscription to an Azure Function" style="background:url(data:image/webp;base64,UklGRkYAAABXRUJQVlA4IDoAAADwAwCdASoYABYAP1mavFMpJSKhKAqpJisJ6QACoqW5f9vb1Y3XGZQAAP7TPyqljT3oMpwV84SWAAAA) center/cover no-repeat" loading="lazy" decoding="async"></p>
<p>While you&rsquo;re on that blade: enable dead-lettering to a blob container on both event subscriptions. Failed deliveries retry for about 24 hours, then land there as blobs with the failure reason attached. Getting alerted when that happens is the next post in this series.</p>
<h2 id="the-event-grid-trigger-function">The Event Grid Trigger Function</h2>
<p>The receiving end is refreshingly boring:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-csharp" data-lang="csharp"><span style="display:flex;"><span><span style="color:#a6e22e">[Function(nameof(MailEventHandler))]</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">public</span> <span style="color:#66d9ef">async</span> Task Run([EventGridTrigger] CloudEvent cloudEvent, CancellationToken cancellationToken) {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">var</span> notification = cloudEvent.Data?.ToObjectFromJson&lt;ChangeNotification&gt;(JsonDefaults.CaseInsensitive);
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> (notification <span style="color:#66d9ef">is</span> <span style="color:#66d9ef">null</span> || <span style="color:#66d9ef">string</span>.IsNullOrWhiteSpace(notification.SubscriptionId)) {
</span></span><span style="display:flex;"><span>        logger.LogWarning(<span style="color:#e6db74">&#34;Event {EventId} carried no usable notification payload; dropping.&#34;</span>, cloudEvent.Id);
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span>;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> (!<span style="color:#66d9ef">string</span>.Equals(notification.ClientState, options.Value.ClientState, StringComparison.Ordinal)) {
</span></span><span style="display:flex;"><span>        logger.LogWarning(<span style="color:#e6db74">&#34;Dropping event for subscription {SubscriptionId}: clientState mismatch.&#34;</span>,
</span></span><span style="display:flex;"><span>            notification.SubscriptionId);
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span>;
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// Look up which mailbox and folder this subscription belongs to, then do the actual work.</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p><strong>What&rsquo;s happening here?</strong></p>
<ol>
<li>Bind <code>Azure.Messaging.CloudEvent</code>, not <code>EventGridEvent</code>. Partner topics deliver the CloudEvents schema, and the wrong type gives you confusing deserialization failures.</li>
<li>There is no validation handshake code. None. The handshake that plain Graph webhooks require is handled entirely by the partner topic plumbing.</li>
<li><code>clientState</code> is checked on every event with an ordinal compare. It&rsquo;s the proof the event traces back to a subscription you created.</li>
<li>Note what happens on bad input: log and return, not throw. A poison event that throws gets redelivered for 24 hours. Save the exceptions for failures that are actually transient, so Event Grid&rsquo;s retries work for you instead of against you.</li>
</ol>
<p>The mapping from <code>subscriptionId</code> to mailbox and folder lives in a small Azure Table - Graph tells you which subscription fired, and the table tells you whose mail that is.</p>
<h2 id="testing-the-trigger-locally-without-sending-50-mails">Testing the Trigger Locally (Without Sending 50 Mails)</h2>
<p>You can poke a locally running Event Grid trigger directly. The functions host exposes the delivery endpoint locally:</p>
<pre tabindex="0"><code>POST http://localhost:7071/runtime/webhooks/eventgrid?functionName=MailEventHandler
aeg-event-type: Notification
Content-Type: application/json

{ ...a sample CloudEvent... }
</code></pre><p>The <code>aeg-event-type: Notification</code> header is the part everyone forgets, and the error you get without it tells you nothing useful. Ask me how I know.</p>
<h2 id="gotchas">Gotchas</h2>
<ul>
<li><strong>Check the event type in code.</strong> The mail types are documented in the <a href="https://learn.microsoft.com/en-us/azure/event-grid/outlook-events">Outlook events reference</a> (<code>Microsoft.Graph.MessageCreated</code> and friends), but the most honest verification is still sending yourself a test mail on the activated topic and reading the <code>type</code> off the event. Trust what actually arrives.</li>
<li><strong>The partner configuration expiration only gates topic creation.</strong> Don&rsquo;t panic-renew it for a running system; renew it when you need Graph to create a new topic.</li>
<li><strong>Both notification URLs, same value.</strong> Forget <code>LifecycleNotificationUrl</code> and reauthorization events go nowhere, and your subscriptions quietly die at their expiry instead of renewing.</li>
<li><strong>Rich notifications shorten subscription lifetime to a day.</strong> <code>IncludeResourceData</code> is great for the hot path, but it commits you to daily renewals and certificate rotation. Budget a reconciler timer for it from day one.</li>
<li><strong>At-least-once still applies.</strong> Same event, delivered twice, is normal. Dedupe on the message id.</li>
</ul>
<h2 id="wrapping-up">Wrapping Up</h2>
<p>Point a Graph subscription&rsquo;s <code>notificationUrl</code> at <code>EventGrid:?...</code>, authorize Graph as a partner once, activate the topic that appears, and mail notifications become plain Event Grid events hitting a plain <code>[EventGridTrigger]</code> function. No public webhook, no handshake, and delivery plumbing that&rsquo;s Azure&rsquo;s problem instead of mine. Rule of thumb: if a service can publish to a partner topic, take that over hosting a webhook every time.</p>
]]></content:encoded></item><item><title>What Is Azure Event Grid (and Why I Don't Poll)</title><link>https://jeppe-spanggaard.dk/blogs/what-is-azure-event-grid/</link><pubDate>Thu, 05 Nov 2026 00:00:00 +0000</pubDate><guid>https://jeppe-spanggaard.dk/blogs/what-is-azure-event-grid/</guid><description>Learn what Azure Event Grid is, how topics, subscriptions, and dead-lettering fit together, and when to pick it over a queue.</description><content:encoded><![CDATA[<p>My backend needed to know when new mail landed in a couple hundred monitored mailboxes. Inbox and sent items, so call it 400 folders. My first thought was delta requests: call Microsoft Graph&rsquo;s delta endpoint on a timer, get back only what changed since the last call, act on it. Polling, but with the diffing done server-side.</p>
<p>Do the math on that. 400 folders, polled every minute, is 576,000 Graph calls a day. Almost all of them return nothing new. And Graph doesn&rsquo;t hand out that kind of call budget for free - you&rsquo;ll be deep in 429 territory long before you get anywhere near &ldquo;every minute&rdquo;.</p>
<p>So I went push instead: Graph change notifications, delivered as HTTPS POSTs straight to an Azure Function - the setup from <a href="https://jeppe-spanggaard.dk/blogs/graph-mail-rich-notifications-filter-before-fetch/">my rich notifications post</a>. No polling, no wasted calls, mail arrives when mail arrives.</p>
<p>It worked, and it still had a smell. Every notification now targets my function directly, so every failure is mine to own: deploys, restarts, an hour of bad code, a burst the plan can&rsquo;t absorb. Graph retries a little, but the guarantees are thin, and at hundreds of thousands of deliveries a month even a small fail ratio is real mail quietly lost. I wanted delivery to be someone else&rsquo;s job, done smarter than I&rsquo;d do it on a deadline. That someone turned out to be Azure Event Grid, and this post is the mental model I wish I&rsquo;d had on day one. The concrete mail setup gets its own post later.</p>
<h2 id="push-dont-poll">Push, Don&rsquo;t Poll</h2>
<p>The polling model makes you responsible for the question: &ldquo;anything new?&rdquo; asked over and over, mostly answered with no. The push model flips it. The system where things happen publishes an event when they happen, and your code gets invoked with the event as input. Nothing runs when nothing happens.</p>
<p>That&rsquo;s the whole pitch, and it&rsquo;s an old idea - webhooks have done this for years. What Event Grid adds is the production plumbing you&rsquo;d otherwise write yourself: fan-out to multiple receivers, filtering, automatic retries with backoff, and a paper trail for the events that never made it.</p>
<h2 id="event-grid-is-a-router-not-a-queue">Event Grid Is a Router, Not a Queue</h2>
<p>This is the mental model that matters most, and the one I got wrong first.</p>
<p>Event Grid is a router. An event arrives at a topic, Event Grid looks at the subscriptions on that topic, pushes the event to every one that matches, and moves on. The event is not stored. There is no backlog to work through, no offset to rewind, no built-in replay. If you need to see an event again after it was delivered, that&rsquo;s on you.</p>
<p>A queue like Service Bus is the opposite: it holds messages until a consumer takes them, guarantees order if you ask for it, and lets a slow consumer catch up later. The usual shorthand is events versus messages. An event is a fact: &ldquo;a mail arrived&rdquo;, &ldquo;a blob was created&rdquo;. The publisher doesn&rsquo;t know or care who listens. A message is a command with an intended recipient: &ldquo;provision this site&rdquo;, &ldquo;send this invoice&rdquo;. My backend uses both, and they don&rsquo;t compete - Service Bus carries the commands, Event Grid carries the facts.</p>
<p>If you catch yourself wanting order, backlog, or replay, you wanted a queue. If you want &ldquo;poke my function when something happens, and don&rsquo;t make me poll&rdquo;, you want Event Grid.</p>
<h2 id="three-kinds-of-event-grid-topics">Three Kinds of Event Grid Topics</h2>
<p>A topic is the thing events are published to, and there are three flavors:</p>
<ul>
<li><strong>System topics</strong> belong to Azure resources. A storage account can raise <code>BlobCreated</code>, a resource group can raise deployment events. You don&rsquo;t create the publisher, you just subscribe.</li>
<li><strong>Custom topics</strong> are yours. Your own code POSTs events to an endpoint you own, and Event Grid routes them. Good for decoupling your own services.</li>
<li><strong>Partner topics</strong> are the interesting one for my scenario: an external service outside your subscription publishes into your Azure subscription. Microsoft Graph is such a partner, which is how mail notifications for 400 folders end up as events in my resource group without a single public webhook on my side.</li>
</ul>
<p>One detail that surprised me: partner topics route by name. All 400 of my Graph subscriptions point at one shared partner topic. You do not get - or want - a topic per source.</p>
<p><img src="https://jeppe-spanggaard.dk/images/what-is-azure-event-grid-1_hu_f198819c1b7ef874.webp" srcset="/images/what-is-azure-event-grid-1_hu_c8a25ee3f7e72c92.webp 480w, /images/what-is-azure-event-grid-1_hu_410914be78eb83ba.webp 720w, /images/what-is-azure-event-grid-1_hu_f198819c1b7ef874.webp 1200w" sizes="(max-width: 760px) 100vw, 720px"
    width="1200" height="223"
    alt="Partner topic metrics in the Azure portal showing published and delivered events over a week" style="background:url(data:image/webp;base64,UklGRkAAAABXRUJQVlA4IDQAAADwAgCdASoYAAQAP1mMuEupJKKYBACTFYT0gAAzI9HmQAD&#43;3kGzdxeGO1Qe7DiE51neKgAA) center/cover no-repeat" loading="lazy" decoding="async"></p>
<h2 id="event-subscriptions-do-the-filtering">Event Subscriptions Do the Filtering</h2>
<p>A topic without subscriptions is a mailbox nobody checks. An event subscription says &ldquo;from this topic, send events matching this filter to this handler&rdquo;. Handlers can be Azure Functions, webhooks, Service Bus queues, storage queues, and more.</p>
<p>Filtering earns its keep once one topic carries more than one event type. My partner topic carries both new-mail notifications and subscription lifecycle events, with one subscription per function. You can filter by event type on each subscription so a function only receives its kind - or do what I ended up doing: skip the portal filters, let both functions receive everything, and have each one check the event&rsquo;s <code>type</code> in code and drop what isn&rsquo;t for it. Same routing, but the decision lives in code you can read and debug.</p>
<p>Here&rsquo;s roughly what an event looks like on the wire. Partner topics use the CloudEvents schema, which is a small CNCF-standardized envelope:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-json" data-lang="json"><span style="display:flex;"><span>{
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;specversion&#34;</span>: <span style="color:#e6db74">&#34;1.0&#34;</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;id&#34;</span>: <span style="color:#e6db74">&#34;8f0f0e58-2c5e-4c4a-9f5e-4a1b2c3d4e5f&#34;</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;source&#34;</span>: <span style="color:#e6db74">&#34;/tenants/&lt;tenant-id&gt;/applications/&lt;app-id&gt;&#34;</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;type&#34;</span>: <span style="color:#e6db74">&#34;Microsoft.Graph.MessageCreated&#34;</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;time&#34;</span>: <span style="color:#e6db74">&#34;2026-11-02T09:14:32Z&#34;</span>,
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">&#34;data&#34;</span>: {
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;subscriptionId&#34;</span>: <span style="color:#e6db74">&#34;&lt;graph-subscription-id&gt;&#34;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;changeType&#34;</span>: <span style="color:#e6db74">&#34;created&#34;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;resource&#34;</span>: <span style="color:#e6db74">&#34;Users/&lt;user-id&gt;/Messages/&lt;message-id&gt;&#34;</span>,
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">&#34;clientState&#34;</span>: <span style="color:#e6db74">&#34;&lt;shared-secret&gt;&#34;</span>
</span></span><span style="display:flex;"><span>  }
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p><strong>What&rsquo;s happening here?</strong></p>
<ol>
<li>The envelope (<code>id</code>, <code>source</code>, <code>type</code>, <code>time</code>) is standard CloudEvents. Every event, from any publisher, has these fields, which is what makes generic routing and filtering possible.</li>
<li><code>type</code> is what you route on, whether with a subscription filter or a check at the top of your handler. The mail types are documented in the <a href="https://learn.microsoft.com/en-us/azure/event-grid/outlook-events">Outlook events reference</a>.</li>
<li><code>data</code> is the publisher&rsquo;s payload and can be anything. Note what it is here: pointers, not the mail itself. Events are notifications, not cargo ships.</li>
<li><code>clientState</code> is a shared secret you set when subscribing, so your handler can check the event really originates from your subscription.</li>
</ol>
<p><img src="https://jeppe-spanggaard.dk/images/what-is-azure-event-grid-2_hu_b7718015536eca05.webp" srcset="/images/what-is-azure-event-grid-2_hu_c20a6b1d7f537ea7.webp 480w, /images/what-is-azure-event-grid-2_hu_50922d50b84dca17.webp 720w, /images/what-is-azure-event-grid-2_hu_b7718015536eca05.webp 1200w" sizes="(max-width: 760px) 100vw, 720px"
    width="1200" height="139"
    alt="Event subscriptions list on a topic" style="background:url(data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAABQAwCdASoYAAMAP1mMtkspJKKYBACTFYT0gAAzI9HjGLjFAAD&#43;3kGqHe5B&#43;gAA) center/cover no-repeat" loading="lazy" decoding="async"></p>
<h2 id="retries-and-dead-letters-when-delivery-fails">Retries and Dead-Letters: When Delivery Fails</h2>
<p>This is where Event Grid stops being &ldquo;just webhooks with extra steps&rdquo;.</p>
<p>If a handler fails - throws, times out, returns a 5xx - Event Grid retries with exponential backoff for up to 24 hours. Your function can be down for a deploy, or an hour, or an evening, and the events still arrive when it comes back. No code on your side, it&rsquo;s just what delivery means here.</p>
<p>When 24 hours run out, or the retry count is exhausted, the event is dead-lettered: written as a blob to a storage container you configure, together with the reason delivery failed. That container is your safety net and your crime scene evidence in one. Since Event Grid doesn&rsquo;t store or replay events, the dead-letter container is also the only place a lost event can be recovered from, which makes it worth monitoring - that&rsquo;s a whole post of its own later in this series.</p>
<p>One catch to design for: delivery is at-least-once. Retries mean your handler will occasionally see the same event twice, so make handling idempotent - dedupe on the event or message id rather than assuming exactly-once.</p>
<h2 id="what-event-grid-costs">What Event Grid Costs</h2>
<p>Event Grid&rsquo;s basic tier charges $0.60 per million operations, and the first 100,000 operations each month are free. My mail scenario pushes roughly 300K events a month, which lands somewhere around twenty cents. The pipeline is a rounding error.</p>
<p>The real costs show up downstream: Application Insights ingestion if you log a line per event, and whatever your handler talks to. In my case the constraint was never Event Grid, it was the Graph throttling budget and the write throughput of the archive behind it. Event Grid just makes sure the events get to the code; what the code does next is still your problem.</p>
<h2 id="gotchas">Gotchas</h2>
<ul>
<li><strong>No replay means no replay.</strong> If your handler had a bug and quietly swallowed events for a week, those events are gone unless they were dead-lettered. Design your handler to fail loudly on real errors so retries and dead-lettering can do their job.</li>
<li><strong>Delivery is at-least-once.</strong> The same event can arrive twice. Idempotent handlers aren&rsquo;t optional.</li>
<li><strong>Events are pointers, not payloads.</strong> The event tells you something happened, and mostly not everything about it. Plan for the follow-up read, or use a publisher feature that includes the data (Graph can, with encryption attached).</li>
<li><strong>Don&rsquo;t reach for Event Grid when you want a queue.</strong> Order, backlog, and consumer-paced processing are queue features. I&rsquo;ve seen the mismatch from both sides, and the workarounds are uglier than just using Service Bus.</li>
</ul>
<h2 id="wrapping-up">Wrapping Up</h2>
<p>Event Grid is push-based routing of facts: publishers raise events at topics, subscriptions filter and deliver them to handlers, retries cover about 24 hours, and dead-letters catch the rest. It saved me from 576,000 daily &ldquo;anything new?&rdquo; calls, and then took the delivery failures off my plate too. The one-line rule of thumb: events for facts, queues for commands, and never poll for what Azure will push to you.</p>
<p>Next up in this series: actually wiring Microsoft Graph mail notifications to an Azure Function through a partner topic.</p>
]]></content:encoded></item></channel></rss>