Optimizing React at Postmates
- 4. (old) Frontend
• Node service to render views and proxy API calls
• SSR React to React Router SPA
• Model-based state management (built in house)
• Browser caching mechanisms for data
• Webpack builds
• Less for styles
• Tests? #YOLO (but set up for unit tests w/ a headless browser)
- 5. Motivation
• Node service to render views and proxy API calls
• SSR React to React Router SPA
• Model-based state management (built in house)
• Browser caching mechanisms for data
• Webpack builds
• Less for styles
• Tests? #YOLO (but set up for tests w/ a headless browser)
Universally use JavaScript, non-blocking I/O and allow for SSR
SEO, perceived improvements with HTML prebuilt
Easy to reason about and separates concerns
Improve performance by reducing unnecessary API calls
Awesome asset pipeline, code splitting, all that great stuff
Built in JS and battle tested
The infrastructure is there but we want to really make it part of the
team culture
- 7. Results
• SSR added complexity and required vetting all packages. Ultimately
reduced dev velocity for minimal or unknown gains.
• Models didn’t scale with code or team size.
• Need to take advantage of Dan Abramov’s ideas the community and
available tools.
• Global state makes things very easy to reason about and inspect the
application. Also provides performance with everything in memory.
- 8. Results
• Want to optimize for development velocity and enjoyment in
addition to optimizations code performance
• Make it easier to onboard new engineers
• Snapshot testing and other methods to make it more enjoyable
while also providing confidence in changes
• Handle A/B testing, event tracking, and data collection with ease
- 9. (future) Frontend
• Go service to render views and proxy API calls
• Client-side React SPA with React Router v4
• Redux
• PostCSS using BEM or CSS Modules or CSS in JS (still debating)
- 12. Lighthouse
Setup
3 options: npm, Chrome extension, or CLI
lighthouse https://order.postmates.com/bun-mee-vietnamese-sandwich-eatery-san-francisco
lighthouse https://www.grubhub.com/restaurant/bun-mee-2015-fillmore-st-san-francisco/258912
lighthouse https://www.trycaviar.com/san-francisco/bun-mee--fillmore-5923
- 18. Methods
• Build for production
• Use `key` correctly in lists
• Manage `shouldComponentUpdate`
• Use PureComponent
- 21. Use key
correctly
Unique key Math.random() as key
28 operations 713 operations
Prints the underlying DOM manipulations, e.g. "set innerHTML" and "remove".
- 24. Postmates
Largest on-demand delivery platform
5-10% growth week-over-week
1
Fulfill over one million deliveries per month
On-demand logistics connecting a three-sided market
2
3
4
5
Operate in all major cities6
Will actively be contributing to and releasing OSS7
Available on Android, iOS and Web
- 25. Optimizing React @ Postmates
team-tech-recruiting@postmates.com
postmates.com/jobs
@postmatesdev
@treyhuffine