Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Server Side Rendering Tuning with Next.js
Search
Yutaro Miyazaki
July 03, 2019
Technology
1.7k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Server Side Rendering Tuning with Next.js
Yutaro Miyazaki
July 03, 2019
More Decks by Yutaro Miyazaki
See All by Yutaro Miyazaki
React + Apollo Client (GraphQL) により変化するアプリケーション設計
vwxyutarooo
6
3.3k
The challenge of Mercari Web Re-Architecture Project
vwxyutarooo
1
200
ゼロから始めるっぽい Service Worker
vwxyutarooo
5
1.1k
Other Decks in Technology
See All in Technology
【Aiming】共通基盤なのに「共通化しない」課金・認証基盤「LINK」が選び取ったシングルテナント戦略と運用の秘訣
saikeda
0
140
AIにブラウザを触らせて、E2EテストをPlaywrightで書く
koji_kawamura
0
350
【GCC2026】大規模言語モデルを活用した内製検索サービスの社内展開や業務活用
bandainamcostudios
PRO
0
490
Flutter × BLE Centralを自前Pluginで実装する設計パターン - MethodChannel / EventChannelで作る双方向ブリッジの実践 / Building Custom Flutter BLE Central Plugins: Bidirectional Bridging with Method & Event Channels
bitkey
PRO
0
230
LLM・AIエージェントシステムベストプラクティス
shibuiwilliam
6
1.6k
도구에서 동료까지: 10년차 AI 스타트업의 AI 적응기
inureyes
PRO
1
330
35分でわかるEffective Platform Engineering
nwiizo
5
600
AI画像認識を活用したゲーム内決済処理検証の自動化
gree_tech
PRO
0
110
AIで変わるエンジニアの働き方(仮)
naoinaoi
0
390
VLMで2.3万枚のPyCon JP写真を検索!
terapyon
1
260
Rust×eBPFでEDRっぽいものをつくる
sunlife3
2
820
強化学習「理論」入門
enakai00
3
3.6k
Featured
See All Featured
Speed Design
sergeychernyshev
33
2k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
310
Tell your own story through comics
letsgokoyo
1
1k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
260
Become a Pro
speakerdeck
PRO
31
6.2k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
2
3.8k
Side Projects
sachag
455
43k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
970
How to make the Groovebox
asonas
2
2.3k
Transcript
Server Side Rendering Tuning with Next.js Server Side Rendering Tuning
with Next.js Mercari x Merpay Frontend Tech Talk vol.2 @vwxyuratoooo
Yutaro Miyazaki (@vwxyutarooo) Yutaro Miyazaki (@vwxyutarooo) 2012~ Jobless 2013~ Freelance
2016~ Startup 2018~ Mercari
My Talk is About... My Talk is About... Our new
architecture of Mercari Web The performance issue of Server Side Rendering with Next.js
Topics Topics Mercari Web Re-Architecture Apollo Next.js Performance Tuning Conclusion
What Web Re-Architecture is What Web Re-Architecture is
Ancient Huge PHP Code ↓ Modern Architecture
None
None
None
None
Topics Topics Mercari Web Re-Architecture Apollo Next.js Performance Tuning Conclusion
Apollo Apollo
None
None
Topics Topics Mercari Web Re-Architecture Apollo Next.js Performance Tuning Conclusion
None
Next.js Upside Next.js Upside Build System Smart Chunk System Various
Practices
Next.js Downside Next.js Downside Folder Structure Router We hit the
Server Side Rendering Performance issue...?
Server Side Rendering Performance?
None
100 requests per second. 40 CPU cores were waste. It
still doesn't reaches to 100 requests per second On the production environment It's supposed to spend 800 CPU cores.
None
Topics Topics Mercari Web Re-Architecture Apollo Next.js Performance Tuning Conclusion
Performance Tuning Performance Tuning How can we solve this catastrophic
performance issue
Render method tuning renderToNodeStream for example. Cache
Investigation Investigation
What We Learned is What We Learned is Styled Components
CategoryLists component Contained regular expression. renderToStaticMarkup and renderToHTML .
Things we've adopted: Prevent HTML from rendering twice. Client Side
Render Component.
1. Prevent HTML From Rendered Twice 1. Prevent HTML From
Rendered Twice
Why Why It's rendered twice by renderToStaticMarkup and renderToHTML ?
None
The case of React Apollo const Dogs = ({ onDogSelected
}) => ( <Query query={GET_DOGS}> {({ loading, error, data }) => { if (loading) return 'Loading...'; if (error) return `Error! ${error.message}`; return ( <select name="dog" onChange={onDogSelected}> {data.dogs.map(dog => ( <option key={dog.id} value={dog.breed}> {dog.breed} </option> ))} </select> ); }} </Query> );
None
None
For general purpose, React Apollo needs to correct all queries
from component tree.
Our Solution Our Solution Fragments + React Apollo Fragments +
Apollo Client
Fragments: query GetPerson { people(id: "7") { firstName lastName avatar(size:
LARGE) } } fragment NameParts on Person { firstName lastName } query GetPerson { people(id: "7") { ...NameParts avatar(size: LARGE) } }
None
const data = (await apolloClientInstance.query(queryOptions)).data;
Measuring Performance (again) Measuring Performance (again)
None
2. Client Side Render Component 2. Client Side Render Component
None
None
By DynamicComponent: import dynamic from 'next/dynamic'; const DynamicComponentWithNoSSR = dynamic(
() => import('../components/hello3'), { ssr: false } ); export default const Index = () => <div><DynamicComponentWithNoSSR /></div>;
Measuring Performance (again) Measuring Performance (again)
Topics Topics Mercari Web Re-Architecture Apollo Next.js Performance Tuning Conclusion
Additionally The Latency Duration has Improved P50: 1,000ms -> 600ms
Also we saved nearly 1.5 million yen per month.
It doesn't matter which frame work you choose, the performance
needs to be considered by application.
Don't Guess, Measure.