{"id":2153,"date":"2026-11-24T19:28:12","date_gmt":"2026-11-24T19:28:12","guid":{"rendered":"https:\/\/vectalk.com.br\/blog\/whatsapp-webhook-message-order\/"},"modified":"2026-11-24T19:28:20","modified_gmt":"2026-11-24T19:28:20","slug":"whatsapp-webhook-message-order","status":"publish","type":"post","link":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-message-order\/","title":{"rendered":"WhatsApp webhook message and status order: why events arrive out of order"},"content":{"rendered":"\n<p><em>Updated on November 24, 2026<\/em><\/p>\n\n\n\n<p>Meta&#8217;s documentation does not guarantee that WhatsApp webhooks arrive in the order the events happened: retries, batching and parallel deliveries shuffle inbound messages and statuses such as <code>sent<\/code>, <code>delivered<\/code> and <code>read<\/code>. To rebuild the sequence, sort by the event&#8217;s own <code>timestamp<\/code> (with an arrival number as a tiebreaker), process one contact at a time, and treat statuses as facts that accumulate, not as &#8220;the last one to arrive wins&#8221;.<\/p>\n\n\n\n<p>This article builds on two we have already published: <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-message-status-webhook\/\">message status via webhook<\/a>, which explains each status and how to store them without regressing, and <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-integration-architecture\/\">integration architecture with queues, retries and idempotency<\/a>. Here the focus is ordering: where the mess comes from, how to sort a conversation, how to collect several messages in a row before calling a bot, and how to send a sequence that must arrive in the right order.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why events arrive out of order<\/h2>\n\n\n\n<p>Five behaviors documented by Meta explain almost every case:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Behavior<\/th><th>What the documentation says<\/th><th>Effect on order<\/th><\/tr><\/thead><tbody><tr><td>Retries<\/td><td>If your endpoint does not return <code>200<\/code>, Meta retries with decreasing frequency for up to 7 days, and retries can produce duplicates<\/td><td>An old event arrives after newer ones<\/td><\/tr><tr><td>Batching<\/td><td>A single <code>POST<\/code> can carry up to 1,000 updates, but batching is not guaranteed<\/td><td>The same kind of event sometimes comes together, sometimes in separate, simultaneous requests<\/td><\/tr><tr><td>Skipped status<\/td><td>When a message is delivered and read at the same time (the user has the chat open), the <code>delivered<\/code> webhook is not sent<\/td><td>You get <code>read<\/code> without ever getting <code>delivered<\/code><\/td><\/tr><tr><td>Several statuses per message<\/td><td>Each sent message can produce up to three status webhooks (<code>sent<\/code>, <code>delivered<\/code>, <code>read<\/code>), plus <code>played<\/code> for voice messages and <code>failed<\/code><\/td><td>Each one travels independently<\/td><\/tr><tr><td>Sending in sequence<\/td><td>Several messages sent back to back may not be delivered in the order of your API calls<\/td><td>The user may see message 2 before message 1<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Sources: <a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/webhooks\/overview\" target=\"_blank\" rel=\"noreferrer noopener\">webhooks overview<\/a>, <a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/webhooks\/create-webhook-endpoint\" target=\"_blank\" rel=\"noreferrer noopener\">create a webhook endpoint<\/a>, <a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/webhooks\/reference\/messages\/status\" target=\"_blank\" rel=\"noreferrer noopener\">status webhook reference<\/a> and <a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/messages\/send-messages\" target=\"_blank\" rel=\"noreferrer noopener\">send messages<\/a>.<\/p>\n\n\n\n<p>None of these pages promises webhook delivery order. Then add your own side: if your server runs more than one worker or replica, two <code>POST<\/code> requests arriving milliseconds apart are processed in parallel, and whichever finishes first writes first.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The field that rules: the event <code>timestamp<\/code><\/h2>\n\n\n\n<p>Every inbound message and every status carries a <code>timestamp<\/code> in Unix seconds, as a string:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-json\">{\n  \"messages\": [{\n    \"from\": \"5511988887777\",\n    \"id\": \"wamid.HBgLNTUx...\",\n    \"timestamp\": \"1764000000\",\n    \"type\": \"text\",\n    \"text\": { \"body\": \"Hi, I want to change the size\" }\n  }]\n}<\/code><\/pre>\n\n\n\n<p>Three practical rules:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Sort by the event <code>timestamp<\/code>, never by the time you received it.<\/strong> An event retried hours later keeps its original time.<\/li>\n\n\n<li><strong>Expect ties.<\/strong> The resolution is one second. A fast typist sends two or three messages within the same second. Use an arrival number (a <code>bigserial<\/code> column) as the tiebreaker.<\/li>\n\n\n<li><strong>Do not sort by <code>wamid<\/code>.<\/strong> It is an opaque identifier: use it to deduplicate and to link statuses to messages, not to order them.<\/li>\n\n<\/ul>\n\n\n\n<p>The fields for each message type are in <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-payload-examples\/\">WhatsApp webhook payload examples<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Store first, sort later<\/h2>\n\n\n\n<p>The most robust way to deal with ordering is not to depend on it at arrival time. The webhook only stores each message with Meta&#8217;s time and an arrival number, then returns <code>200<\/code>. Sorting happens when you read.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-sql\">CREATE TABLE inbound_messages (\n  seq         bigserial PRIMARY KEY,          -- arrival order (tiebreaker)\n  wamid       text UNIQUE NOT NULL,           -- deduplication\n  contact_key text NOT NULL,                  -- who sent it\n  meta_ts     bigint NOT NULL,                -- Meta timestamp (seconds)\n  received_at timestamptz NOT NULL DEFAULT now(),\n  raw         jsonb NOT NULL,\n  handled_at  timestamptz\n);\n\nCREATE INDEX inbound_by_contact ON inbound_messages (contact_key, meta_ts, seq);<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-js\">import pg from 'pg';\n\nexport const pool = new pg.Pool(); \/\/ reads PGHOST, PGUSER etc. from the environment\n\nexport async function saveInbound(payload) {\n  const saved = new Set();\n  for (const entry of payload.entry ?? []) {\n    for (const change of entry.changes ?? []) {\n      for (const m of change.value?.messages ?? []) {\n        \/\/ Users with a username may arrive without \"from\"; Meta recommends\n        \/\/ using from_user_id to identify the sender.\n        const contactKey = m.from_user_id ?? m.from;\n        await pool.query(\n          `INSERT INTO inbound_messages (wamid, contact_key, meta_ts, raw)\n           VALUES ($1, $2, $3, $4)\n           ON CONFLICT (wamid) DO NOTHING`,\n          [m.id, contactKey, Number(m.timestamp), m],\n        );\n        saved.add(contactKey);\n      }\n    }\n  }\n  return [...saved]; \/\/ contacts with new messages\n}<\/code><\/pre>\n\n\n\n<p><code>ON CONFLICT (wamid) DO NOTHING<\/code> drops the retry without an error. Full deduplication, including statuses and side effects, is covered in <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-duplicate-events-idempotency\/\">duplicate webhooks and idempotency<\/a>.<\/p>\n\n\n\n<p>To display the conversation, the query is always the same:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-sql\">SELECT wamid, meta_ts, raw\nFROM inbound_messages\nWHERE contact_key = $1\nORDER BY meta_ts, seq;<\/code><\/pre>\n\n\n\n<p>One note on the key: if your account sometimes receives <code>from<\/code> and sometimes only <code>from_user_id<\/code> for the same customer, keep a mapping table between the two so the conversation does not split in two.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Late events after an outage<\/h2>\n\n\n\n<p>If your endpoint was down for two hours, Meta retries what was pending once it comes back. Those events land &#8220;in the past&#8221;: their <code>meta_ts<\/code> is earlier than messages you have already processed.<\/p>\n\n\n\n<p>With sorting at read time, the conversation view fixes itself. The care goes into automations:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Do not answer old messages as if they were new.<\/strong> Before sending an automatic reply, compare <code>meta_ts<\/code> with the current time. A question from two hours ago that an agent has already answered should not trigger the bot.<\/li>\n\n\n<li><strong>Recompute anything that depends on the customer&#8217;s last message.<\/strong> The <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-24-hour-customer-service-window\/\">24-hour customer service window<\/a> counts from the customer&#8217;s last message; use the highest <code>meta_ts<\/code>, not the last inserted row.<\/li>\n\n\n<li><strong>Button replies carry a reference.<\/strong> When the user taps a quick-reply button in a template, the webhook includes <code>context.id<\/code>, the <code>wamid<\/code> of the message that held the button. Use it to tie the reply to the right question even if it arrives out of order. To reply quoting a specific message, see <a href=\"https:\/\/vectalk.com.br\/blog\/en\/reply-to-specific-message-whatsapp-api\/\">how to reply to a specific message<\/a>.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">One contact at a time: serialize processing<\/h2>\n\n\n\n<p>Sorting at read time fixes the display. For processing (bot, CRM, business rules) the problem is different: two workers handling messages from the same customer at the same time can reply out of order or twice.<\/p>\n\n\n\n<p>The fix is to serialize per contact and parallelize across contacts. In PostgreSQL, a transaction-level advisory lock does this with no extra infrastructure: only one transaction at a time holds the lock for a <code>contact_key<\/code>, and it is released on <code>COMMIT<\/code> or <code>ROLLBACK<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-js\">export async function processContact(contactKey, handler) {\n  const client = await pool.connect();\n  try {\n    await client.query('BEGIN');\n    \/\/ Waits if another worker is processing this contact.\n    await client.query('SELECT pg_advisory_xact_lock(hashtext($1))', [contactKey]);\n\n    const { rows } = await client.query(\n      `SELECT seq, wamid, meta_ts, raw\n       FROM inbound_messages\n       WHERE contact_key = $1 AND handled_at IS NULL\n       ORDER BY meta_ts, seq`,\n      [contactKey],\n    );\n\n    if (rows.length &gt; 0) {\n      await handler(contactKey, rows);\n      await client.query(\n        'UPDATE inbound_messages SET handled_at = now() WHERE seq = ANY($1::bigint[])',\n        [rows.map((r) =&gt; r.seq)],\n      );\n    }\n    await client.query('COMMIT');\n  } catch (err) {\n    await client.query('ROLLBACK');\n    throw err;\n  } finally {\n    client.release();\n  }\n}<\/code><\/pre>\n\n\n\n<p>If you use a queue, the principle is the same: the partition key is the contact. In queues with groups or partitions, use <code>contact_key<\/code> as the key; in simple queues, keep the lock in the database. The article on a <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-queue-redis-bullmq\/\">WhatsApp API queue with Redis and BullMQ<\/a> covers the sending side.<\/p>\n\n\n\n<p>A warning: <code>handler<\/code> runs inside the transaction, so slow calls (AI, CRM) hold the connection. At high volume, switch to an &#8220;in progress&#8221; flag with a deadline and release the transaction before the external call.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Several messages in a row: buffer before calling the bot<\/h2>\n\n\n\n<p>WhatsApp users write in bursts: &#8220;hi&#8221;, &#8220;how are you?&#8221;, &#8220;I wanted to ask about my order&#8221;, &#8220;it&#8217;s 4821&#8221;. If the bot answers each one, the user gets four disjointed replies, and their order depends on which AI call finished first.<\/p>\n\n\n\n<p>The pattern is a short per-contact buffer (debounce): each new message pushes the reply back a few seconds, with a ceiling for people who keep typing. When the deadline passes, the bot receives all pending messages at once, already sorted.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-sql\">CREATE TABLE pending_turns (\n  contact_key text PRIMARY KEY,\n  first_at    timestamptz NOT NULL DEFAULT now(),\n  due_at      timestamptz NOT NULL\n);<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-js\">const QUIET_SECONDS = 4;  \/\/ wait after the last message\nconst MAX_SECONDS = 15;   \/\/ ceiling counted from the first one\n\nexport async function scheduleTurn(contactKey) {\n  await pool.query(\n    `INSERT INTO pending_turns (contact_key, due_at)\n     VALUES ($1, now() + make_interval(secs =&gt; $2))\n     ON CONFLICT (contact_key) DO UPDATE SET\n       due_at = LEAST(\n         pending_turns.first_at + make_interval(secs =&gt; $3),\n         now() + make_interval(secs =&gt; $2)\n       )`,\n    [contactKey, QUIET_SECONDS, MAX_SECONDS],\n  );\n}\n\nasync function tick(answerWithBot) {\n  const { rows } = await pool.query(\n    `DELETE FROM pending_turns\n     WHERE contact_key IN (\n       SELECT contact_key FROM pending_turns\n       WHERE due_at &lt;= now()\n       ORDER BY due_at\n       LIMIT 20\n       FOR UPDATE SKIP LOCKED\n     )\n     RETURNING contact_key`,\n  );\n  for (const r of rows) {\n    await processContact(r.contact_key, answerWithBot);\n  }\n}\n\nexport function startTurnWorker(answerWithBot) {\n  setInterval(() =&gt; {\n    tick(answerWithBot).catch((err) =&gt; console.error('turn worker', err));\n  }, 1000);\n}<\/code><\/pre>\n\n\n\n<p>In the webhook, after <code>saveInbound<\/code>, call <code>scheduleTurn<\/code> for each returned contact. <code>FOR UPDATE SKIP LOCKED<\/code> lets you run several workers without two of them grabbing the same contact, and <code>processContact<\/code> keeps the order inside it. The 4 and 15 second values are a starting point; tune them to your audience. To build the bot itself, see the guide to an <a href=\"https:\/\/vectalk.com.br\/blog\/en\/ai-chatbot-whatsapp-api\/\">AI chatbot on the WhatsApp API<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Statuses: derive state from history, not from the last event<\/h2>\n\n\n\n<p>For messages you send, ordering problems show up in statuses. The <a href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-api-message-status-webhook\/\">message status<\/a> article shows how to update a row without regressing. An alternative that solves ordering, duplicates and the race with sending all at once is to keep every status you receive in a log and compute the state from it.<\/p>\n\n\n\n<p>The race goes like this: you call the API, Meta answers with the <code>wamid<\/code>, but the <code>sent<\/code> webhook can arrive before you store that <code>wamid<\/code> in your database. If the webhook code runs <code>UPDATE ... WHERE wamid = $1<\/code>, nothing is updated and the status is lost. With a log, the status is kept even without a matching message.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-sql\">CREATE TABLE status_events (\n  wamid      text NOT NULL,\n  status     text NOT NULL,\n  meta_ts    bigint NOT NULL,\n  raw        jsonb NOT NULL,\n  PRIMARY KEY (wamid, status, meta_ts)\n);<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-js\">const RANK = { sent: 1, delivered: 2, read: 3, played: 4 };\n\n\/\/ Same result in any arrival order (commutative) and with duplicates.\nexport function deriveState(events) {\n  const s = { status: null, rank: 0, sentAt: null, deliveredAt: null,\n              readAt: null, playedAt: null, failed: null, pricing: null };\n\n  for (const e of events) {\n    const ts = Number(e.timestamp);\n    if (e.pricing) s.pricing = e.pricing; \/\/ only present in one of the statuses\n\n    if (e.status === 'failed') {\n      s.failed = { ts, code: e.errors?.[0]?.code ?? null };\n      continue;\n    }\n    const rank = RANK[e.status];\n    if (!rank) continue; \/\/ unknown status: skip here, log it\n\n    const key = `${e.status}At`;\n    s[key] = s[key] === null ? ts : Math.min(s[key], ts);\n    \/\/ read without delivered: Meta does not send delivered when delivery and\n    \/\/ read happen together, so a read implies delivery.\n    if (rank &gt;= 3) s.deliveredAt = s.deliveredAt === null ? ts : Math.min(s.deliveredAt, ts);\n    if (rank &gt; s.rank) { s.rank = rank; s.status = e.status; }\n  }\n  if (s.rank === 0 &amp;&amp; s.failed) s.status = 'failed';\n  return s;\n}<\/code><\/pre>\n\n\n\n<p>In the webhook, run <code>INSERT ... ON CONFLICT DO NOTHING<\/code> into <code>status_events<\/code> and recompute the message state from all rows for that <code>wamid<\/code>. After sending, when you store the <code>wamid<\/code> in your outbound messages table, recompute as well: any statuses that arrived earlier are already in the log. The <code>pricing<\/code> object appears in only one of the statuses, so keeping it when it shows up (as in the code) avoids losing billing information.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sending in sequence: wait for <code>delivered<\/code><\/h2>\n\n\n\n<p>Meta&#8217;s sending page is direct: if you send several messages, they may not be delivered in the order of your API calls; if order matters, confirm each one was delivered through the <code>delivered<\/code> status before sending the next. That applies to step-by-step instructions, a boleto (a Brazilian bank payment slip) followed by how to pay it, or a photo followed by the price.<\/p>\n\n\n\n<p>Since <code>delivered<\/code> can be skipped when the message has already been read, accept either <code>delivered<\/code> or <code>read<\/code> as the release signal. And because both can arrive (and arrive twice), advancing must be idempotent:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-sql\">CREATE TABLE sequence_steps (\n  id        bigserial PRIMARY KEY,\n  seq_id    text NOT NULL,\n  position  int  NOT NULL,\n  to_wa_id  text NOT NULL,\n  payload   jsonb NOT NULL,\n  wamid     text,\n  sent_at   timestamptz,\n  UNIQUE (seq_id, position)\n);<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"language-js\">export async function onStatusForSequence(st, sendMessage) {\n  if (st.status !== 'delivered' &amp;&amp; st.status !== 'read') return;\n\n  \/\/ Claims the next step only once, even with delivered + read + retries.\n  const { rows } = await pool.query(\n    `UPDATE sequence_steps nxt SET sent_at = now()\n     FROM sequence_steps cur\n     WHERE cur.wamid = $1\n       AND nxt.seq_id = cur.seq_id\n       AND nxt.position = cur.position + 1\n       AND nxt.sent_at IS NULL\n     RETURNING nxt.id, nxt.to_wa_id, nxt.payload`,\n    [st.id],\n  );\n\n  for (const step of rows) {\n    const wamid = await sendMessage(step.to_wa_id, step.payload);\n    await pool.query('UPDATE sequence_steps SET wamid = $2 WHERE id = $1', [step.id, wamid]);\n  }\n}<\/code><\/pre>\n\n\n\n<p>Two caveats. First, your code sends step one when it creates the sequence; the webhook only handles the following steps. Second, <code>delivered<\/code> can take a while if the customer&#8217;s phone is off, and the sequence waits until then. For content that does not need strict order, put everything in a single message (for example, an image with a caption) and skip the wait.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Showing the conversation on screen<\/h2>\n\n\n\n<p>If you run your own agent inbox, three decisions prevent confusion:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Sort by <code>meta_ts<\/code> and break ties by arrival.<\/strong> For sent messages, use the <code>timestamp<\/code> of the <code>sent<\/code> status as the message time.<\/li>\n\n\n<li><strong>Show the most advanced status seen so far.<\/strong> If <code>read<\/code> arrived, show it as read, even without <code>delivered<\/code>.<\/li>\n\n\n<li><strong>Reposition late events.<\/strong> A message that arrives with an old time belongs in the right place in the conversation, not at the end. If the UI updates in real time, push the event with its <code>meta_ts<\/code> and let the client re-sort.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How to do this with Vectalk<\/h2>\n\n\n\n<p>Vectalk is a proxy for Meta&#8217;s official Cloud API: the Hub receives events from Meta and forwards them to the URLs you registered with the same payload, according to the <a href=\"https:\/\/docs.vectalk.com.br\/concepts\/webhooks\">Vectalk webhooks documentation<\/a>. Everything in this article applies unchanged: <code>timestamp<\/code>, <code>wamid<\/code>, <code>context<\/code> and statuses are the same fields.<\/p>\n\n\n\n<p>Two specific points:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The Hub expects <code>200<\/code> in under 20 seconds and retries if it does not get it. As with Meta, retries are a source of late and duplicate events, and the &#8220;store, respond, sort later&#8221; pattern handles both.<\/li>\n\n\n<li>You can register several URLs per instance with <code>POST https:\/\/apis.vectalk.com.br\/api\/webhooks<\/code>, and all of them receive the same event. If two of your services consume the same number, decide which one replies to the customer so replies are not duplicated.<\/li>\n\n<\/ul>\n\n\n\n<p>Sending uses <code>POST https:\/\/apis.vectalk.com.br\/api\/messages<\/code> with the same JSON as the Cloud API, as in the <a href=\"https:\/\/docs.vectalk.com.br\/quickstart\">quickstart<\/a>. For the big picture, see the <a href=\"https:\/\/vectalk.com.br\/blog\/en\/official-whatsapp-api\/\">official WhatsApp API guide<\/a>. To get started, <a href=\"https:\/\/apps.vectalk.com.br\/register\">create your account<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently asked questions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Does Meta guarantee webhook order?<\/h3>\n\n\n\n<p>No. The webhook pages do not promise delivery order, and retries for up to 7 days make old events arrive after new ones. Sort by the event <code>timestamp<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why did I get <code>read<\/code> without <code>delivered<\/code>?<\/h3>\n\n\n\n<p>Because when a message is delivered and read at the same time (the user has the chat open), Meta does not send the <code>delivered<\/code> webhook. Treat <code>read<\/code> as proof of delivery.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Two messages with the same <code>timestamp<\/code>: which came first?<\/h3>\n\n\n\n<p>The <code>timestamp<\/code> has one-second resolution, so ties are common. Use an arrival number in your database as the tiebreaker. Do not sort by <code>wamid<\/code>: it is an identifier, not a sequence.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How do I make sure the user receives my messages in the order I sent them?<\/h3>\n\n\n\n<p>Send the next one only after you receive <code>delivered<\/code> (or <code>read<\/code>) for the previous one, as Meta&#8217;s sending documentation recommends. If order is not critical, put the content in a single message.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">I use a queue: do I need to worry about order?<\/h3>\n\n\n\n<p>Yes. Several consumers processing the same contact in parallel will shuffle the order. Partition by contact or use a per-contact lock, like the advisory lock in the example.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>Official sources checked on November 24, 2026:<\/strong> <a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/webhooks\/overview\" target=\"_blank\" rel=\"noreferrer noopener\">Meta: webhooks overview<\/a>, <a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/webhooks\/create-webhook-endpoint\" target=\"_blank\" rel=\"noreferrer noopener\">Meta: create a webhook endpoint<\/a>, <a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/webhooks\/reference\/messages\/status\" target=\"_blank\" rel=\"noreferrer noopener\">Meta: status webhook<\/a>, <a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/webhooks\/reference\/messages\" target=\"_blank\" rel=\"noreferrer noopener\">Meta: messages webhook<\/a>, <a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/webhooks\/reference\/messages\/button\" target=\"_blank\" rel=\"noreferrer noopener\">Meta: button webhook<\/a>, <a href=\"https:\/\/developers.facebook.com\/documentation\/business-messaging\/whatsapp\/messages\/send-messages\" target=\"_blank\" rel=\"noreferrer noopener\">Meta: send messages<\/a>, <a href=\"https:\/\/www.postgresql.org\/docs\/current\/explicit-locking.html\" target=\"_blank\" rel=\"noreferrer noopener\">PostgreSQL: advisory locks<\/a>, <a href=\"https:\/\/www.postgresql.org\/docs\/current\/sql-select.html\" target=\"_blank\" rel=\"noreferrer noopener\">PostgreSQL: SELECT &#8230; SKIP LOCKED<\/a>, <a href=\"https:\/\/docs.vectalk.com.br\/concepts\/webhooks\">Vectalk: webhooks<\/a>, <a href=\"https:\/\/docs.vectalk.com.br\/quickstart\">Vectalk: quickstart<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Why messages and statuses (sent, delivered, read) arrive out of order on the WhatsApp webhook, and how to rebuild the right sequence in your system.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-2153","post","type-post","status-publish","format-standard","hentry","category-blog"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>WhatsApp Webhook Message Order Explained | Vectalk<\/title>\n<meta name=\"description\" content=\"WhatsApp webhook message order: why messages and statuses arrive out of order and how to rebuild the sequence with timestamps, locks and Node.js.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-message-order\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WhatsApp Webhook Message Order Explained | Vectalk\" \/>\n<meta property=\"og:description\" content=\"WhatsApp webhook message order: why messages and statuses arrive out of order and how to rebuild the sequence with timestamps, locks and Node.js.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-message-order\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Vectalk\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-24T19:28:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-24T19:28:20+00:00\" \/>\n<meta name=\"author\" content=\"wanderleyfcunha\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"wanderleyfcunha\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-webhook-message-order\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-webhook-message-order\\\/\"},\"author\":{\"name\":\"wanderleyfcunha\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#\\\/schema\\\/person\\\/ff36ecd9d8257856f227f8e5d639db2b\"},\"headline\":\"WhatsApp webhook message and status order: why events arrive out of order\",\"datePublished\":\"2026-11-24T19:28:12+00:00\",\"dateModified\":\"2026-11-24T19:28:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-webhook-message-order\\\/\"},\"wordCount\":1872,\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-webhook-message-order\\\/\",\"url\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-webhook-message-order\\\/\",\"name\":\"WhatsApp Webhook Message Order Explained | Vectalk\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#website\"},\"datePublished\":\"2026-11-24T19:28:12+00:00\",\"dateModified\":\"2026-11-24T19:28:20+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#\\\/schema\\\/person\\\/ff36ecd9d8257856f227f8e5d639db2b\"},\"description\":\"WhatsApp webhook message order: why messages and statuses arrive out of order and how to rebuild the sequence with timestamps, locks and Node.js.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-webhook-message-order\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-webhook-message-order\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/en\\\/whatsapp-webhook-message-order\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WhatsApp webhook message and status order: why events arrive out of order\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/\",\"name\":\"Blog Vectalk\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/vectalk.com.br\\\/blog\\\/#\\\/schema\\\/person\\\/ff36ecd9d8257856f227f8e5d639db2b\",\"name\":\"wanderleyfcunha\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g\",\"caption\":\"wanderleyfcunha\"},\"sameAs\":[\"https:\\\/\\\/vectalk.com.br\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WhatsApp Webhook Message Order Explained | Vectalk","description":"WhatsApp webhook message order: why messages and statuses arrive out of order and how to rebuild the sequence with timestamps, locks and Node.js.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-message-order\/","og_locale":"en_US","og_type":"article","og_title":"WhatsApp Webhook Message Order Explained | Vectalk","og_description":"WhatsApp webhook message order: why messages and statuses arrive out of order and how to rebuild the sequence with timestamps, locks and Node.js.","og_url":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-message-order\/","og_site_name":"Blog Vectalk","article_published_time":"2026-11-24T19:28:12+00:00","article_modified_time":"2026-11-24T19:28:20+00:00","author":"wanderleyfcunha","twitter_card":"summary_large_image","twitter_misc":{"Written by":"wanderleyfcunha","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-message-order\/#article","isPartOf":{"@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-message-order\/"},"author":{"name":"wanderleyfcunha","@id":"https:\/\/vectalk.com.br\/blog\/#\/schema\/person\/ff36ecd9d8257856f227f8e5d639db2b"},"headline":"WhatsApp webhook message and status order: why events arrive out of order","datePublished":"2026-11-24T19:28:12+00:00","dateModified":"2026-11-24T19:28:20+00:00","mainEntityOfPage":{"@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-message-order\/"},"wordCount":1872,"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-message-order\/","url":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-message-order\/","name":"WhatsApp Webhook Message Order Explained | Vectalk","isPartOf":{"@id":"https:\/\/vectalk.com.br\/blog\/#website"},"datePublished":"2026-11-24T19:28:12+00:00","dateModified":"2026-11-24T19:28:20+00:00","author":{"@id":"https:\/\/vectalk.com.br\/blog\/#\/schema\/person\/ff36ecd9d8257856f227f8e5d639db2b"},"description":"WhatsApp webhook message order: why messages and statuses arrive out of order and how to rebuild the sequence with timestamps, locks and Node.js.","breadcrumb":{"@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-message-order\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-message-order\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/vectalk.com.br\/blog\/en\/whatsapp-webhook-message-order\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vectalk.com.br\/blog\/"},{"@type":"ListItem","position":2,"name":"WhatsApp webhook message and status order: why events arrive out of order"}]},{"@type":"WebSite","@id":"https:\/\/vectalk.com.br\/blog\/#website","url":"https:\/\/vectalk.com.br\/blog\/","name":"Blog Vectalk","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vectalk.com.br\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/vectalk.com.br\/blog\/#\/schema\/person\/ff36ecd9d8257856f227f8e5d639db2b","name":"wanderleyfcunha","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/21c37077f1731eb558973f27a7b647d55f72fde5200a843ac5f5345b247ea725?s=96&d=mm&r=g","caption":"wanderleyfcunha"},"sameAs":["https:\/\/vectalk.com.br\/blog"]}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/posts\/2153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/comments?post=2153"}],"version-history":[{"count":1,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/posts\/2153\/revisions"}],"predecessor-version":[{"id":2156,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/posts\/2153\/revisions\/2156"}],"wp:attachment":[{"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/media?parent=2153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/categories?post=2153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vectalk.com.br\/blog\/wp-json\/wp\/v2\/tags?post=2153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}