why we’re building a worse wheel decoupled...decoupled why we’re building a worse wheel josh...

43
Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Upload: others

Post on 16-Oct-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

DecoupledWhy we’re building a worse wheel

Josh WaihiNovember 2019

デカップルドなぜ悪い車輪を構築してしまうのか

Page 2: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

https://www.youtube.com/watch?v=6GwTClYxFmohttps://drupalsouth.org/

Drupal South Hobart 2019で、Josh Waihiが話した内容を日本語で発表します

Page 3: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Profile自己紹介

Hikaru Maruyama 丸山ひかる

Acquia Technical Translator

Developer Relations

Drupaler Since 2019.08

Ruby / Rails / Web API / Docker / AWS

Page 4: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

HISTORYLET’S LOOK AT DRUPAL’S EVOLUTION

Drupalの進化をみてみましょう!

Page 5: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Traditional DrupalThe static web

従来のDrupal - 静的ウェブサイト

Server Side

Database

PHP

Web server

Client Side

BrowserHTML

Filesystem CSS/JS/IMG

“pageview”

Page 6: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Resource demandA “mainframe” approachリソースの需要 - メインフレーム型のアプローチ

Server Side

Database

PHP

Web server

Client Side

BrowserHTML

Filesystem CSS/JS/IMG

“pageview”

DynamicResource intensive

StaticConservative

Page 7: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Loading JourneyDrupal bound performance

読込時間から見るDrupalの性能限界

Page 8: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Delivery OptimisationReverse cache proxies

Server Side

Database

PHP

Web server

Client Side

Browser

HTML

Filesystem CSS/JS/IMG

“pageview”

DynamicResource intensive

StaticConservative

Cache

CD

N

The read-only world

配信の最適化 - リバースキャッシュプロキシ

Page 9: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Loading JourneyServer-side caching shifts performancefocus to client-sideサーバーサイドキャッシュにより、クライアントサイドに焦点をシフト

Page 10: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

ページ配布

トラフィック

キャッシュヒット率

Performanceexample 10k pageviews

● Site = 500 pages● Average Drupal Response Time = 1.8 seconds● 10,000 pageviews

Page Distr 20% (100) 30% (150) 35% (175) 15% (75)

Traffic Distr 70% (7k) 20% (2k) 7% (700) 3% (300)

Cache Hit Rate 98.57% 92.5% 75% 75%

● Cache Hit Rate Avg 85.27%● 14.73% of traffic > 1.8s TTFB● Assuming no cache invalidation or expiry takes place

1万ページビューの場合のパフォーマンス

サイト = 500ページ数平均レスポンスタイム = 1.8秒1万ページビュー

平均キャッシュヒット率 85.27%14.73%のトラフィック > 1.8秒のTTFB(TIme To First Byte)

キャッシュ無効化なし and 有効期限なしを想定

Page 11: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Performanceexample 5k pageviews

● Site = 500 pages● Average Drupal Response Time = 1.8 seconds● 5,000 pageviews

Page Distr 20% (100) 30% (150) 35% (175) 15% (75)

Traffic Distr 70% (7k) 20% (2k) 7% (700) 3% (300)

Cache Hit Rate 97.14% 85% 58.33% 50%

● Cache Hit Rate Avg 72.62%● 27.38% of traffic > 1.8s TFFB● Assuming no cache invalidation or expiry takes place

ページ配布

トラフィック

キャッシュヒット率

5千ページビューの場合のパフォーマンス

サイト = 500ページ数平均レスポンスタイム = 1.8秒5,000ページビュー

平均キャッシュヒット率 72.62%27.38%のトラフィック > 1.8秒のTTFB(TIme To First Byte)

キャッシュ無効化なし and 有効期限なしを想定

Page 12: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

MO PAGEVIEWSMO PERFORMANCE

Page 13: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Content IntegrityCache invalidation

Server Side

Database

PHP

Web server

Client Side

Browser

HTML

Filesystem CSS/JS/IMG

“pageview”

DynamicResource intensive

StaticConservative

Cache

CD

N

The read-only world

Cache Purge

コンテンツの完全性 - キャッシュの無効化

Page 14: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Modern Paradigm ShiftsIn the Web

● Data refresh, not page refresh● Personalised experience● Event-driven data push

Javascript is naturally suited to modern demands of the web

● Pageless DOM manipulation● Client-side personalisation processing power● Event-driven backend supports push (websockets) and pull (req)

ページの更新ではなくデータの更新

パーソナライズ体験

イベントドリブンなデータプッシュ

JavaScriptは現代の要求に適している

ページレスなDOM操作

クライアント側の処理能力

イベントドリブンなバックエンドは

プッシュ(websockets)とプル(リクエスト)をサポート

現代のパラダイムシフト

Page 15: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Traditional DrupalPros/Cons

Pros

● Content Management

● Optimised Content Delivery

● Centralised processing

● Scale simple content

Cons

● Monolithic

● Complexity with personalisation

● Limited frontend leverage

● Slow TTFB

従来のDrupalのメリット/デメリット

メリット デメリット

コンテンツマネジメント

コンテンツ配信の最適化

集中処理

シンプルなコンテンツのスケール

モノリシック

パーソナライズの複雑さ

フロントエンドレバレッジの制限

遅いTTFB

Page 16: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Dynamic ClientLocalised processing

Server Side

Database

PHP

Web server

JS Engine

Dynamic UX

Client Side

HTML

Filesystem

CSS/JS/IMG

“experience”

Dynamic Static

Cache

CD

N

動的クライアント - ローカライズされた処理

Page 17: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Loading JourneyClient-side complexityクライアント側の複雑さ

Page 18: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか
Page 19: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

JavaScript - the popularity of

The State of Octoverse results for 2018. Category: languages. Source: Octoverse

JavaScriptは人気

Page 20: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

JavaScript - the job market

https://www.hiringlab.org/2018/11/29/hottest-skills-tech-job-searches1/

JavaScriptは求人でも人気

Page 21: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

GitHub Emojis

Page 22: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか
Page 23: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

MicroservicesPolylithic service delivery

Server Side

Database

PHP

Web server

Dynamic UXJS Engine

Client Side

HTML

Filesystem

IMG

“experience”

Dynamic

Static

Cache

CD

N

Filesystem Web server

CSS/JS

マイクロサービス - ポリリシックなサービス提供

Page 24: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Loading JourneyClient-side App loadingクライアントサイドのアプリケーション読み込み

Page 25: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

https://medium.com/@addyosmani/the-cost-of-javascript-in-2018-7d8950fbb5d4

Page 26: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

https://medium.com/@addyosmani/the-cost-of-javascript-in-2018-7d8950fbb5d4

Page 27: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

https://medium.com/@addyosmani/the-cost-of-javascript-in-2018-7d8950fbb5d4

Page 28: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

https://medium.com/@addyosmani/the-cost-of-javascript-in-2018-7d8950fbb5d4

Page 29: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

https://medium.com/@addyosmani/the-cost-of-javascript-in-2018-7d8950fbb5d4

Page 30: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

https://medium.com/@addyosmani/the-cost-of-javascript-in-2018-7d8950fbb5d4

Page 31: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

https://medium.com/@addyosmani/the-cost-of-javascript-in-2018-7d8950fbb5d4

Page 32: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Reinventing Server-side rendering

Server Side

Database

PHP

Web server

Dynamic UXJS Engine

Client Side

HTMLFilesystem

IMG

“experience”

Dynamic

Static

Cache

CD

N

Filesystem Web server

CSS/JSNode.js

再発明 - サーバーサイドレンダリング(SSR)

Page 33: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Reinventing Server-side rendering

Server Side

Database

PHP

Web server

Dynamic UXJS Engine

Client Side

HTMLFilesystem

IMG

“experience”

Dynamic

Static

Cache

CD

N

Filesystem Web server

CSS/JSNode.js

再発明 - サーバーサイドレンダリング(SSR)

Page 34: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Loading JourneyThis looks suspiciously familiar...これは非常に疑わしい...

Page 35: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Pros

● Content Management

● Optimised Content Delivery

● Centralised processing

● Scale simple content

Fully DecoupledPros/Cons

Cons

● Polylithic

● Backend Complexity

● No cache invalidation

● Slow TTFB?

完全なデカップルド設計 - メリット/デメリット

メリット

コンテンツマネジメント

コンテンツ配信の最適化

集中処理

シンプルなコンテンツのスケール

デメリット

ポリリシック

バックエンドの複雑さ

キャッシュ無効化なし

遅いTTFB?

Page 36: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Reinventing the WheelFor Server-side Content Delivery

PHP Node.js

車輪の再発明 - サーバーサイドのコンテンツ配信

Page 37: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Early

Ado

pter

s

Early

Maj

ority

Late

Maj

ority

Lagg

ers

Technology Maturity

EOL

テクノロジーの成熟度

Page 38: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Early

Ado

pter

s

Early

Maj

ority

Late

Maj

ority

Lagg

ers

Feature complete

Buildin

g Fr

amew

orks

PoC Usable

Stable

Solved

Boring

Technology Maturity

EOL

テクノロジーの成熟度

Page 39: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Early

Ado

pter

s

Early

Maj

ority

Late

Maj

ority

Lagg

ers

Feature complete

Buildin

g Fr

amew

orks

PoC Usable

Stable

Solved

Boring

Primetime

Technology Maturity

EOL

テクノロジーの成熟度

Page 40: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Early

Ado

pter

s

Early

Maj

ority

Late

Maj

ority

Lagg

ers

Feature complete

Buildin

g Fr

amew

orks

PoC Usable

Stable

Solved

Boring

Primetime

Technology Maturity

EOL

Node

Drupal

Java

テクノロジーの成熟度

Page 41: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

REINVENT A BETTER WHEEL

(To the tune of the gambler)

You gotta know when to decoupleknow when to coupleknow when you need FE dynamecy know when you don’t

You gotta count your node_moduleswhen your setting on the PR merge

They’ll be time enough for renderingwhen the compiling’s done

いつ分離するか、いつ結合するか

いつフロントエンド ダイナミズムが

必要になるのか

知らない時に知っておく必要がある

PRがマージされる時

node_modulesを数える必要がある

コンパイルが完了したら

レンダリングに十分な時間になります

より良い車輪を再発明する

Page 42: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか

Decoupling tips● Performance is worse in a fully decoupled architecture.

● Start coupled and validate reasons to decouple.

● Polylithic delivery increases operational costs exponentially.

● Clarify editorial requirements up front.

○ Editorial layout management is hard in a decoupled architecture.

● DO NOT DIY API. Use JSON:API or GraphQL.

デカップリングのヒント

完全に分離された(デカップルド)設計では、パフォーマンスが低下

まずはカップルド設計ではじめて、分離する理由を検証する

ポリリシック配信は、運用コストを指数関数的に増加させる

編集要件を前もって明確にする

デカップルド設計では、編集レイアウトの管理は困難

DIY(自家製)APIはやめて、JSON:APIまたはGraphQLを使う

Page 43: Why we’re building a worse wheel Decoupled...Decoupled Why we’re building a worse wheel Josh Waihi November 2019 デカップルド なぜ悪い車輪を構築してしまうのか