SlideShare a Scribd company logo
MAY. 18, 2019 • REACTJS-
BANGALORE
COMPONENT
LEVEL
CACHING
WITH REACT
ANUSHEEL SINGH (@ImAnusheel)
TEAM GOIBIBO (@goibibo_tech)
DISCUSSION OUTLINE
Background of Goibibo's Isomorphic
Usecase
Problem statement in-hand
Lifecycle of a request for dynamic
content
Basis of Solution
Implementation
Future of component level caching
Q&A
ORGANIC TRAFFIC IS
IMPORTANT
New user. Search engine
domination on user
behaviour.
WHY SERVER SIDE RENDERING?
NO REPETITIVE EFFORT
Single system powering all source of
traffic. Feature parity. Better
utilisation of engineering bandwidth.
Reliability.
MATRICS MATTERS
Response time, Time to first
meaningful paint, SEO Rank
TECH STACK
CUSTOM IMPLEMENTATION
React Redux Redis
PROPERTY DETAIL PAGE
TOTAL REQUEST
~300K
UNIQUE PROPERTY REQUESTED
~100k
DOC GZIP SIZE
~25kb
CACHE TTL
~7 Days
* Organic traffic only
Natural language organic
queries/searches
BEACH FACING HOTEL IN GOA.
TREE HOUSE IN MUNNAR.
HOTELS WITH INFINITY POOLS IN
PHUKET.
AND MANY MORE ENDLESS QUERIES.
PROBLEM STATEMENT / OPPORTUNITY
All reviews indexing
NATURAL LANGUAGE
QUERIES
Infinite set of queries are
possible.
Hard to control tagging quality if
power is given to the hotelier.
USER GENERATED
CONTENTS
Natural language reviews.
Trusted content.
Good response time with optimised cache size
MATCH ROUTE
Top level component to be rendered. Async task to be
performed. Should be cached or not. Cache key function.
TRY TO SERVE FROM CACHE
If route is configured to be cached then check in cache
against the cache key.
INITIALISE STORE WITH INPUT & PERFORM
ASYNC TASK
Input from URL & async task from matched route object.
RENDER TO STATIC MARKUP
Content. Critical CSS. Store snapshot for client
hydration. Meta/Link tags (using helmet).
CACHE IT
If cache flag is true then set the cache against the cache
key.
LIFECYCLE
OF A
REQUEST
DYNAMIC CONTENT
String output
from
renderToString.
Goes into body
tag (element
hook).
CONTENT
CACHE FORMAT
CSS required for
proper layout.
Goes into head
tag.
CRITICAL CSS
Redux store
snapshot used to
render on server.
Hydrate on client
with same state.
STORE
SNAPSHOT
Critical for SEO
Goes into head
tag
HEAD TAGS
Comstech • Oct. 15, 2020
SERVER RESPONSE TEMPLATE
export default function serverResponseTemplate({appContent = '', headCss = '', storeJson = {}, helmetObj}, {scriptName}) {
  const assets = global.assetsChunks;
  return `
    <!DOCTYPE html>
    <html lang="en" ${helmetObj.htmlAttributes}>
      <head>
        ${headCss}${helmetObj.title}${helmetObj.meta}${helmetObj.link}
      </head>
      <body>
        <div id="root">${appContent}</div>
        <script charSet="UTF-8">
          window.__initial_state__=${serialize(storeJson)};
        </script>
        ${assets.styles.main ? `<link rel="stylesheet" href="${assets.styles.main}">` : ''}
        <script src="${assets.javascript.vendor}"></script>
        ${scriptName ? `<script src="${assets.javascript[scriptName]}"></script>` : ''}
        </body>
    </html>
  `;
}
Basis of solution
EVERYTHING IS A
COMPONENT
App layout, Route Layout,
Container, Component everything
is a component. Props can be
provided from parent or
component can be connnected to
redux store
COMPONENT IS A
FUNCTION OF PROPS
On server, component is just a
function of props provided. If
props remains the same then
output will also be the same.
COMPONENT AS A
INDEPENDENT UNIT
Each component can be rendered
as content, critical css, helmet
object, data snapshot.
Implementation
DIVIDE & FETCH
Introduce a request handler and split
it into two sub request. Complete
Detail and Review.
INDIVIDUAL LIFECYCLE
Both will go through there individual 
journey, cache and returns the cache
structure.
MERGE
Once we have both the response.
Merge it and create a new cache
structure.
SERVER RESPONSE
TEMPLATE
Send the final merged output to the
server response template and send
response.
CODE SNIPPETS
DETAIL CONTAINER
// detail component render function
  render() {
    return (
      <View>
        {/* other components */}
        <DetailReview
          // other props
          renderHook={Platform.OS ===
'mobile' && __SERVER__}
        />
      {/* other components */}
      </View>
    );
REVIEW COMPONENT
// detail review component render function
  render() {
    if (this.props.renderHook) {
      return (<div id="detail-rnr"></div>);
    }
    // otherwise render actual component
    return (<TheComponent />);
  }
MERGING
const storeJson = {...staticStoreJson,ugc: reviewStoreJson.ugc}; // merge store
const finalHelmetObj = {...helmetObj, link: `${helmetObj.link}${seoLinks} || ''`}; // merge helmet
const appContent = staticContent.replace(`<div id="detail-rnr"></div>`, reviewContent); // merge markup
const headCss = `${staticHeadCss}${reviewHeadCss}`; // merge css
  const data = {
    appContent,
    headCss,
    storeJson,
    helmetObj: finalHelmetObj
  };
FUTURE OF COMPONENT LEVEL CACHIING
REACT COMPONENT
CACHING
https://github.com/rookLab/rea
ct-component-caching
REACT CACHE
https://github.com/facebook/re
act/tree/master/packages/reac
t-cache
CONCURRENT
RENDERING IN REACT
https://www.youtube.com/watc
h?v=ByBPyMBTzM0
Anusheel Singh -
@ImAnusheel
TEAM GOIBIBO - @GOIBIBO_TECH
Q & A
THANK YOU

More Related Content

PDF
React & Redux
PDF
React on Rails - RailsConf 2017 (Phoenix)
PPTX
[Final] ReactJS presentation
PDF
Redux Universal
PDF
Using redux
PPTX
BackboneJS + ReactJS
PPTX
React / Redux Architectures
PPTX
Let's react - Meetup
React & Redux
React on Rails - RailsConf 2017 (Phoenix)
[Final] ReactJS presentation
Redux Universal
Using redux
BackboneJS + ReactJS
React / Redux Architectures
Let's react - Meetup

What's hot (20)

PDF
React JS and Redux
PPTX
React & redux
PDF
Backbone to React. What it says about awesome UI Code.
PDF
AtlasCamp 2015: How HipChat ships at the speed of awesome
PDF
Designing applications with Redux
PDF
React & Redux
PDF
React state managmenet with Redux
PPTX
Getting Started With ReactJS
PDF
React.js and Redux overview
PDF
AngularJS Deep Dives (NYC GDG Apr 2013)
PPTX
A Brief Introduction to React.js
PPTX
Academy PRO: React JS. Redux & Tooling
PDF
Workload Replay in the Cloud: Secret Weapon for Cloud Migrations
PPTX
20180518 QNAP Seminar - Introduction to React Native
PDF
React.js in real world apps.
PPTX
React + Redux Introduction
PDF
An Introduction to Redux
PDF
Neoito — React 101
PDF
React, Redux, ES2015 by Max Petruck
PDF
Introduction to React & Redux
React JS and Redux
React & redux
Backbone to React. What it says about awesome UI Code.
AtlasCamp 2015: How HipChat ships at the speed of awesome
Designing applications with Redux
React & Redux
React state managmenet with Redux
Getting Started With ReactJS
React.js and Redux overview
AngularJS Deep Dives (NYC GDG Apr 2013)
A Brief Introduction to React.js
Academy PRO: React JS. Redux & Tooling
Workload Replay in the Cloud: Secret Weapon for Cloud Migrations
20180518 QNAP Seminar - Introduction to React Native
React.js in real world apps.
React + Redux Introduction
An Introduction to Redux
Neoito — React 101
React, Redux, ES2015 by Max Petruck
Introduction to React & Redux
Ad

Similar to Component level caching with react (20)

PDF
Universal JS Applications with React
PDF
Integrating React.js Into a PHP Application
PPTX
Intro react js
PPT
PPTX
PDF
Hastening React SSR - Web Performance San Diego
PPTX
React - Start learning today
PDF
OttawaJS - React
PPTX
Combining Angular and React Together
PPTX
Introduction to react and redux
PPTX
React JS .NET
PDF
Introduction to react
PPTX
React & Redux for noobs
PDF
React js
PDF
ReactJS vs AngularJS - Head to Head comparison
PDF
Front End Development for Back End Developers - UberConf 2017
PPTX
React basic by Yoav Amit, Wix
PDF
Workshop 27: Isomorphic web apps with ReactJS
PDF
The Exciting Future Of React
PDF
Building Universal Web Apps with React ForwardJS 2017
Universal JS Applications with React
Integrating React.js Into a PHP Application
Intro react js
Hastening React SSR - Web Performance San Diego
React - Start learning today
OttawaJS - React
Combining Angular and React Together
Introduction to react and redux
React JS .NET
Introduction to react
React & Redux for noobs
React js
ReactJS vs AngularJS - Head to Head comparison
Front End Development for Back End Developers - UberConf 2017
React basic by Yoav Amit, Wix
Workshop 27: Isomorphic web apps with ReactJS
The Exciting Future Of React
Building Universal Web Apps with React ForwardJS 2017
Ad

Recently uploaded (20)

PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Current and future trends in Computer Vision.pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPT
introduction to datamining and warehousing
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Geodesy 1.pptx...............................................
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Safety Seminar civil to be ensured for safe working.
PPT
Project quality management in manufacturing
PPTX
OOP with Java - Java Introduction (Basics)
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PPTX
UNIT 4 Total Quality Management .pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Foundation to blockchain - A guide to Blockchain Tech
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Current and future trends in Computer Vision.pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
introduction to datamining and warehousing
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Geodesy 1.pptx...............................................
Operating System & Kernel Study Guide-1 - converted.pdf
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Safety Seminar civil to be ensured for safe working.
Project quality management in manufacturing
OOP with Java - Java Introduction (Basics)
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
UNIT 4 Total Quality Management .pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
additive manufacturing of ss316l using mig welding
Foundation to blockchain - A guide to Blockchain Tech

Component level caching with react

  • 1. MAY. 18, 2019 • REACTJS- BANGALORE COMPONENT LEVEL CACHING WITH REACT ANUSHEEL SINGH (@ImAnusheel) TEAM GOIBIBO (@goibibo_tech)
  • 2. DISCUSSION OUTLINE Background of Goibibo's Isomorphic Usecase Problem statement in-hand Lifecycle of a request for dynamic content Basis of Solution Implementation Future of component level caching Q&A
  • 3. ORGANIC TRAFFIC IS IMPORTANT New user. Search engine domination on user behaviour. WHY SERVER SIDE RENDERING? NO REPETITIVE EFFORT Single system powering all source of traffic. Feature parity. Better utilisation of engineering bandwidth. Reliability. MATRICS MATTERS Response time, Time to first meaningful paint, SEO Rank
  • 5. PROPERTY DETAIL PAGE TOTAL REQUEST ~300K UNIQUE PROPERTY REQUESTED ~100k DOC GZIP SIZE ~25kb CACHE TTL ~7 Days * Organic traffic only
  • 6. Natural language organic queries/searches BEACH FACING HOTEL IN GOA. TREE HOUSE IN MUNNAR. HOTELS WITH INFINITY POOLS IN PHUKET. AND MANY MORE ENDLESS QUERIES. PROBLEM STATEMENT / OPPORTUNITY
  • 7. All reviews indexing NATURAL LANGUAGE QUERIES Infinite set of queries are possible. Hard to control tagging quality if power is given to the hotelier. USER GENERATED CONTENTS Natural language reviews. Trusted content. Good response time with optimised cache size
  • 8. MATCH ROUTE Top level component to be rendered. Async task to be performed. Should be cached or not. Cache key function. TRY TO SERVE FROM CACHE If route is configured to be cached then check in cache against the cache key. INITIALISE STORE WITH INPUT & PERFORM ASYNC TASK Input from URL & async task from matched route object. RENDER TO STATIC MARKUP Content. Critical CSS. Store snapshot for client hydration. Meta/Link tags (using helmet). CACHE IT If cache flag is true then set the cache against the cache key. LIFECYCLE OF A REQUEST DYNAMIC CONTENT
  • 9. String output from renderToString. Goes into body tag (element hook). CONTENT CACHE FORMAT CSS required for proper layout. Goes into head tag. CRITICAL CSS Redux store snapshot used to render on server. Hydrate on client with same state. STORE SNAPSHOT Critical for SEO Goes into head tag HEAD TAGS Comstech • Oct. 15, 2020
  • 10. SERVER RESPONSE TEMPLATE export default function serverResponseTemplate({appContent = '', headCss = '', storeJson = {}, helmetObj}, {scriptName}) {   const assets = global.assetsChunks;   return `     <!DOCTYPE html>     <html lang="en" ${helmetObj.htmlAttributes}>       <head>         ${headCss}${helmetObj.title}${helmetObj.meta}${helmetObj.link}       </head>       <body>         <div id="root">${appContent}</div>         <script charSet="UTF-8">           window.__initial_state__=${serialize(storeJson)};         </script>         ${assets.styles.main ? `<link rel="stylesheet" href="${assets.styles.main}">` : ''}         <script src="${assets.javascript.vendor}"></script>         ${scriptName ? `<script src="${assets.javascript[scriptName]}"></script>` : ''}         </body>     </html>   `; }
  • 11. Basis of solution EVERYTHING IS A COMPONENT App layout, Route Layout, Container, Component everything is a component. Props can be provided from parent or component can be connnected to redux store COMPONENT IS A FUNCTION OF PROPS On server, component is just a function of props provided. If props remains the same then output will also be the same. COMPONENT AS A INDEPENDENT UNIT Each component can be rendered as content, critical css, helmet object, data snapshot.
  • 12. Implementation DIVIDE & FETCH Introduce a request handler and split it into two sub request. Complete Detail and Review. INDIVIDUAL LIFECYCLE Both will go through there individual  journey, cache and returns the cache structure. MERGE Once we have both the response. Merge it and create a new cache structure. SERVER RESPONSE TEMPLATE Send the final merged output to the server response template and send response.
  • 13. CODE SNIPPETS DETAIL CONTAINER // detail component render function   render() {     return (       <View>         {/* other components */}         <DetailReview           // other props           renderHook={Platform.OS === 'mobile' && __SERVER__}         />       {/* other components */}       </View>     ); REVIEW COMPONENT // detail review component render function   render() {     if (this.props.renderHook) {       return (<div id="detail-rnr"></div>);     }     // otherwise render actual component     return (<TheComponent />);   }
  • 14. MERGING const storeJson = {...staticStoreJson,ugc: reviewStoreJson.ugc}; // merge store const finalHelmetObj = {...helmetObj, link: `${helmetObj.link}${seoLinks} || ''`}; // merge helmet const appContent = staticContent.replace(`<div id="detail-rnr"></div>`, reviewContent); // merge markup const headCss = `${staticHeadCss}${reviewHeadCss}`; // merge css   const data = {     appContent,     headCss,     storeJson,     helmetObj: finalHelmetObj   };
  • 15. FUTURE OF COMPONENT LEVEL CACHIING REACT COMPONENT CACHING https://github.com/rookLab/rea ct-component-caching REACT CACHE https://github.com/facebook/re act/tree/master/packages/reac t-cache CONCURRENT RENDERING IN REACT https://www.youtube.com/watc h?v=ByBPyMBTzM0
  • 16. Anusheel Singh - @ImAnusheel TEAM GOIBIBO - @GOIBIBO_TECH Q & A THANK YOU