How do I batch incoming webhook messages for 3-5 seconds before processing
Hi @Anjali_sharma Welcome!
Each webhook call is its own execution, so a single run can’t natively “wait” for the next messages. The reliable pattern is a debounce backed by external state (Redis): on every incoming message, append it to a Redis list keyed by the sender/session, write the current execution’s ID to a marker key, Wait 3 to 5 seconds, then check the marker. If it still holds your execution ID, no newer message arrived, so this run pulls the whole list, clears it, and processes the batch. If the marker changed, a newer message took over, so this run just exits. Order of nodes
- Webhook
- Redis (RPUSH the message onto a per-session list key)
- Redis (SET a “last execution” key to {{ $execution.id }})
- Wait (3 to 5 seconds)
- Redis (GET the “last execution” key)
- If ({{ $json.value }} equals {{ $execution.id }})
- true branch: Redis (LRANGE to read all, then DEL the list) and process the batch; false branch: do nothing
There’s a ready-made template that implements exactly this debounce: