Prompt
How do I accept inbound webhooks and enqueue jobs from them?
Latest observation
Oct 27, 2026
OpenAI APIWeb search: off
A common pattern is:
- Expose an HTTP endpoint to receive the webhook.
- Verify it (signature/shared secret/IP allowlist if applicable).
- Do the bare minimum quickly:
- parse the payload
- validate required fields
- create a job record or push a message to a queue
- return
2xximmediately
- Process the job asynchronously in a background worker.
Typical flow
1) Webhook receiver
Your server receives a POST like:
POST /webhooks/provider
Content-Type: application/json
X-Signature: ...
Handler should:
- authenticate the sender
- check idempotency (webhooks can be retried)
- enqueue a job
- respond
200 OKor202 Accepted
2) Queue the work
Use a durable queue such as:
- Redis queue: BullMQ, RQ, Sidekiq, Celery, etc.
- Cloud queue: SQS, Pub/Sub, RabbitMQ, Azure Queue, etc.
3) Worker
A separate process consumes jobs and performs the heavy work:
- calling APIs
- writing to DB
- sending emails
- generating files, etc.
Example in Node.js with Express + BullMQ
Webhook endpoint
import express from "express";
import { Queue } from "bullmq";
import IORedis from "ioredis";
const app = express();
app.use(express.json());
const connection = new IORedis(process.env.REDIS_URL);
const webhookQueue = new Queue("webhooks", { connection });
app.post("/webhooks/provider", async (req, res) => {
try {
// 1. Verify signature here (important!)
// 2. Validate payload
const { event_id, type, data } = req.body;
if (!event_id || !type) {
return res.status(400).send("Invalid payload");
}
// 3. Enqueue job
await webhookQueue.add(
"process-webhook",
{ event_id, type, data },
{
jobId: event_id, // helps dedupe retries
removeOnComplete: true,
removeOnFail: false,
}
);
// 4. Respond quickly
return res.status(202).send("Accepted");
} catch (err) {
console.error(err);
return res.status(500).send("Internal error");
}
});
app.listen(3000);
Worker
import { Worker } from "bullmq";
import IORedis from "ioredis";
const connection = new IORedis(process.env.REDIS_URL);
new Worker(
"webhooks",
async (job) => {
const { event_id, type, data } = job.data;
// Do the actual work here
console.log("Processing", event_id, type);
},
{ connection }
);
Important best practices
1) Verify the webhook
Never trust incoming webhooks blindly. Common verification methods:
- HMAC signature header
- shared secret token
- mTLS
- IP allowlist
2) Make processing idempotent
Webhook providers often retry delivery. Ensure the same event doesn’t run twice:
- use a unique
event_id - store processed event IDs in DB
- make queue job IDs deterministic
3) Return fast
Providers usually expect a response within seconds. Don’t:
- do long DB migrations
- call slow external APIs
- wait for background work to finish
4) Persist before acknowledging
If the job is important, store it durably before returning success:
- enqueue to a durable broker, or
- write to DB and let a worker pick it up
5) Handle retries and dead-lettering
Background jobs should have:
- retry limits
- exponential backoff
- dead-letter queue / failed jobs table
6) Log and monitor
Track:
- webhook delivery count
- queue depth
- processing latency
- failures and retries
If you want the simplest reliable architecture
Webhook endpoint → database “events” table → worker polls table
This is easy and durable:
- insert webhook payload into
incoming_webhooks - respond
202 - worker reads unprocessed rows and marks them done
It’s slower than a queue but very robust.
If you tell me your stack (Node/Python/Rails/.NET/etc.) and what queue system you use, I can give you a concrete implementation.