Redux is an implementation of "Facebook Flux". Flux is not a library or framework. It's simply a recommended architecture for web applications. I don't see how you can compare a concrete implementation with the abstract concept that motivated it. Facebook's actual implementation of a Flux architecture is Relay and the open source version is still in the very early stages. facebook.github.io/relay
– Charlie MartinSep 17 '15 at 4:22

2

@CharlieMartin By FB Flux I ment applicaiton like this github.com/facebook/flux/tree/master/examples. My current project is written on FB Flux (due FB Flux). If you want you may think as Redux architecture over FB Flux architecture.
– VB_Sep 17 '15 at 6:39

Relay is not an implementation of Flux - Relay/GraphQL is more concerned with managing data-fetching/queryng with the server while Flux is mainly concerned with structuring Data flow between Client Side Data Models & View Components. However there is some overlap: At Facebook, we have apps built entirely using Flux, entirely using Relay, or with both. One pattern we see emerging is letting Relay manage the bulk of the data flow for an application, but using Flux stores on the side to handle a subset of application state
– HalSep 23 '15 at 14:33

8 Answers
8

Redux is not that different from Flux. Overall it has same architecture, but Redux is able to cut some complexity corners by using functional composition where Flux uses callback registration.

There is not a fundamental difference in Redux, but I find it makes certain abstractions easier, or at least possible to implement, that would be hard or impossible to implement in Flux.

Reducer Composition

Take, for example, pagination. My Flux + React Router example handles pagination, but the code for that is awful. One of the reasons it's awful is that Flux makes it unnatural to reuse functionality across stores. If two stores need to handle pagination in response to different actions, they either need to inherit from a common base store (bad! you're locking yourself into a particular design when you use inheritance), or call an externally defined function from within the event handler, which will need to somehow operate on the Flux store's private state. The whole thing is messy (although definitely in the realm of possible).

On the other hand, with Redux pagination is natural thanks to reducer composition. It's reducers all the way down, so you can write a reducer factory that generates pagination reducers and then use it in your reducer tree. The key to why it's so easy is because in Flux, stores are flat, but in Redux, reducers can be nested via functional composition, just like React components can be nested.

This pattern also enables wonderful features like no-user-code undo/redo. Can you imagine plugging Undo/Redo into a Flux app being two lines of code? Hardly. With Redux, it is—again, thanks to reducer composition pattern. I need to highlight there's nothing new about it—this is the pattern pioneered and described in detail in Elm Architecture which was itself influenced by Flux.

Server Rendering

People have been rendering on the server fine with Flux, but seeing that we have 20 Flux libraries each attempting to make server rendering “easier”, perhaps Flux has some rough edges on the server. The truth is Facebook doesn't do much server rendering, so they haven't been very concerned about it, and rely on the ecosystem to make it easier.

In traditional Flux, stores are singletons. This means it's hard to separate the data for different requests on the server. Not impossible, but hard. This is why most Flux libraries (as well as the new Flux Utils) now suggest you use classes instead of singletons, so you can instantiate stores per request.

There are still the following problems that you need to solve in Flux (either yourself or with the help of your favorite Flux library such as Flummox or Alt):

If stores are classes, how do I create and destroy them with dispatcher per request? When do I register stores?

How do I hydrate the data from the stores and later rehydrate it on the client? Do I need to implement special methods for this?

Redux just goes further: since there is just a single store (managed by many reducers), you don't need any special API to manage the (re)hydration. You don't need to “flush” or “hydrate” stores—there's just a single store, and you can read its current state, or create a new store with a new state. Each request gets a separate store instance. Read more about server rendering with Redux.

Again, this is a case of something possible both in Flux and Redux, but Flux libraries solve this problem by introducing a ton of API and conventions, and Redux doesn't even have to solve it because it doesn't have that problem in the first place thanks to conceptual simplicity.

Developer Experience

I didn't actually intend Redux to become a popular Flux library—I wrote it as I was working on my ReactEurope talk on hot reloading with time travel. I had one main objective: make it possible to change reducer code on the fly or even “change the past” by crossing out actions, and see the state being recalculated.

I haven't seen a single Flux library that is able to do this. React Hot Loader also doesn't let you do this—in fact it breaks if you edit Flux stores because it doesn't know what to do with them.

When Redux needs to reload the reducer code, it calls replaceReducer(), and the app runs with the new code. In Flux, data and functions are entangled in Flux stores, so you can't “just replace the functions”. Moreover, you'd have to somehow re-register the new versions with the Dispatcher—something Redux doesn't even have.

thanks for the answer...I am new to js..in your answer you have said flux is using singleton design pattern...can you tell me in redux what kind of design pattern they are using...and in flux can you tell me where they are using singleton pattern...can you give both an example...I understood what does design pattern from here singleton
– user6015171Apr 6 '16 at 14:26

2

I started my Android/Java implementation (Fluxxan) based on Fluxxor (basically pure flux). Once I saw redux, I was sold. There are some portions I kept purely flux tho but man, your lib is awesome!
– frostymarvelousApr 12 '16 at 17:08

We chose redux being of it being way more opinionated than flux. We were constantly fighting about how/where certain code should go, etc. Redux removed all of that confusion for us. We've built apps with redux for web and react-native and it's amazing!!
– SomethingOnDec 12 '16 at 21:59

Motivation As the requirements for JavaScript single-page applications have become increasingly complicated, our
code must manage more state than ever before. This state can include
server responses and cached data, as well as locally created data that
has not yet been persisted to the server. UI state is also increasing
in complexity, as we need to manage active routes, selected tabs,
spinners, pagination controls, and so on.

Managing this ever-changing state is hard. If a model can update
another model, then a view can update a model, which updates another
model, and this, in turn, might cause another view to update. At some
point, you no longer understand what happens in your app as you have
lost control over the when, why, and how of its state. When a system
is opaque and non-deterministic, it's hard to reproduce bugs or add
new features.

As if this wasn't bad enough, consider the new requirements becoming
common in front-end product development. As developers, we are
expected to handle optimistic updates, server-side rendering, fetching
data before performing route transitions, and so on. We find ourselves
trying to manage a complexity that we have never had to deal with
before, and we inevitably ask the question: Is it time to give up? The
answer is No.

This complexity is difficult to handle as we're mixing two concepts
that are very hard for the human mind to reason about: mutation and
asynchronicity. I call them Mentos and Coke. Both can be great when
separated, but together they create a mess. Libraries like React
attempt to solve this problem in the view layer by removing both
asynchrony and direct DOM manipulation. However, managing the state of
your data is left up to you. This is where Redux comes in.

Following in the footsteps of Flux, CQRS, and Event Sourcing, Redux
attempts to make state mutations predictable by imposing certain
restrictions on how and when updates can happen. These restrictions
are reflected in the three principles of Redux.

This object is like a "model" except that there are no setters. This
is so that different parts of the code can’t change the state
arbitrarily, causing hard-to-reproduce bugs.

To change something in the state, you need to dispatch an action. An
action is a plain JavaScript object (notice how we don't introduce any
magic?) that describes what happened. Here are a few example actions:

Enforcing that every change is described as an action lets us have a
clear understanding of what’s going on in the app. If something
changed, we know why it changed. Actions are like breadcrumbs of what
has happened. Finally, to tie state and actions together, we write a
function called a reducer. Again, nothing magic about it — it's just a
function that takes state and action as arguments, and returns the
next state of the app. It would be hard to write such a function for a
big app, so we write smaller functions managing parts of the state:

This is basically the whole idea of Redux. Note that we haven't used
any Redux APIs. It comes with a few utilities to facilitate this
pattern, but the main idea is that you describe how your state is
updated over time in response to action objects, and 90% of the code
you write is just plain JavaScript, with no use of Redux itself, its
APIs, or any magic.

You might be best starting with reading this post by Dan Abramov where he discusses various implementations of Flux and their trade-offs at the time he was writing redux:
The Evolution of Flux Frameworks

Secondly that motivations page you link to does not really discuss the motivations of Redux so much as the motivations behind Flux (and React). The Three Principles is more Redux specific though still does not deal with the implementation differences from the standard Flux architecture.

Basically, Flux has multiple stores that compute state change in response to UI/API interactions with components and broadcast these changes as events that components can subscribe to. In Redux, there is only one store that every component subscribes to. IMO it feels at least like Redux further simplifies and unifies the flow of data by unifying (or reducing, as Redux would say) the flow of data back to the components - whereas Flux concentrates on unifying the other side of the data flow - view to model.

I'm an early adopter and implemented a mid-large single page application using the Facebook Flux library.

As I'm a little late to the conversation I'll just point out that despite my best hopes Facebook seem to consider their Flux implementation to be a proof of concept and it has never received the attention it deserves.

I'd encourage you to play with it, as it exposes more of the inner working of the Flux architecture which is quite educational, but at the same time it does not provide many of the benefits that libraries like Redux provide (which aren't that important for small projects, but become very valuable for bigger ones).

We have decided that moving forward we will be moving to Redux and I suggest you do the same ;)

I've been developing Facebook Flux app for six months. And I still not sure if a migration time is worth the benefits Redux provide. I'll very appreciate all your comments about pros/cons of Redux over FB flux!
– VB_Jan 11 '16 at 13:59

1

@VolodymyrBakhmatiuk for us it's mostly about reducing the amount of boilerplate we have to write + better error handling (redux will for example yell if you fire an action that was not defined in your constant list - FB flux won't and it can cause all sorts of problems) There's a few more advanced capabilities in flux, but I've not used them yet
– Guy NesherJan 11 '16 at 16:01

1

@GuyNesher an undefined action should be detected at compile-time, not at run-time. Flow (another Facebook contribution) allows you to do that.
– Dominique PERETTIFeb 8 '16 at 23:46

@DominiquePERETTI - true (can also use linting) but it doesn't change the fact that not catching the error at run time is kinda sad
– Guy NesherFeb 11 '16 at 19:06

I wrote a few simple helpers for dealing with FBFlux, and it actually seems to be less boilerplate and app set up than all of the example Redux apps I've found. Worked on an app for 9+ months last between two devs and never had any issues whatsoever with the architecture.
– rob2dMar 22 '17 at 1:05

Here is the simple explanation of Redux over Flux.
Redux does not have a dispatcher.It relies on pure functions called reducers. It does not need a dispatcher. Each actions are handled by one or more reducers to update the single store. Since data is immutable, reducers returns a new updated state that updates the store

I worked quite a long time with Flux and now quite a long time using Redux. As Dan pointed out both architectures are not so different. The thing is that Redux makes the things simpler and cleaner. It teaches you a couple of things on top of Flux. Like for example Flux is a perfect example of one-direction data flow. Separation of concerns where we have data, its manipulations and view layer separated. In Redux we have the same things but we also learn about immutability and pure functions.

From a new react/redux adopter migrating from (a few years of) ExtJS in mid-2018:

After sliding backward down the redux learning curve I had the same question and thought pure flux would be simpler like OP.

I soon saw the benefits of redux over flux as noted in the answers above, and was working it into my first app.

While getting a grip on the boiler plate again, I tried out a few of the other state management libs, the best I found was rematch.

It was much more intuitive then vanilla redux, it cuts out 90% of the boilerplate and cut out 75% of the time I was spending on redux (something I think a library should be doing), I was able to get a couple enterprise apps going right away.

It also runs with the same redux tooling. This is a good article that covers some of the benefits.

So for anyone else who arrived to this SO post searching "simpler redux", I recommend trying it out as a simple alternative to redux with all the benefits and 1/4 of the boilerplate.

Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).