SlideShare a Scribd company logo
Redux at scale
@matterstech
by Baptiste
@batmansmk
I assume you know
Redux.
20 frontend devs
5 apps desktop, PWA, native
130+ action types / app
Matters is a startup studio
Redux scaled with:
- our team size
- the form factors supported
- the number of features in the apps
This is how we did it.
1/ Planed 1 full day of
training for each member
Official documentation
Videos on Egghead from @dan_abramov
Code
Make a little quizz!
- What is a selector?
- How much RAM does an
immutable state use?
- What is a normalized state?
2/ Tooled our env
const store = createStore(
reducer,
window.__REDUX_DEVTOOLS_EXTENSION__ &&
window.__REDUX_DEVTOOLS_EXTENSION__()
);
https://github.com/zalmoxisus/redux-devtools-extension
add
3/ Used action
creators
// 1 - Defining in our components got messy.
const action = {type: 'my-app/users/ADD', {id:
1, name:'Bat'}}
3/ Action creators
// 2 - Better in ./users.js
export const addUser = payload => ({type: 'my-
app/users/ADD', payload})
// and get the action in another file
import {addUser} from '../redux/users'
const action = addUser({id: 1, name:'Bat'})
- defines an API
- defines an explicit dependency
component <=> action
- are convenient with react-redux
3/ Action creators
// 1 - instead of
const mapDispatchToProps = dispatch => {
return {
addUser: payload => dispatch({type:'my-app/users/
ADD',payload})
}
}
const connect(null, mapDispatchToProps)(MyComponent)
3/ Actions creators are convenient
// 2 - with action creators
import {addUser} from './redux/users'
const connect(null, {addUser})(MyComponent)
4/ Redux ducks
4/ Redux ducks
const ADD = 'my-app/users/ADD';
export default function reducer(state = {}, action = {})
{
switch (action.type) {
ADD: return {
...state, 

[action.payload.id]: action.payload

}
default: return state;
}
}
// Action Creators
export function addUser(payload) {
return { type: ADD, payload };
}
4/ Redux ducks
Redux ducks is sufficient for us.*
* tested up to our capability.
5/ Write Unit tests
Redux ❤ TDD so much
0
15
30
45
60
without test with tests
dev ut dev maintenance ut maintenance
Mitigated Unit tests ROI in
frontend
Possible causes of bad ROI on automated
testing?
Frontend code changes too often to have good
ROI with systematic Unit Testing.
https://www.future-processing.pl/blog/object-oriented-metrics-by-robert-martin/
0
15
30
45
60
all js no test all js with tests redux only no test redux with tests
dev ut dev maintenance ut maintenance
6/ Use payload-based
actions
export const editName = name => ({type:'users/edit-name',
name});
export const editEmail = email => ({type:'users/edit-email',
email});
// can be often simplified to
export const edit = payload => ({type:’users/edit', payload});
6/ Payload-based actions
With Payload-based actions,
reducers are simpler
7/ Frontend development
is all about side-effects
redux-thunk
didn't scale.
let’s talk about redux-thunk.
Redux co-creator

after he saw
redux-thunk
in our codebase
We were more successful with
redux-sagas.*
* Ask me more details, doesn’t fit in the talk!
8/ Normalized the
state like a db
8/ Normalization
Redux at scale
// 1 - instead of
const state = {
users: [
{ id: 1, name: "Alan", groups: [{ name: "Dog" }, { name: "Cat" }] },
{ id: 2, name: "Chloe", groups: { name: "Dog" } },
{ id: 1, name: "Marvis", groups: { name: "Cat" } }
]
};
// 2- Normalize and index by primary key
const state = {
users: {
1: { id: 1, name: "Alan", groups: [1, 2] },
2: { id: 2, name: "Chloe", groups: [1] },
3: { id: 3, name: "Marvis", groups: [2] }
},
groups: {
1: { id: 1, name: “Dog” },
2: { id: 2, name: "Cat" }
}
};
8/ Normalize state
9/ Selectors are
helpful
export const getGroupsById = (state, ids) => ids.map(
id => state.groups[id]
)
export const getUsersWithGroupsById = (state, ids) => ids.map(id
=> ({
...state.users[id],
groups: getGroupsById(state.users[id].groups)
}))
9/ Selectors
10/ Flow and
Typescript helped
1/ Plan 1 day of training
2/ Tool the env
3/ Action creators
4/ Structure in modules
5/ TDD
6/ Payload-based actions
7/ Side-effects are 95% of the problem
8/ Normalize the state
9/ Selectors are helpful
10/ Types
@matterstech
Thanks!
Any questions?

More Related Content

PDF
探討Web ui自動化測試工具
PDF
JavaScript + Jenkins = Winning!
PPTX
前端網頁自動測試
PPTX
Your Script Just Killed My Site
PDF
Testing with Codeception (Webelement #30)
PDF
Writing a Jenkins / Hudson plugin
PPTX
Jenkins Plugin Development With Gradle And Groovy
PDF
Why gradle
探討Web ui自動化測試工具
JavaScript + Jenkins = Winning!
前端網頁自動測試
Your Script Just Killed My Site
Testing with Codeception (Webelement #30)
Writing a Jenkins / Hudson plugin
Jenkins Plugin Development With Gradle And Groovy
Why gradle

What's hot (19)

PDF
Martin Aspeli Extending And Customising Plone 3
ODP
Building JBoss AS 7 for Fedora
PDF
Night Watch with QA
PDF
Jenkinsプラグインの作り方
PDF
Puppeteer - Headless Chrome Node API
PPTX
Jasmine with JS-Test-Driver
PPTX
Working Software Over Comprehensive Documentation
PDF
Tasting Your First Test Burger
PDF
Frontend SPOF
PDF
Automating your workflow with Gulp.js
PPT
Building and Deployment of Drupal sites with Features and Context
PDF
How we maintain 200+ Drupal sites in Georgetown University
PDF
CI : the first_step: Auto Testing with CircleCI - (MOSG)
PDF
Continuous Integration Testing in Django
PPT
Auto Build
PDF
DevOps叢林裡的小隊游擊戰術 (@ iThome DevOps 2015)
PDF
Puppeteer - A web scraping & UI Testing Tool
PDF
Test kitchen 1.0 - Fletcher Nichol
PPTX
Puppeteer
Martin Aspeli Extending And Customising Plone 3
Building JBoss AS 7 for Fedora
Night Watch with QA
Jenkinsプラグインの作り方
Puppeteer - Headless Chrome Node API
Jasmine with JS-Test-Driver
Working Software Over Comprehensive Documentation
Tasting Your First Test Burger
Frontend SPOF
Automating your workflow with Gulp.js
Building and Deployment of Drupal sites with Features and Context
How we maintain 200+ Drupal sites in Georgetown University
CI : the first_step: Auto Testing with CircleCI - (MOSG)
Continuous Integration Testing in Django
Auto Build
DevOps叢林裡的小隊游擊戰術 (@ iThome DevOps 2015)
Puppeteer - A web scraping & UI Testing Tool
Test kitchen 1.0 - Fletcher Nichol
Puppeteer
Ad

Similar to Redux at scale (20)

PDF
Building React Applications with Redux
PPTX
Maintaining sanity in a large redux app
PDF
#FrontConf2017 — Enhance your User (and Developer) Experience with React & Redux
PDF
Redux js
PDF
Redux essentials
PDF
Let's Redux!
PDF
Introduction to Redux (for Angular and React devs)
PDF
React+Redux at Scale
PDF
Evan Schultz - Angular Summit - 2016
PDF
Advanced Redux architecture - WHAT/WHEN/WHY/HOW
PDF
Materi Modern React Redux Power Point.pdf
PPTX
PDF
Why Full Stack Developers Use Redux for State Management.pdf
PPTX
Redux Tech Talk
PDF
Advanced React Component Patterns - ReactNext 2018
PDF
Using redux
PDF
ReactRedux.pdf
PDF
React & Redux
PDF
The Road To Redux
PPTX
an Introduction to Redux
Building React Applications with Redux
Maintaining sanity in a large redux app
#FrontConf2017 — Enhance your User (and Developer) Experience with React & Redux
Redux js
Redux essentials
Let's Redux!
Introduction to Redux (for Angular and React devs)
React+Redux at Scale
Evan Schultz - Angular Summit - 2016
Advanced Redux architecture - WHAT/WHEN/WHY/HOW
Materi Modern React Redux Power Point.pdf
Why Full Stack Developers Use Redux for State Management.pdf
Redux Tech Talk
Advanced React Component Patterns - ReactNext 2018
Using redux
ReactRedux.pdf
React & Redux
The Road To Redux
an Introduction to Redux
Ad

More from inovia (20)

PDF
10 tips for Redux at scale
PDF
10 essentials steps for kafka streaming services
PDF
DocuSign's Road to react
PPTX
API Gateway: Nginx way
PPTX
Kafka: meetup microservice
PPTX
Microservice: starting point
PPTX
Correlation id (tid)
PPTX
Meetic back end redesign - Meetup microservices
PPTX
Security in microservices architectures
PPTX
Building a Secure, Performant Network Fabric for Microservice Applications
PPTX
Microservices vs SOA
PPTX
CQRS, an introduction by JC Bohin
PPTX
Domain Driven Design
PPTX
Oauth2, open-id connect with microservices
PPTX
You probably don't need microservices
PPTX
Api Gateway - What's the use of an api gateway?
PDF
Steam Learn: An introduction to Redis
PDF
Steam Learn: Speedrun et TAS
PDF
Steam Learn: Asynchronous Javascript
PDF
Steam Learn: Cheat sheet for Vim
10 tips for Redux at scale
10 essentials steps for kafka streaming services
DocuSign's Road to react
API Gateway: Nginx way
Kafka: meetup microservice
Microservice: starting point
Correlation id (tid)
Meetic back end redesign - Meetup microservices
Security in microservices architectures
Building a Secure, Performant Network Fabric for Microservice Applications
Microservices vs SOA
CQRS, an introduction by JC Bohin
Domain Driven Design
Oauth2, open-id connect with microservices
You probably don't need microservices
Api Gateway - What's the use of an api gateway?
Steam Learn: An introduction to Redis
Steam Learn: Speedrun et TAS
Steam Learn: Asynchronous Javascript
Steam Learn: Cheat sheet for Vim

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PPT
Teaching material agriculture food technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Encapsulation theory and applications.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
KodekX | Application Modernization Development
PDF
cuic standard and advanced reporting.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Per capita expenditure prediction using model stacking based on satellite ima...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
sap open course for s4hana steps from ECC to s4
Teaching material agriculture food technology
Digital-Transformation-Roadmap-for-Companies.pptx
Network Security Unit 5.pdf for BCA BBA.
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation theory and applications.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Approach and Philosophy of On baking technology
Machine learning based COVID-19 study performance prediction
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
KodekX | Application Modernization Development
cuic standard and advanced reporting.pdf
20250228 LYD VKU AI Blended-Learning.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

Redux at scale

  • 1. Redux at scale @matterstech by Baptiste @batmansmk
  • 2. I assume you know Redux.
  • 3. 20 frontend devs 5 apps desktop, PWA, native 130+ action types / app
  • 4. Matters is a startup studio
  • 5. Redux scaled with: - our team size - the form factors supported - the number of features in the apps This is how we did it.
  • 6. 1/ Planed 1 full day of training for each member
  • 7. Official documentation Videos on Egghead from @dan_abramov Code
  • 8. Make a little quizz! - What is a selector? - How much RAM does an immutable state use? - What is a normalized state?
  • 10. const store = createStore( reducer, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() ); https://github.com/zalmoxisus/redux-devtools-extension
  • 11. add
  • 13. // 1 - Defining in our components got messy. const action = {type: 'my-app/users/ADD', {id: 1, name:'Bat'}} 3/ Action creators // 2 - Better in ./users.js export const addUser = payload => ({type: 'my- app/users/ADD', payload}) // and get the action in another file import {addUser} from '../redux/users' const action = addUser({id: 1, name:'Bat'})
  • 14. - defines an API - defines an explicit dependency component <=> action - are convenient with react-redux 3/ Action creators
  • 15. // 1 - instead of const mapDispatchToProps = dispatch => { return { addUser: payload => dispatch({type:'my-app/users/ ADD',payload}) } } const connect(null, mapDispatchToProps)(MyComponent) 3/ Actions creators are convenient // 2 - with action creators import {addUser} from './redux/users' const connect(null, {addUser})(MyComponent)
  • 18. const ADD = 'my-app/users/ADD'; export default function reducer(state = {}, action = {}) { switch (action.type) { ADD: return { ...state, 
 [action.payload.id]: action.payload
 } default: return state; } } // Action Creators export function addUser(payload) { return { type: ADD, payload }; } 4/ Redux ducks
  • 19. Redux ducks is sufficient for us.* * tested up to our capability.
  • 20. 5/ Write Unit tests
  • 21. Redux ❤ TDD so much
  • 22. 0 15 30 45 60 without test with tests dev ut dev maintenance ut maintenance Mitigated Unit tests ROI in frontend
  • 23. Possible causes of bad ROI on automated testing? Frontend code changes too often to have good ROI with systematic Unit Testing. https://www.future-processing.pl/blog/object-oriented-metrics-by-robert-martin/
  • 24. 0 15 30 45 60 all js no test all js with tests redux only no test redux with tests dev ut dev maintenance ut maintenance
  • 26. export const editName = name => ({type:'users/edit-name', name}); export const editEmail = email => ({type:'users/edit-email', email}); // can be often simplified to export const edit = payload => ({type:’users/edit', payload}); 6/ Payload-based actions
  • 28. 7/ Frontend development is all about side-effects
  • 30. Redux co-creator
 after he saw redux-thunk in our codebase
  • 31. We were more successful with redux-sagas.* * Ask me more details, doesn’t fit in the talk!
  • 35. // 1 - instead of const state = { users: [ { id: 1, name: "Alan", groups: [{ name: "Dog" }, { name: "Cat" }] }, { id: 2, name: "Chloe", groups: { name: "Dog" } }, { id: 1, name: "Marvis", groups: { name: "Cat" } } ] }; // 2- Normalize and index by primary key const state = { users: { 1: { id: 1, name: "Alan", groups: [1, 2] }, 2: { id: 2, name: "Chloe", groups: [1] }, 3: { id: 3, name: "Marvis", groups: [2] } }, groups: { 1: { id: 1, name: “Dog” }, 2: { id: 2, name: "Cat" } } }; 8/ Normalize state
  • 37. export const getGroupsById = (state, ids) => ids.map( id => state.groups[id] ) export const getUsersWithGroupsById = (state, ids) => ids.map(id => ({ ...state.users[id], groups: getGroupsById(state.users[id].groups) })) 9/ Selectors
  • 39. 1/ Plan 1 day of training 2/ Tool the env 3/ Action creators 4/ Structure in modules 5/ TDD 6/ Payload-based actions 7/ Side-effects are 95% of the problem 8/ Normalize the state 9/ Selectors are helpful 10/ Types