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.6k
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
190
ゼロから始めるっぽい Service Worker
vwxyutarooo
5
1.1k
Other Decks in Technology
See All in Technology
新しいVibe Codingと”自走”について
watany
5
240
"何を作るか"を任される エンジニアは、どう育つのか
yutaokafuji
1
260
[モダンアプリ勉強会]今更聞けないGit/GitHub入門
tsukuboshi
0
310
ChatworkとBPaaS 異なる特性で学んだAI機能開発の ベストプラクティス
kubell_hr
2
3.2k
EventBridge Connection
_kensh
5
670
運用を見据えたAIエージェント設計実践
amacbee
1
3.3k
Snowflakeと仲良くなる第一歩
coco_se
3
250
【Gen-AX】20260530開催_JJUG CCC 2026 Spring
genax
1
440
サプライチェーンセキュリティの空白地帯 - 信頼できる”依存性”の未来を考える
rung
PRO
2
790
機械学習を「社会実装」するということ 2026年夏版 / Social Implementation of Machine Learning June 2026 Version
moepy_stats
2
360
「エンジニア進化論」2028年の開発完全自動化、エンジニアはどう進化するか
cyberagentdevelopers
PRO
1
160
GoとSIMDとWasmの今。
askua
3
520
Featured
See All Featured
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
62
44k
The Invisible Side of Design
smashingmag
302
52k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.3k
Site-Speed That Sticks
csswizardry
13
1.2k
Visualization
eitanlees
152
17k
Building Applications with DynamoDB
mza
96
7.1k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
550
Chasing Engaging Ingredients in Design
codingconduct
0
210
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
54k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
From π to Pie charts
rasagy
0
200
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.