Choosing a Context Storage Mechanism for Node‑RED Flows
Learn how to pick file, Redis, or in‑memory context storage for Node‑RED flows based on persistence, scalability, and setup effort.
09 Sept 2026, 14:53 UTC

Decision and Constraints
You need a way for Node‑RED flow context to survive a process restart. The solution must add little operational overhead, work with existing flows unchanged, and allow horizontal scaling if you later run multiple Node‑RED instances.
Options Comparison
| Option | Persistence | Scalability | Setup Complexity | Typical Use |
|---|---|---|---|---|
| Memory | None | Single process | None | Prototyping, stateless logic |
| File | Disk (JSON) | Single process (file locking) | Low | Small‑to‑medium deployments, easy backup |
| Redis | Remote DB | Horizontal (multiple nodes) | Medium | Distributed, high‑availability scenarios |
Trade‑offs
- Memory – fastest access but loses all context on every restart.
- File – simple disk persistence, low latency, but only one Node‑RED process can safely write the file; heavy write load can become a bottleneck and power loss may corrupt the JSON.
- Redis – enables shared context across instances and horizontal scaling, yet adds network latency and introduces an external service that must be monitored.
Implementation Steps
-
Locate the Node‑RED settings file, usually
$HOME/.node-red/settings.jsor the path passed with--settings. You need read/write permission on this file. -
Choose the storage module. For file‑based persistence add (or edit) the
contextsection:context: { storage: { module: 'localfilesystem', // optional: change the default directory dir: '/data/nodered/context' } }For Redis storage use:
context: { storage: { module: 'redisdb', // Redis connection details – adjust host, port, password if needed host: '127.0.0.1', port: 6379 } } -
Save the file and restart Node‑RED (e.g.,
systemctl restart noderedornode-red-stopfollowed bynode-red-start). -
Create a simple test flow:
- Inject node → Function node → Debug node.
- In the Function node set:
let count = flow.get('counter', 0); count = count + 1; flow.set('counter', count); return {payload: count}; - Deploy the flow.
Validation and Checks
-
Open the debug sidebar and click the inject node repeatedly. Observe the counter increasing (1, 2, 3 …).
-
Stop Node‑RED (
node-red-stopor system stop). -
If you used file storage, verify that a JSON file exists under the directory you set (e.g.,
/data/nodered/context/flow.json) and contains acounterproperty. -
If you used Redis, run
redis-cli GET 'node-red:flow:counter'(the exact key depends on Node‑RED's naming) to see the stored value. -
Start Node‑RED again and inject once more. The counter should continue from the last value (e.g., 4 if you stopped at 3).
-
As an extra check, manually edit the stored value (e.g., set the file's counter to 99 or run
redis-cli SET 'node-red:flow:counter' 99), restart Node‑RED, and inject; the flow should read the edited value, proving persistence.
Limitations and Practical Tips
- File storage relies on proper filesystem permissions; ensure the Node‑RED process can write to the chosen directory and consider placing it on a reliable volume with regular backups.
- Redis storage adds an external dependency; monitor Redis health (e.g.,
redis-cli ping) and plan for fallback or alerting if the database becomes unavailable. - If you anticipate running multiple Node‑RED instances, file storage is not suitable; choose Redis or another shared database.
- After changing the storage module, you must restart Node‑RED for the change to take effect; reverting to a previous module follows the same edit‑and‑restart steps.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.