{"id":2171,"date":"2025-09-02T22:35:28","date_gmt":"2025-09-02T19:05:28","guid":{"rendered":"https:\/\/mshaeri.com\/blog\/?p=2171"},"modified":"2026-05-19T02:20:15","modified_gmt":"2026-05-19T12:20:15","slug":"azure-storage-blob-triggers-vs-event-grid-the-lesson-i-learned-in-production","status":"publish","type":"post","link":"https:\/\/mshaeri.com\/blog\/azure-storage-blob-triggers-vs-event-grid-the-lesson-i-learned-in-production\/","title":{"rendered":"Solving Azure Blob Trigger Delays by Switching to Event Grid"},"content":{"rendered":"\n<p>About a year ago, I set up an <strong>Azure Function App<\/strong> that would fire whenever a file was uploaded to a specific container in Blob Storage. It was one of those setups that felt almost magical, upload a file, the function wakes up, processes it, and moves on. For months, it worked exactly as expected. But, it gradually started to slip as the number of files in the container grew and traffic increased.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Unexpected Delay In Blob Triggers<\/h3>\n\n\n\n<p>After running smoothly for months, I started noticing something strange. Some files were processed within minutes of upload, no big deal. But some files sat in the container for <strong>up to five days<\/strong> before the function processed them, the processing itself was instant, no errors, no crashes. The function itself was fine. No failures. Whenever it ran, it worked perfectly. The real issue was that the trigger, the \u201chey, a new blob is here!\u201d signal was showing up late. Some times very late.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Root Cause<\/h3>\n\n\n\n<p>So, I dug deeper. Looking at the logs, I noticed something important: the detection source was listed as <strong>ContainerScan<\/strong>. That was my \u201caha\u201d moment. Blob Triggers don\u2019t actually get notified in real time when a new blob appears. It rely on a <strong>polling mechanism<\/strong> essentially, Azure scans the storage account at intervals to discover new blobs. As the storage grew, more blobs, deeper folder hierarchies, and heavier traffic, this scanning process slowed. Eventually, it hit a point where the detection delay was no longer acceptable and reliable. Some blobs were processed the same day, others languished unnoticed for days.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-medium is-resized\"><a href=\"https:\/\/mshaeri.com\/blog\/wp-content\/uploads\/2025\/09\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"219\" src=\"https:\/\/mshaeri.com\/blog\/wp-content\/uploads\/2025\/09\/image-300x219.png\" alt=\"\" class=\"wp-image-2172\" style=\"aspect-ratio:1.5;object-fit:cover;width:400px;height:auto\" srcset=\"https:\/\/mshaeri.com\/blog\/wp-content\/uploads\/2025\/09\/image-300x219.png 300w, https:\/\/mshaeri.com\/blog\/wp-content\/uploads\/2025\/09\/image-768x560.png 768w, https:\/\/mshaeri.com\/blog\/wp-content\/uploads\/2025\/09\/image.png 877w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption class=\"wp-element-caption\">Blob Triggers rely on periodic polling of the storage container to detect new blobs<\/figcaption><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">The Fix: Event Grid to the Rescue<\/h3>\n\n\n\n<p>I found that Blob Triggers weren\u2019t designed for real-time, high-volume scenarios. That\u2019s where <strong>Event Grid<\/strong> comes in. Unlike Blob Triggers, <strong>Event Grid<\/strong> operates on a push model, Azure sends an event the moment a blob is created, and the function receives it almost instantly. So, we rewired our architecture, instead of relying on Blob Triggers, we subscribed the Function App to Blob Created events via Event Grid. After migrating the function to use Event Grid triggers, files began processing <strong>in under a second<\/strong> after upload and performance was stable even as blob count and traffic continued to grow.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><a href=\"https:\/\/mshaeri.com\/blog\/wp-content\/uploads\/2025\/09\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"993\" height=\"325\" src=\"https:\/\/mshaeri.com\/blog\/wp-content\/uploads\/2025\/09\/image-1.png\" alt=\"\" class=\"wp-image-2173\" style=\"width:629px;height:auto\" srcset=\"https:\/\/mshaeri.com\/blog\/wp-content\/uploads\/2025\/09\/image-1.png 993w, https:\/\/mshaeri.com\/blog\/wp-content\/uploads\/2025\/09\/image-1-300x98.png 300w, https:\/\/mshaeri.com\/blog\/wp-content\/uploads\/2025\/09\/image-1-768x251.png 768w\" sizes=\"(max-width: 993px) 100vw, 993px\" \/><\/a><figcaption class=\"wp-element-caption\">Event Grid operates on a push model, Azure sends an event the moment a blob is created<\/figcaption><\/figure><\/div>\n\n\n<p>Event Grid doesn\u2019t just trigger Azure Functions. It can also call any <strong>HTTP endpoint<\/strong>, which means you can notify an external system, trigger a webhook in a third-party app, or even integrate directly with your own APIs. This flexibility makes Event Grid a much stronger choice than relying solely on Blob Triggers.<\/p>\n\n\n\n<p>To use <strong>Event Grid<\/strong> with Azure Functions, we need to update the function signature to accept an <strong><code>EventGridEvent<\/code> <\/strong>instead of a Blob.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"python\" class=\"language-python\">import logging\nimport azure.functions as func\n\ndef main(event: func.EventGridEvent):\n&nbsp; &nbsp; logging.info('Event Grid event received')\n\n&nbsp; &nbsp; # Parse the event payload\n&nbsp; &nbsp; event_data = event.get_json()\n&nbsp; &nbsp; blob_url = event_data.get('url')\n\n&nbsp; &nbsp; logging.info(f'Blob created at: {blob_url}')\n\n&nbsp; &nbsp; # Here you can add your processing logic,\n&nbsp; &nbsp; # e.g., download the blob, transform, move, etc.<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">What I Learned<\/h3>\n\n\n\n<ul>\n<li><strong>Blob Triggers are fine<\/strong> for small workloads or where near-real-time isn\u2019t critical.<\/li>\n\n\n\n<li><strong>Event Grid is essential<\/strong> for high-volume, low-latency scenarios.<\/li>\n\n\n\n<li><strong>Monitor your system and don\u2019t wait until things break.<\/strong> The signs were there early small delays that grew over time. Continues monitoring could have avoided a lot of frustration.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Final Thoughts<\/h3>\n\n\n\n<p>If you\u2019re relying on Blob Triggers and your workload is growing, don\u2019t wait for five-day delays to surprise you. Consider switching early, you\u2019ll thank yourself later.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>About a year ago, I set up an Azure Function App that would fire whenever a file was uploaded to a specific container in Blob &hellip; <\/p>\n","protected":false},"author":1,"featured_media":2174,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[307,203,202,35,41],"tags":[226,308,311,309,310,313,39],"_links":{"self":[{"href":"https:\/\/mshaeri.com\/blog\/wp-json\/wp\/v2\/posts\/2171"}],"collection":[{"href":"https:\/\/mshaeri.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mshaeri.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mshaeri.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mshaeri.com\/blog\/wp-json\/wp\/v2\/comments?post=2171"}],"version-history":[{"count":5,"href":"https:\/\/mshaeri.com\/blog\/wp-json\/wp\/v2\/posts\/2171\/revisions"}],"predecessor-version":[{"id":2306,"href":"https:\/\/mshaeri.com\/blog\/wp-json\/wp\/v2\/posts\/2171\/revisions\/2306"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mshaeri.com\/blog\/wp-json\/wp\/v2\/media\/2174"}],"wp:attachment":[{"href":"https:\/\/mshaeri.com\/blog\/wp-json\/wp\/v2\/media?parent=2171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mshaeri.com\/blog\/wp-json\/wp\/v2\/categories?post=2171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mshaeri.com\/blog\/wp-json\/wp\/v2\/tags?post=2171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}