Scalable AI Chat Message Buffering with Redis and LLMs - n8n Workflow

Deploy a robust n8n workflow for intelligent AI chat buffering using Redis. Aggregate rapid user messages into a single context for natural LLM responses via the OpenAI n8n node.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

AI developers building highly concurrent conversational interfaces.
n8n automation specialists seeking high-performance, stateful solutions.
Users looking for advanced n8n templates for handling concurrency.
Anyone needing to optimize LLM usage by reducing fragmented API calls.

Overview

Handling quick, fragmented input in AI chatbots—where a user types several messages rapidly—often leads to fragmented, unnatural AI responses. This specialized n8n workflow solves this by implementing an intelligent, session-specific buffer using Redis.

The core value is optimizing the conversation flow: the first message initiates a short buffering delay (default 15 seconds). Subsequent messages from the same user session during this window are immediately stored in the Redis queue but bypass the delay, ensuring no message is lost and eliminating performance bottlenecks. Once the buffer window expires, the n8n workflow aggregates all stored messages into a single, cohesive prompt, which is then sent to the LLM (like GPT-4-mini). This results in a single, well-informed AI response, providing a far more human-like interaction. This sophisticated logic makes this one of the most useful n8n templates for serious chat application development.

How it Works


  1. Trigger and Store: The process begins with the chat n8n trigger, capturing an incoming message and its unique session ID. The message is immediately stored (pushed) onto a session-specific list in Redis using the store n8n node.

  2. First Message Check: A counter is incremented. The checkfirstmessage n8n node determines if this is the initial message in the burst.

  3. Buffer Activation: If it is the first message, a timestamp is set in Redis, and the execution thread enters a buffering period via the wait n8n node. If it is a subsequent message, the n8n workflow thread terminates, having safely stored the message for later processing, enabling truly scalable concurrency.

  4. Buffer Completion: Once the 15-second buffer delay is met (verified by the checkdelay n8n node), the n8n workflow proceeds.

  5. Aggregation Loop: The n8n workflow enters a loop: it continuously uses the extract n8n node to pop messages from the Redis queue, concatenating them using the setmessage n8n node, until the queue is fully drained (checkqueueisempty).

  6. AI Processing: The resulting aggregated text is passed to the AI Agent n8n node, which utilizes the OpenAI Chat Model (GPT-4-mini) and redischat_memory for stateful context. The AI generates a single, comprehensive response based on the full buffered context.

Installation Guide


  1. Import: Copy the provided n8n workflow JSON code and import it into your n8n instance using the "New" menu -> "Import from JSON."

  2. Redis Credentials: Configure the Redis credentials for the store, timestamp, count, gettimestamp, extract, getmessage, and setmessage n8n nodes, as well as the redischatmemory n8n node. This robust n8n workflow relies heavily on Redis for state management and buffering.

  3. OpenAI Credentials: Set up your OpenAI API key connection for the OpenAI Chat Model n8n node. The model is currently configured for optimal speed using gpt-4-mini.

  4. Activate Trigger: Ensure the chat n8n trigger is correctly linked to your chat platform (e.g., via a custom webhook or dedicated chat client), and set the n8n workflow to "Active."

  5. Customization: Adjust the buffer time (default 15 seconds, configured in the checkdelay n8n node) and Redis TTL values for fine-tuning performance.

Node Details

Chat Trigger (chat): The initiating n8n trigger. Captures incoming user messages and, critically, extracts the unique sessionId used across all Redis keys.
Redis Node (store): Pushes the raw incoming message onto the user-specific list: chat{{sessionId}}.
Redis Node (count): Increments a temporary session counter (counter{{sessionId}}) used solely to identify the first message in a burst.
IF Node (checkfirstmessage): Determines if the counter equals 1. If true, it initiates the 15-second buffer delay via the wait n8n node; if false, the message is buffered but the execution stops immediately.
Wait Node (wait): Pauses the execution of the thread initiated by the first message, allowing subsequent messages to queue up.
IF Node (checkdelay): Checks if the current time has exceeded the timestamp plus 15 seconds, confirming the buffer period is complete before extraction starts.
Redis Node (extract): Repeatedly pops individual messages from the Redis queue (chat{{sessionId}}) to begin aggregation.
Redis Node (setmessage): Manages the context building. It retrieves any partial message context and concatenates the newly extracted message, saving the combined string to a temporary key.
IF Node (checkqueueisempty): Controls the message aggregation loop, ensuring the flow moves to the AI only after all messages have been extracted.
AI Agent Node (AI Agent): Receives the final, complete buffered message context and orchestrates the LLM response.
LLM Chat OpenAI Node (OpenAI Chat Model): The language model used, configured as gpt-4-mini for efficient processing of the combined user input generated by this powerful n8n workflow.
Redis Chat Memory Node (redischatmemory): Provides stateful, persistent conversation history for the AI Agent, keyed by memory_{{sessionId}}.

Related n8n Workflows

Free

Nodes: 9 Nodes
Updated: December 26 2025
View all

Featured*