What This Workflow Does
This workflow template demonstrates how to use n8n's built-in data tables as a persistent key-value store to maintain state between workflow executions. Unlike temporary variables that reset with each run, this solution preserves data across multiple triggers, enabling more complex automation scenarios that require memory of previous actions.
The implementation provides a reusable pattern for storing and retrieving values by unique keys, similar to how Redis or other key-value databases function, but without requiring external services. This is particularly valuable for tracking workflow execution counts, maintaining user session data, or implementing stateful automation logic.
How It Works
1. Data Table Setup
The workflow begins by initializing a data table with columns for keys and values. This table serves as the persistent storage layer that maintains state between workflow runs.
2. Value Storage Logic
When storing a value, the workflow first checks if the key exists. If found, it updates the existing record; if not, it creates a new entry. This ensures data integrity while allowing flexible updates.
3. Value Retrieval Process
For retrieval operations, the workflow queries the data table for the specified key and returns the associated value. The template includes error handling for cases where keys don't exist.
Pro tip: For production use, consider adding timestamp columns to implement data expiration logic and prevent your key-value store from growing indefinitely.
Who This Is For
This solution is ideal for n8n users who need to:
- Track state across multiple workflow executions
- Implement counters or progress tracking
- Store temporary data between automation runs
- Develop complex workflows that require memory of previous actions
- Avoid external database dependencies for simple state management
What You'll Need
- An active n8n instance (self-hosted or cloud)
- Basic familiarity with n8n's data table node
- Understanding of key-value storage concepts
- Clear identification of what data needs persistence
Quick Setup Guide
- Download and import the JSON template into your n8n instance
- Review the example data table structure
- Adapt the key naming convention to your use case
- Connect the storage and retrieval logic to your existing workflows
- Test with sample data before production deployment
Key Benefits
No external dependencies: Uses n8n's built-in data tables instead of requiring additional database services.
Persistent state management: Maintains variable values between workflow executions, enabling more complex automation logic.
Simple implementation: Provides a ready-to-use pattern that can be adapted to various use cases with minimal modification.
Lightweight solution: Ideal for small to medium data storage needs without the overhead of full database systems.