Normalizing State Shape in Redux?

This is a comment from this Redux course:

What I don’t get is why this process is called “normalizing” the state shape. I understand the value of the changes made, just not what exactly that term means and why it applies here.

From my research normalizing is a term from dealing with data that make its more predictable to deal with and easier to access. Is this correct or could anyone provide more insight?

1 Like

This article is a very good explanation:

https://support.microsoft.com/en-us/help/283878/description-of-the-database-normalization-basics

I think it’s interesting because fundamentally the global data aspect of Redux essentially means it’s a database so these concepts apply.

Normalization is the process of organizing data in a database. This includes creating tables and establishing relationships between those tables according to rules designed both to protect the data and to make the database more flexible by eliminating redundancy and inconsistent dependency.

Redundant data wastes disk space and creates maintenance problems. If data that exists in more than one place must be changed, the data must be changed in exactly the same way in all locations. A customer address change is much easier to implement if that data is stored only in the Customers table and nowhere else in the database.

From @erindoyle8080:

So “normalizing” in this example refers to changing the shape of the state from an array of arrays to an object keyed by id for more efficient management and lookup (“like a database”)

The post with the question says “From my research normalizing is a term from dealing with data that make its more predictable to deal with and easier to access”. Yes that’s exactly what Dan is doing in this example. It’s much easier to get the todos by ID, but he also provides the array of all todos for when we need to filter and perform functions that need to act on all todos.

From @ben.clinkinbeard:

For additional context, a database is said to be more normalized (or in higher normal form) when more of the entities in it can be looked up by a unique identifier in their own table.

Like if your users table had a bookmarks column/field that held a list of urls. Normalizing that data would involve creating a bookmarks table/collection, creating an entry for each unique url across all users in said table, and then updating the bookmarks columns to hold bookmark ids instead of urls directly.
The ids are usually automatically created by the database but can be anything unique. The benefits are deduplication of data, faster lookups, and much more efficient reasoning about the dataset as a whole. (Think about how you’d check if anyone has bookmarked a given url before and after the normalization.)

This was way longer than I intended, I hope it helps. :laughing: