DDevArchive
Đăng nhập

Webhook & Integration: biến app thành platform

App đơn lẻ = tool. App kết nối 100 app khác = PLATFORM. Slack, Shopify, Stripe — tất cả thành công nhờ ecosystem. Webhook là cách đơn giản nhất để app bạn "nói chuyện" với thế giới bên ngoài.

Webhook: push notification giữa servers

Polling: “Có gì mới chưa? Có gì mới chưa?” — hỏi 1000 lần/phút = lãng phí. Webhook: “Khi có gì mới → tôi POST đến URL bạn.” — hiệu quả, real-time, không lãng phí.

Outgoing webhook: app bạn gửi event ra ngoài

// File: webhook-sender.ts
import crypto from 'crypto'

interface WebhookConfig {
  url: string
  secret: string
  events: string[]
}

async function sendWebhook(
  config: WebhookConfig,
  event: string,
  payload: Record<string, unknown>,
) {
  const body = JSON.stringify({ event, data: payload, ts: Date.now() })

  // Ký bằng HMAC để receiver verify nguồn gốc
  const signature = crypto.createHmac('sha256', config.secret)
    .update(body).digest('hex')

  await fetch(config.url, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-Webhook-Signature': signature,
    },
    body,
    signal: AbortSignal.timeout(10_000), // timeout 10s
  })
}

// Sử dụng: khi user tạo order mới
await sendWebhook(customerConfig, 'order.created', {
  orderId: 'ord_123',
  amount: 500000,
  status: 'paid',
})

Zapier/Make integration: kết nối 5000+ app

CáchEffortKết nối được
Tự build integration (Slack API, Gmail API…)2-5 ngày/integration1 app
Zapier Integration1-2 ngày setup5000+ apps tự động
Make.com (Integromat)1-2 ngày setup1500+ apps

Zapier model: bạn cung cấp Triggers (webhook events) + Actions (API endpoints) → Zapier kết nối với 5000 app. User tự tạo automation: “Khi có order mới → thêm row vào Google Sheet → gửi Slack notification.”

Security cho webhooks

Vấn đềSolution
Ai cũng POST vào webhook URLHMAC signature: verify nguồn gốc bằng shared secret
Replay attack: gửi lại request cũKiểm tra timestamp: reject nếu > 5 phút
Webhook endpoint bị DDoSRate limiting + IP allowlist
Receiver down, miss eventRetry 3 lần + event log để replay
💡 Webhook = growth lever

Shopify App Store có 8,000+ apps — tất cả kết nối qua webhook. Stripe, GitHub, Slack cũng vậy. Khi app bạn cho phép integrate → developer khác build trên nền bạn → ecosystem tự growth.

❓ Lợi ích lớn nhất của webhook so với polling?

  • Implement outgoing webhook với HMAC signature
  • Tạo webhook management UI cho user (URL, events, secret)
  • Setup retry cho webhook delivery fail
  • Nghiên cứu Zapier Developer Platform