Skip to main content

Message buffer system with Redis for efficient processing

Workflow preview

Workflow preview
100%
Message buffer system with Redis for efficient processing preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

Message Batching Buffer Workflow (n8n) This workflow implements a lightweight message batching buffer using Redis for temporary storage and a JavaScript consolidation function to merge messages....

Best for

  • Support Chatbot automation workflows
  • AI Summarization automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.manualtrigger, n8n-nodes-base.noop, n8n-nodes-base.code, n8n-nodes-base.redis, n8n-nodes-base.set, n8n-nodes-base.if, @n8n/n8n-nodes-langchain.chattrigger, n8n-nodes-base.wait

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Edisson Garcia.

Original n8n.io source

1.1 Workflow description

Title
Message buffer system with Redis for efficient processing
Workflow name
Message buffer system with Redis for efficient processing

🚀 Message-Batching Buffer Workflow (n8n)

This workflow implements a lightweight message-batching buffer using Redis for temporary storage and a JavaScript consolidation function to merge messages. It collects incoming user messages per session, waits for a configurable inactivity window or batch size threshold, consolidates buffered messages via custom code, then clears the buffer and returns the combined response—all without external LLM calls.


🔑 Key Features

  • Redis-backed buffer queues incoming messages per context_id.
  • Centralized Config Parameters node to adjust thresholds and timeouts in one place.
  • Dynamic wait time based on message length (configurable minWords, waitLong, waitShort).
  • Batch trigger fires on inactivity timeout or when buffer_countbatchThreshold.
  • Zero-cost consolidation via built-in JavaScript Function (consolidate buffer)—no GPT-4 or external API required.

⚙️ Setup Instructions

  1. Extract Session & Message

    • Trigger: When chat message received (webhook) or When clicking ‘Test workflow’ (manual).
    • Map inputs: set variables context_id and message into a Set node named Mock input data (for testing) or a proper mapping node in production.
  2. Config Parameters

    • Add a Set node Config Parameters with:

      minWords: 3         # Word threshold
      waitLong: 10        # Timeout (s) for long messages
      waitShort: 20       # Timeout (s) for short messages
      batchThreshold: 3   # Messages to trigger batch early
      
    • All downstream nodes reference these JSON values dynamically.

  3. Determine Wait Time

    • Node: get wait seconds (Code)

    • JS code:

      const msg = $json.message || '';
      const wordCount = msg.split(/\s+/).filter(w => w).length;
      const { minWords, waitLong, waitShort } = items[0].json;
      const waitSeconds = wordCount < minWords ? waitShort : waitLong;
      return [{ json: { context_id: $json.context_id, message: msg, waitSeconds } }];
      
  4. Buffer Message in Redis

    • Buffer messages: LPUSH buffer_in:{{$json.context_id}} with payload {text, timestamp}.
    • Set buffer_count increment: INCR buffer_count:{{$json.context_id}} with TTL {{$json.waitSeconds + 60}}.
    • Set last_seen: record last_seen:{{$json.context_id}} timestamp with same TTL.
  5. Check & Set Waiting Flag

    • Get waiting_reply: if null, Set waiting_reply to true with TTL {{$json.waitSeconds}}; else exit.
  6. Wait for Inactivity

    • WaitSeconds (webhook): pauses for {{$json.waitSeconds}} seconds before batch evaluation.
  7. Check Batch Trigger

    • Get last_seen and Get buffer_count.
    • IF (now - last_seen) ≥ waitSeconds * 1000 OR buffer_count ≥ batchThreshold, proceed; else use Wait node to retry.
  8. Consolidate Buffer

    • consolidate buffer (Code):

      const j = items[0].json;
      const raw = Array.isArray(j.buffer) ? j.buffer : [];
      const buffer = raw.map(x => {
        try { return typeof x === 'string' ? JSON.parse(x) : x;
        } catch { return null; }
      }).filter(Boolean);
      buffer.sort((a, b) => new Date(a.timestamp) - new Date(b.timestamp));
      const texts = buffer.map(e => e.text?.trim()).filter(Boolean);
      const unique = [...new Set(texts)];
      const message = unique.join(' ');
      return [{ json: { context_id: j.context_id, message } }];
      
  9. Cleanup & Respond

    • Delete Redis keys: buffer_in, buffer_count, waiting_reply, last_seen (for the context_id).
    • Return consolidated message to the user via your chat integration.

🛠 Customization Guidance

  • Adjust thresholds by editing the Config Parameters node.
  • Change concatenation (e.g., line breaks) by modifying the join separator in the consolidation code.
  • Add filters (e.g., ignore empty or system messages) inside the consolidation Function.
  • Monitor performance: for very high volume, consider sharding Redis keys by date or user segments.

© 2025 Innovatex • Automation & AI Solutions • innovatexiot.carrd.coLinkedIn

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - When clicking ‘Test workflow’

Type / Role
n8n-nodes-base.manualTrigger - manualTrigger
Config choices
Version 1

Block 2 - No Operation, do nothing1

Type / Role
n8n-nodes-base.noOp - noOp
Config choices
Version 1

Block 3 - get wait seconds

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 4 - Set last_seen

Type / Role
n8n-nodes-base.redis - redis
Config choices
Version 1

Block 5 - Get waiting_reply

Type / Role
n8n-nodes-base.redis - redis
Config choices
Version 1

Block 6 - Mod input

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 7 - waiting_reply?

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 8 - When chat message received

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.1

Block 9 - Set waiting_reply

Type / Role
n8n-nodes-base.redis - redis
Config choices
Version 1

Block 10 - Get buffer

Type / Role
n8n-nodes-base.redis - redis
Config choices
Version 1

Block 11 - Delete buffer_in

Type / Role
n8n-nodes-base.redis - redis
Config choices
Version 1

Block 12 - Delete waiting_reply

Type / Role
n8n-nodes-base.redis - redis
Config choices
Version 1

Block 13 - WaitSeconds

Type / Role
n8n-nodes-base.wait - wait
Config choices
Version 1.1

Block 14 - Buffer messages

Type / Role
n8n-nodes-base.redis - redis
Config choices
Version 1

Block 15 - Set buffer_count increment

Type / Role
n8n-nodes-base.redis - redis
Config choices
Version 1

Block 16 - Get last_seen

Type / Role
n8n-nodes-base.redis - redis
Config choices
Version 1

Block 17 - Get buffer_count

Type / Role
n8n-nodes-base.redis - redis
Config choices
Version 1

Block 18 - Map ouput

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 19 - Check Inactivity + Count

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 20 - Delete waiting_reply1

Type / Role
n8n-nodes-base.redis - redis
Config choices
Version 1

Block 21 - No Operation, do nothing2

Type / Role
n8n-nodes-base.noOp - noOp
Config choices
Version 1

Block 22 - Wait

Type / Role
n8n-nodes-base.wait - wait
Config choices
Version 1.1

Block 23 - When Executed by Another Workflow

Type / Role
n8n-nodes-base.executeWorkflowTrigger - executeWorkflowTrigger
Config choices
Version 1.1

Block 24 - Mock input data

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Showing the first 24 of 30 workflow blocks. Download the JSON for the full node graph.

3. Summary Table

Workflow Message buffer system with Redis for efficient processing
Complexity advanced
Nodes 30
Categories Support Chatbot, AI Summarization
Author Edisson Garcia
Published 02 May 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/3832/3832.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Message buffer system with Redis for efficient processing do?

Message Batching Buffer Workflow (n8n) This workflow implements a lightweight message batching buffer using Redis for temporary storage and a JavaScript consolidation function to merge messages....

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Support Chatbot, AI Summarization use case.