<?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: Pallab Das</title>
    <description>The latest articles on DEV Community by Pallab Das (@pallab_das_71b2cda46b54f5).</description>
    <link>https://dev.to/pallab_das_71b2cda46b54f5</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%2Fuser%2Fprofile_image%2F4219138%2Fcb7e9f90-fcaf-4cb8-9ef2-497987b2060b.png</url>
      <title>DEV Community: Pallab Das</title>
      <link>https://dev.to/pallab_das_71b2cda46b54f5</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pallab_das_71b2cda46b54f5"/>
    <language>en</language>
    <item>
      <title># Building a Reliable WhatsApp Webhook Handler with Node.js</title>
      <dc:creator>Pallab Das</dc:creator>
      <pubDate>Sat, 31 Oct 2026 15:27:33 +0000</pubDate>
      <link>https://dev.to/pallab_das_71b2cda46b54f5/-building-a-reliable-whatsapp-webhook-handler-with-nodejs-2427</link>
      <guid>https://dev.to/pallab_das_71b2cda46b54f5/-building-a-reliable-whatsapp-webhook-handler-with-nodejs-2427</guid>
      <description>&lt;p&gt;&lt;em&gt;Receiving a webhook is easy. Processing it safely, handling duplicates, and recovering from failures is where production systems get interesting.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When integrating a messaging API, it's tempting to build a single endpoint that receives an event and immediately processes it.&lt;/p&gt;

&lt;p&gt;That can work in a local demo. Under real traffic, however, slow database queries, duplicate events, and temporary failures can make the system unreliable.&lt;/p&gt;

&lt;p&gt;Here's a practical approach.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Create a basic Express endpoint
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/webhooks/whatsapp&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;event&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Add provider-specific verification here.&lt;/span&gt;
  &lt;span class="c1"&gt;// Validate the event before processing it.&lt;/span&gt;

  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Enqueue the event for asynchronous processing.&lt;/span&gt;
    &lt;span class="c1"&gt;// Replace this placeholder with your queue implementation.&lt;/span&gt;

    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sendStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Webhook enqueue failed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sendStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Server listening on port 3000&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a structural example, not a complete production implementation. The endpoint must perform actual verification, validation, and queue insertion before acknowledging an event.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Avoid processing everything inside the request
&lt;/h2&gt;

&lt;p&gt;If an event triggers several database operations or external API calls, processing all of them inside the HTTP request can increase latency.&lt;/p&gt;

&lt;p&gt;A better architecture is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Receive the webhook.&lt;/li&gt;
&lt;li&gt;Verify the request according to the provider's documented security mechanism.&lt;/li&gt;
&lt;li&gt;Validate the event structure.&lt;/li&gt;
&lt;li&gt;Store or enqueue the event durably.&lt;/li&gt;
&lt;li&gt;Return the appropriate HTTP response.&lt;/li&gt;
&lt;li&gt;Process the event asynchronously.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A durable queue or database-backed inbox helps protect events when workers temporarily fail.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Handle duplicate events
&lt;/h2&gt;

&lt;p&gt;Webhook providers may retry delivery. Your application should not assume that every incoming event is unique.&lt;/p&gt;

&lt;p&gt;Use stable event identifiers where available and enforce idempotency at the processing layer.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Add controlled retries
&lt;/h2&gt;

&lt;p&gt;Retry transient errors with exponential backoff and jitter. Avoid endless retries for permanent errors, and use a dead-letter mechanism for events that repeatedly fail.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Monitor the complete pipeline
&lt;/h2&gt;

&lt;p&gt;Useful metrics include processing latency, retry counts, queue depth, failed events, and delivery status.&lt;/p&gt;

&lt;p&gt;These metrics help you distinguish provider delivery problems from failures inside your own application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further resources
&lt;/h2&gt;

&lt;p&gt;If you're evaluating WhatsApp messaging integrations, review CampaigningTool's &lt;a href="https://campaigningtool.com/products/whatsapp-business-api" rel="noopener noreferrer"&gt;WhatsApp Business API information&lt;/a&gt; and its &lt;a href="https://documenter.getpostman.com/view/46662670/2sB34kEJy8" rel="noopener noreferrer"&gt;Postman API documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Verify the actual endpoint definitions and authentication requirements in the documentation before implementing an integration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Developer question:&lt;/strong&gt; Do you prefer processing webhooks through a queue such as BullMQ, or using a database-backed job system?&lt;/p&gt;

</description>
      <category>backend</category>
      <category>javascript</category>
      <category>node</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
