I’ve had two (somewhat) recent experiences with the Redux pattern:
- Building a web app using React + Redux
- Contributing to Holochain, which uses it for managing node state
I think that it worked well for the web app, but I don’t think it did for Holochain. Here are some of my thoughts on when it works well.
If you’re not already familiar with Redux, it helps you model state by defining different types of Actions and a Reducer that given the current state and an Action, produces the next state.
Based on that definition, Redux requires that:
- You have a clear set of Actions that will come from outside your system.
- You have a clear order in which Actions should be processed.
- You don’t mind having a single global state.
- Since global state inhibits local reasoning, you don’t have much complicated logic to reason about.
- Since global state requires synchronization, you’re not trying to do things in parallel.
- You don’t need to persist your state between executions.
Web sites (for the most part) meet all of these requirements:
- Yes, you have one action per button.
- Yes, your users can only click one button at a time; no ambigous ordering.
- Yes, you don’t mind having a single global state because
- Yes, you’re not doing complicated logic and
- Yes, you can’t possibly do things in parallel (it’s in the browser).
- Yes, your users expect the page to get reset after they close it.
Holochain meets only one of them:
- Yes, you have one action per possible network protocol event.
- No, since there are multiple agents producing actions (many other nodes, the user interacting with the UI), there isn’t a clear order in which actions should be processed.
- No, you do mind having a single global state because
- No, you are doing complicated logic and
- No, you do want to do things in parallel.
- No, you do need to persist your state and even be versatile with respect to power-loss, etc.
Since by design, most of the state that nodes need to keep track of should be within cryptographic data structures anyway, the need for a state management system at all pretty much doesn’t exist for Holochain.
Overall, I can’t wait to switch Holochain so that it doesn’t use Redux anymore. We’ll see how hard that ends up being…