Why I implemented Flux in a UI-less software project

Spaghetti is a wonderful meal, but a terrible software design.

I am currently developing a React Native library at my workplace, that implements background behavior and communicates with our backend. I am unsure to what extent I am allowed to describe what this library actually does, so I will have to remain vague on the subject. All you need to know is this library has to manage a state, and changes to this state should trigger actions from various entities. It should also be able to save its current state to a persistent store, and retrieve it back later.

When I started to think about how I should implement the state management, I came to the conclusion that to avoid turning my library into a bunch of spaghetti code (although I love spaghetti), I definitely had to work with a clean, proven design pattern. This is why I remembered that a friend of mine, who is more on the front-end side of the Force — and who wrote this great article on how to achieve reliable CI with JavaScript projects — had once told me about Flux and Redux. According to my erroneous understanding at the time, Flux and Redux were two different, but somehow related, frameworks for managing the state of an application.

However, I also remembered trying to understand how to use Redux (or was it Flux?) and only achieving to realize that it was complicated. Also, it seemed to me, at the time, that Flux and Redux were designed for applications, aka software with a UI, which my library is not. (I do realize that “software with a UI” is a poor definition of what an application is, but my library still isn’t.)

Having very little time to devote to my state manager implementation, I had the feeling that trying to learn how to use Redux (or Flux, whatever) was risky, since I was not sure it was really suited for my project — especially for the part about being able to save the current state to a persistent store and retrieve it back later. But during a conversation with my aforementioned friend on the matter, he told me this:

You can implement Flux without a library.

So Flux must not be a framework, after all.

So, what is really Flux?

Flux is not a library or a framework, it is an architecture. Redux, however, is a software library that evolves the ideas of Flux.

The principle behind Flux is simple: it’s a flux. Data “moves” in an unidirectional pattern.