<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: GDG Cloud Port Harcourt</title>
    <description>The latest articles on DEV Community by GDG Cloud Port Harcourt (gdgcloudph).</description>
    <link>https://dev.to/gdgcloudph</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F12932%2F61b0123c-5779-4027-995a-d22ae726bfcf.png</url>
      <title>DEV Community: GDG Cloud Port Harcourt</title>
      <link>https://dev.to/gdgcloudph</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gdgcloudph"/>
    <language>en</language>
    <item>
      <title>The Architecture Split &amp; The $10 Billion Shift Reshaping Who Wins in 2026: Horizontal AI vs Vertical AI</title>
      <dc:creator>Caleb Duff</dc:creator>
      <pubDate>Thu, 10 Sep 2026 20:21:01 +0000</pubDate>
      <link>https://dev.to/gdgcloudph/the-architecture-split-the-10-billion-shift-reshaping-who-wins-in-2026-horizontal-ai-vs-17ig</link>
      <guid>https://dev.to/gdgcloudph/the-architecture-split-the-10-billion-shift-reshaping-who-wins-in-2026-horizontal-ai-vs-17ig</guid>
      <description>&lt;p&gt;If you’ve spent any time evaluating machine learning initiatives over the past few cycles, you’ve likely watched the enterprise AI conversation drift into two completely different camps.&lt;/p&gt;

&lt;p&gt;On one side, hyperscalers and frontier labs release ever-larger foundation models promising universal capability across text, code, vision, and reasoning. On the other side, an army of domain-specific startups and internal enterprise teams quietly build bespoke platforms tailored to a single regulatory framework, clinical pathway, or supply chain bottleneck; often racking up higher margins and stickier retention with models a fraction of the size.&lt;/p&gt;

&lt;p&gt;This is the divide between Horizontal AI and Vertical AI.&lt;/p&gt;

&lt;p&gt;In 2025, more than 3,800 horizontal AI startups shut down. In that same year, a completely different category of AI company crossed $10 billion in market size, and multiple companies inside it reached unicorn status in under three years.&lt;/p&gt;

&lt;p&gt;Same underlying technology. Wildly different outcomes.&lt;/p&gt;

&lt;p&gt;The difference comes down to a single strategic decision made at the very beginning of each company's life: whether to build horizontal AI: general-purpose tools sold to everyone or vertical AI: tools built deep into one specific industry or workflow. This post breaks down exactly what separates the two, backs it up with real companies and real numbers (including a look at the vertical AI boom happening across Nigeria and the rest of Africa), and gives you a practical framework for deciding which approach fits whatever you're building next.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;By the end of this article, you will be able to:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clearly explain the difference between horizontal and vertical AI, with real examples of each.&lt;/li&gt;
&lt;li&gt;Understand the market data driving the shift toward vertical AI in 2025-2026.&lt;/li&gt;
&lt;li&gt;Name specific vertical AI companies: globally, across Africa and the industries they serve.&lt;/li&gt;
&lt;li&gt;Explain why vertical AI is more defensible, and why that defensibility isn't guaranteed.&lt;/li&gt;
&lt;li&gt;Apply a practical framework to decide which approach fits your own project.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;New to the broader AI landscape? A good primer is Euclid Ventures' &lt;a href="https://www.euclid.vc" rel="noopener noreferrer"&gt;The Vertical Report 2026&lt;/a&gt;, which this article draws several data points from.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who This Article Is For
&lt;/h2&gt;

&lt;p&gt;This is written for developers, founders, and technical decision-makers who are trying to cut through "AI strategy" buzzwords and understand a real, architectural and measurable market shift. No specific technical prerequisites are required, though if you're actively building something, it helps to already have a rough idea of the problem you're solving.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The Core Distinction: What Actually Separates the Two
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  ┌─────────────────────────────────────────────────────────────┐
  │                       HORIZONTAL AI                         │
  │     (Foundation Models, Cross-Industry APIs, General Tools) │                
            │                      │                      │
            ▼                      ▼                      ▼
   ┌─────────────┐        ┌─────────────┐        ┌─────────────┐
   │ Healthcare  │        │ Legal Tech  │        │ FinTech /   │
   │  Workflows  │        │ Discovery   │        │ Underwrite  │
   └─────────────┘        └─────────────┘        └─────────────┘
         ▲                      ▲                      ▲
  ┌──────┴──────────────────────┴──────────────────────┴────────┐
  │                        VERTICAL AI                          │
  │  (Deep Domain Workflows, Proprietary Data, Bespoke Evals)   │
  └─────────────────────────────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Horizontal AI: The Generalist Layer
&lt;/h3&gt;

&lt;p&gt;Horizontal AI is broad, task-agnostic, and designed to solve cross-cutting problems across every industry.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Horizontal AI&lt;/strong&gt; is general-purpose. It's built to work across every industry and every role, and it's sold to as many people as possible with one product. ChatGPT, Gemini, Claude, and GitHub Copilot are the clearest examples; one tool, used by a lawyer, a marketer, a developer, and a student, all at once.&lt;/p&gt;

&lt;p&gt;The pitch is flexibility and scale: build one thing, sell it to everyone. For a long stretch of the current AI boom, this was the entire startup playbook; wrap a chatbot interface around a foundation model's API and ship it.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Horizontal Strengths
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Rapid Prototyping:&lt;/strong&gt; Zero infrastructure to train; developers can spin up a proof of concept in hours with straightforward prompt engineering.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Continuous Upgrades:&lt;/strong&gt; As the underlying foundation models improve, horizontal wrappers inherit better performance and lower latency without retraining.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Economies of Scale:&lt;/strong&gt; Foundation model providers optimize inference clusters (e.g., custom TPUs, speculative decoding) far more efficiently than an isolated startup can.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Horizontal Pitfalls
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The "Thin Wrapper" Vulnerability:&lt;/strong&gt; If your value proposition is merely a UI sitting on top of a standard API call, a model update from the provider can commoditize your product overnight.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Context Gap:&lt;/strong&gt; Horizontal models struggle with dense, non-standardized shorthand (e.g., a hospital’s proprietary clinical shorthand or a manufacturer's internal CAD nomenclature).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compliance &amp;amp; Data Privacy Walls:&lt;/strong&gt; Sending raw payloads to public inference endpoints often fails compliance mandates in strictly regulated jurisdictions.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Vertical AI: The Deep Specialist Layer
&lt;/h3&gt;

&lt;p&gt;Vertical AI is purpose-built to solve high value problems inside a single industry, operational domain, or regulatory context.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vertical AI&lt;/strong&gt; takes the opposite approach. Instead of serving everyone a little, it's built for one specific industry or workflow, and it goes deep. It understands that industry's language, its regulatory constraints, its edge cases, and the software it already runs on.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Vertical Strengths
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Proprietary Data Flywheel:&lt;/strong&gt; Every corrected contract or diagnostic scan refines fine-tuned weights or vector knowledge bases, widening the moat against generalist competitors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deep Process Integration:&lt;/strong&gt; A doctor doesn't want an empty chat box; they want ambient listening that auto-populates clinical fields directly into their Epic EHR interface.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost Efficiency at Scale:&lt;/strong&gt; Instead of paying $10–$30 per million tokens on a heavyweight general model, vertical teams often distill tasks down to specialized 3B–8B parameter models running on lean, cost-efficient inference servers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Vertical Pitfalls
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Smaller Total Addressable Market (TAM):&lt;/strong&gt; A tool tailored specifically to commercial HVAC estimation has a naturally capped ceiling compared to a general office productivity suite.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;High Customer Acquisition Costs (CAC):&lt;/strong&gt; Selling into regulated enterprise verticals involves lengthy procurement cycles, security reviews, and custom migration pipelines.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A few real examples worth knowing:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Company&lt;/th&gt;
&lt;th&gt;Industry&lt;/th&gt;
&lt;th&gt;What Makes It Vertical&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Harvey&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Legal&lt;/td&gt;
&lt;td&gt;AI for legal research and contract review — reached $190M ARR and an $11B valuation in 36 months&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Basis&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Accounting&lt;/td&gt;
&lt;td&gt;The first AI-native accounting company to reach unicorn status&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Avoca&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;HVAC &amp;amp; Plumbing&lt;/td&gt;
&lt;td&gt;Voice AI purpose-built for trade dispatch — a niche a horizontal chatbot would never target&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Hippocratic AI&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Healthcare&lt;/td&gt;
&lt;td&gt;Non-diagnostic clinical support, built around healthcare's specific compliance needs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;EvenUp&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Personal Injury Law&lt;/td&gt;
&lt;td&gt;Automates claims and case-value assessment for a single legal specialty&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; None of these are "AI for everyone." They're AI for one job, done extremely well and that distinction is the entire thesis of this article.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  2. The Numbers Behind the Shift
&lt;/h2&gt;

&lt;p&gt;The data on this shift is stark enough that it's worth walking through carefully, because the headline numbers alone can be misleading.&lt;/p&gt;

&lt;p&gt;The vertical AI market crossed &lt;strong&gt;$10 billion&lt;/strong&gt; in size in 2025. In that same year, vertical AI startups captured &lt;strong&gt;53% of total deal volume&lt;/strong&gt;, according to Euclid Ventures' Vertical Report, meaning more individual funding deals went to vertical AI companies than horizontal ones.&lt;/p&gt;

&lt;p&gt;Here's the nuance that's easy to miss: horizontal AI companies still absorbed the majority of actual &lt;em&gt;capital&lt;/em&gt;, roughly $130 billion compared to vertical AI's $56 billion. That gap is mostly explained by a handful of massive infrastructure rounds raised by foundation model companies themselves, which skews the total. When you look at where individual founders were actually getting funded and actually shipping products, vertical was where the volume was.&lt;/p&gt;

&lt;p&gt;The return on investment numbers reinforce the same pattern. According to the McKinsey's State of AI research:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Vertical AI deployments hitting measurable ROI within 6 months:  71%
Horizontal-only deployments hitting the same bar:                 32%
Average ROI multiple for vertical AI tools vs. general tools:    2.3x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Sources:&lt;/strong&gt; Euclid Ventures "The Vertical Report 2026," McKinsey State of AI 2025, Bessemer Venture Partners State of AI 2025.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  3. Vertical AI in Practice: The Global Playbook
&lt;/h2&gt;

&lt;p&gt;It's worth understanding &lt;em&gt;why&lt;/em&gt; these companies are winning, not just that they are. Three (3) structural advantages show up consistently across successful vertical AI companies, and they're genuinely hard for a general purpose model to replicate:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Proprietary data.&lt;/strong&gt; Deep, accurately labeled datasets specific to one industry; legal case outcomes, accounting audit trails, clinical documentation, that horizontal models simply don't have access to.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Workflow integration.&lt;/strong&gt; Vertical tools embed directly into the software and processes an industry already uses. That creates real switching costs; ripping out a tool that's wired into your daily workflow is a much bigger decision than closing a chat tab.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Regulatory and compliance knowledge.&lt;/strong&gt; Industries like legal, healthcare, and finance operate under rules a general chatbot has no built-in understanding of. Vertical tools are designed around those rules from day one, rather than bolting compliance on as an afterthought.&lt;/p&gt;

&lt;p&gt;Put together, these three (3) things create what venture capital calls a &lt;strong&gt;moat&lt;/strong&gt;; a durable reason a customer can't simply swap you out for a marginally cheaper general-purpose tool next year.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Vertical AI, Made in Africa (and Nigeria)
&lt;/h2&gt;

&lt;p&gt;Every example so far has been a Silicon Valley story, and that would be an incomplete picture. Some of the most interesting vertical AI activity happening right now is across Africa, Nigeria in particular.&lt;/p&gt;

&lt;p&gt;A Brookings Institution dataset tracking AI startups across the continent found that Nigeria leads Africa in healthcare AI and software development, and is the clear home for legal AI on the continent. According to the "AI Outlook 2026" report from AI CoLab Africa, Nigeria now has more than &lt;strong&gt;120 AI startups&lt;/strong&gt;, concentrated in health tech, fintech, agriculture, and language technology. Nigeria is also one of Africa's "Big Four" AI hubs, alongside South Africa, Kenya, and Egypt and together those four (4) countries absorbed roughly &lt;strong&gt;72% of all AI funding&lt;/strong&gt; on the continent in 2025.&lt;/p&gt;

&lt;p&gt;A few concrete examples, using the exact same definition of "vertical" applied throughout this article:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Flutterwave AI&lt;/strong&gt; is built into one of Africa's largest payment infrastructure platforms, using AI specifically for fraud detection and payment optimization across checkout, international transfers, and financial products; a vertical AI tool embedded directly into one industry's core workflow, exactly like Harvey is for legal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decide&lt;/strong&gt; is one of the more remarkable stories in this space. It's a Nigerian startup founded in 2025 by Abiodun Adetona, a former Flutterwave developer; bootstrapped, with a three-person team and zero venture capital. Decide built an AI agent specifically for spreadsheet work: it doesn't just suggest formulas, it executes changes directly and explains them in plain language. On the SpreadsheetBench benchmark 400 real, verified Excel tasks, Decide ranked &lt;strong&gt;4th in the world for accuracy&lt;/strong&gt;, outperforming several well-funded competitors, and crossed a thousand users within 24 days of launch.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;10mg Health&lt;/strong&gt; applies AI to a specific financial workflow inside healthcare: providing AI-powered, collateral free credit so clinics and pharmacies across Africa can buy medicine now and pay later. That's a distinctly local, industry-specific problem no general-purpose chatbot was ever going to touch.&lt;/p&gt;

&lt;p&gt;And outside of startups entirely, the &lt;strong&gt;Ogun SmartFarm Initiative&lt;/strong&gt; in Nigeria combined drones, soil sensors, and AI-driven forecasting for farmers, increasing crop yields by &lt;strong&gt;35%&lt;/strong&gt; while cutting costs by &lt;strong&gt;20%&lt;/strong&gt; — vertical AI's value proposition, proven in a real field rather than a pitch deck.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Worth noting:&lt;/strong&gt; Nigeria's National AI Strategy (launched August 2024) and National AI Trust (established February 2025) mean this isn't just startups acting independently, there's active government policy support behind the momentum too.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  5. The Twist, and the Reality Check
&lt;/h2&gt;

&lt;p&gt;No honest analysis of this space stops at "vertical wins." Two things complicate the picture, and both matter if you're actually making a decision based on this article.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The twist: foundation model companies are entering the verticals themselves.&lt;/strong&gt; On January 8, 2026, OpenAI launched a dedicated product called OpenAI for Healthcare: a HIPAA-compliant workspace already deployed at Stanford Medicine, Cedars-Sinai, and Memorial Sloan Kettering. Google grew its enterprise AI market share from 7% to 21% between 2023 and 2025, specifically by pushing into healthcare, legal, finance, and education. Mistral is doing the same, positioning its models directly for regulated industries.&lt;/p&gt;

&lt;p&gt;The pattern: foundation model companies build horizontal platforms first to capture scale and reach, then turn around and enter the highest-margin verticals themselves. If you're building a vertical AI product, the real question isn't "horizontal versus vertical" in the abstract; it's whether you can establish a defensible position in your specific niche before a company with a hundred times your resources decides to walk in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The reality check: most vertical AI never ships.&lt;/strong&gt; According to McKinsey, roughly &lt;strong&gt;90% of vertical AI agents never make it past the pilot stage.&lt;/strong&gt; Typically, this isn't because the underlying AI is weak, it's because the surrounding workflow, data quality, and governance weren't actually ready. Getting a vertical AI tool to the accuracy a real business can trust often 99% or higher is dramatically harder than producing an impressive demo.&lt;/p&gt;

&lt;p&gt;Choosing "vertical" as a strategy doesn't guarantee success. It means you're competing on depth and trust instead of reach, and depth and trust are genuinely hard to earn.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Choosing Your Approach: A Decision Framework
&lt;/h2&gt;

&lt;p&gt;If you're deciding which direction makes sense for something you're building, here's a practical way to frame it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GO HORIZONTAL IF:
- You're building a genuinely general-purpose tool (coding, writing, broad automation)
- The core value is reach and flexibility, not depth.
- You have the resources or distribution to compete at scale.

GO VERTICAL IF:
- You can name one specific industry AND one specific painful workflow inside it.
- You have domain expertise or proprietary data a general model lacks.
- You're optimizing for trust and defensibility, not just reach.

MOST REAL PRODUCTS TODAY ARE HYBRID:
- A general-purpose model underneath (for reasoning)
- Wrapped in deep, vertical-specific workflow and data (for defensibility)
- Examples: Sierra and Decagon in customer service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That hybrid pattern, general-purpose reasoning underneath, radically narrow and deep on top is probably the most realistic target for most teams building something today, rather than treating this as a binary choice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where to Go Next
&lt;/h2&gt;

&lt;p&gt;If you're evaluating a product idea against this framework, start small: pick one specific industry, name one painful workflow inside it you understand well, and honestly assess whether you have access to data or expertise a general-purpose model doesn't. Decide's story, a three-person, bootstrapped team beating funded competitors on a global benchmark is proof that this doesn't require Silicon Valley-scale resources to start.&lt;/p&gt;

&lt;p&gt;Are you building (or using) something closer to horizontal or vertical AI right now? And if you're in Nigeria or elsewhere in Africa, which industry problem do you think is still wide open for a vertical AI solution? I'd love to hear your take in the comments.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>automation</category>
      <category>verticalai</category>
      <category>horizontalai</category>
    </item>
    <item>
      <title>I spent a week reading about the Node.js Event Loop. This is everything I found out</title>
      <dc:creator>Precious Bob-Manuel</dc:creator>
      <pubDate>Thu, 03 Sep 2026 23:53:00 +0000</pubDate>
      <link>https://dev.to/gdgcloudph/i-spent-a-week-reading-about-the-nodejs-event-loop-this-is-everything-i-found-out-4iec</link>
      <guid>https://dev.to/gdgcloudph/i-spent-a-week-reading-about-the-nodejs-event-loop-this-is-everything-i-found-out-4iec</guid>
      <description>&lt;p&gt;So my mentor challenged me to study about the Event Loop before our next meeting and I realised while we learn about the Event Loop as a theoretical concept, very few understand how it works in practice.&lt;/p&gt;

&lt;p&gt;We’re all taught that Javascript is single threaded, meanwhile it can handle asynchronous operations like API calls, timers, and file reading without blocking execution. At first, this feels contradictory. How can a language that runs only one operation at a time manage multiple tasks efficiently? This is the core idea behind the event loop.&lt;/p&gt;

&lt;p&gt;To understand how the event loop works, we first need to look at where JavaScript actually executes code: the call stack.&lt;br&gt;
The call stack is where JavaScript keeps track of function execution. It determines which function is currently running and what should run next. You can think of it as a stack of books.&lt;/p&gt;

&lt;p&gt;Whenever a function is called, it is added (or “pushed”) onto the stack. When that function finishes execution, it is removed (or “popped”) from the stack. Because of &lt;br&gt;
this structure, the call stack follows a Last In, First Out (LIFO) order; the most recently added function is the first to be executed and removed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmgo00w2ut6r9fmtj2m7w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmgo00w2ut6r9fmtj2m7w.png" alt="call stack" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This model explains how JavaScript executes code synchronously: each function runs to completion before the next one begins.&lt;br&gt;
However, this raises an important question: what happens when a task takes time to complete, like fetching data from an API or waiting on a timer? If such tasks were handled directly on the call stack, they would block everything else from running. To avoid this, JavaScript relies on external APIs provided by its environment.&lt;/p&gt;

&lt;p&gt;In the browser, these are known as Web APIs (such as setTimeout, DOM events, fetch, etc). In Node.js, similar functionality is provided by built-in APIs for tasks like fs operations, networking, timers, etc.&lt;br&gt;
When an asynchronous function is called, it is handed off to these APIs instead of remaining on the call stack. This allows the call stack to stay free and continue executing other code.&lt;/p&gt;

&lt;p&gt;Once the operation is complete, its callback function is not executed immediately. Instead, it is placed in a queue, waiting for the right moment to be processed. This queue is known as the callback queue (or task queue), and it holds callbacks from completed asynchronous operations in the order they were received.&lt;/p&gt;

&lt;p&gt;Now this is where the event loop comes in.&lt;br&gt;
The event loop continuously monitors the call stack. When the stack becomes empty, it takes a task from a queue and pushes it onto the stack for execution.&lt;br&gt;
At this point, it might seem like the event loop simply processes tasks from a single queue in order. However, this is not the full picture.&lt;/p&gt;

&lt;p&gt;Consider the following code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj9hw9i2ulamr3nwhxmdz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj9hw9i2ulamr3nwhxmdz.png" alt="asynchronous code" width="578" height="155"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might expect the setTimeout callback to run first since it appears earlier in the code. But when we run this we might be in for a little surprise:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh3oa9j5kgtkmvmk3i2zl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh3oa9j5kgtkmvmk3i2zl.png" alt="runtime order" width="151" height="78"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So why does the Promise execute before the timeout?&lt;/p&gt;

&lt;p&gt;The reason is that the event loop does not rely on just one queue. Instead, it prioritizes tasks using two main queues: the microtask queue and the macrotask queue.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Microtask Queue (Higher Priority)&lt;/strong&gt;&lt;br&gt;
The microtask queue holds tasks such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Promise callbacks (.then(), .catch(), .finally())&lt;/li&gt;
&lt;li&gt;  queueMicrotask&lt;/li&gt;
&lt;li&gt;  In Node.js, process.nextTick (with even higher priority)
Microtasks are executed immediately after the current operation completes and before the event loop moves to the next Macrotask.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Macrotask Queue (Lower Priority)&lt;/strong&gt;&lt;br&gt;
The macrotask queue (or callback queue) contains tasks like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  setTimeout and setInterval&lt;/li&gt;
&lt;li&gt;  I/O operations (e.g., fs or network requests)&lt;/li&gt;
&lt;li&gt;  setImmediate (in Node.js)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These tasks are processed only after all microtasks have been completed.&lt;br&gt;
So In our example, the Promise callback is placed in the microtask queue, while the setTimeout callback goes into the macrotask queue.&lt;br&gt;
When the call stack becomes empty, the event loop processes all tasks in the microtask queue, then moves to the macrotask queue. This is why the Promise runs before the timeout, even though it appears later in the code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
The event loop is what allows JavaScript to handle asynchronous operations while still being single-threaded. Rather than executing everything directly on the call stack, JavaScript delegates time-consuming tasks to external APIs, queues their callbacks, and uses the event loop to decide when they should run.&lt;br&gt;
However, not all tasks are treated equally. Microtasks are always processed before macrotasks, which is why, for example, Promise callbacks run before functions scheduled with setTimeout, even if they appear later in the code.&lt;br&gt;
Understanding this execution order removes much of the confusion around asynchronous JavaScript. It explains why certain operations behave the way they do, and the implications this behaviour has in software development.&lt;/p&gt;

</description>
      <category>node</category>
      <category>eventloop</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
