Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
GraphQL Server on Edge
Search
chimame
July 19, 2023
Programming
6.8k
12
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
GraphQL Server on Edge
Workers Teck Tolks #1
chimame
July 19, 2023
More Decks by chimame
See All by chimame
Cloudflare is Agents
chimame
0
210
知って得する@cloudflare_vite-pluginのあれこれ
chimame
2
690
Boost Your Web Performance with Hyperdrive
chimame
1
580
RemixでVersion skewに立ち向かう
chimame
2
1.3k
私がエッジを使う理由
chimame
10
4.2k
GraphQL Server on Edge after that
chimame
1
1.9k
Accelerating App Dev with Cloudflare Workers
chimame
1
520
エッジで輝くフロントエンド
chimame
11
7k
Cloudflare Workersと状態管理
chimame
4
2.1k
Other Decks in Programming
See All in Programming
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
190
JRuby: Past, Present, and Future
headius
0
220
Agents on Rails - Rails at Scale 2026
irinanazarova
0
310
Turning Architecture into Unit Tests in the AI Era (NSSpain XIV)
steliosf
PRO
1
120
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
380
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
1k
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2.6k
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
220
SREの越境 / SRE Collaboration
y0hgi
2
290
mrbgem 三角測量 開発
ogom
0
170
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
460
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
270
Featured
See All Featured
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
290
How to Ace a Technical Interview
jacobian
280
24k
brightonSEO & MeasureFest 2025 - Winning Strategies for Black Friday CRO & PPC - Christian Goodrich
cargoodrich
3
860
[SF Ruby Conf 2025] Rails X
palkan
3
1.4k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
540
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Deep Space Network (abreviated)
tonyrice
0
350
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
420
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
270
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
What's in a price? How to price your products and services
michaelherold
247
13k
Transcript
GraphQL Server on Edge Workers Tech Talks #1 2023.07.19
目次 • (GraphQL) API Server 構築 • サーバレスコンテナサービスの運用課題 • Cloudflare
Workersという選択肢 • ユースケース • まとめ
今日話すことの細かい実装はこちら
(GraphQL) API Server • APIサーバはどこにどうやって建てますか? ◦ Amazon Web Services(Fargate, App
Runner, EKS) ◦ Google Cloud(App Engine, Cloud Run, GKE) ◦ Azure(Container Instances, Container Apps, AKS) ◦ オンプレ • Backend for frontend(BFF)の設計になるとAPI Serverの管理者は誰? ◦ バックエンド? ◦ フロントエンド?
(GraphQL) API Server 私の場合は、初手は大体Cloud Run • サーバレスアーキテクチャにしてインフラコストを 極限まで下げる • 最終的にデータがBigQueryに行くことが多いの
で、Google Cloudは結局使うことになる • アプリケーションが最終的にコンテナで動けば、他 に移行もそこまで難しくない
サーバレス(コンテナ)サービスの運用課題 Cloud Runに限らず、サーバレスも銀の弾丸ではない • コンテナのデプロイまでの時間がかかる • コールドスタートを短く抑えないといけない • コンピュータリソースあたりの単価は高め
さて、どうしよう??🤔
Cloudflare Workersという選択肢 パブリッククラウドのサーバレスサービスと比較して異なるところ • ビルドしたファイルをデプロイする • V8エンジンをランタイムとして採用 • 基本料金$5で、最低100万リクエストは処理できる
Cloudflare Workersという選択肢 パブリッククラウドのサーバレスサービスと比較して異なるところ • ビルドしたファイルをデプロイする → コンテナを入れ替えるより高速にデプロイが可能 • V8エンジンをランタイムとして採用 →
V8 isolateを使用することで高速に起動できる • 基本料金$5で、最低100万リクエストは処理できる → 計算リソースあたりの単価が非常に安価
Cloudflare Workersという選択肢 なんで今まで選択されてこなかった? • Cloudflareにロックインする • ランタイムがNode.jsではないのでNode.jsに依存する資産は使用できない • Cloudflare WorkersからRDBMSに接続するにはhttpで接続するしかなかった
Cloudflare Workersという選択肢 なんで今まで選択されてこなかった? • Cloudflareにロックインする • ランタイムがNode.jsではないのでNode.jsに依存する資産は使用できない • Cloudflare WorkersからRDBMSに接続するにはhttpで接続するしかなかった
許容すれば選択可 TCPでの接続が行えるようになった
※管理画面 ユースケース Cloudflare Workers Durable Objects Authentication Cloud Messaging Crashlytics
etc 認証 画像データ Socket通信 GraphQL PUSH その他サービス サービス初期
※管理画面 ユースケース Cloudflare Workers Durable Objects Authentication Cloud Messaging Crashlytics
etc 認証 画像データ (R2) Socket通信 GraphQL PUSH Node.js処理サーバ GraphQL Server その他サービス 現在
ユースケース ライブラリの変遷 • Fastify • Apollo Server • Prisma •
Pothos • GraphQL Yoga • Kysely (Prisma) • Pothos 2.0からWeb Standard APIで動作するように再構築されている。 そのためCloudflare Workersでも動作する。 Prismaは通常のモードでは Cloudflare Workersで動作しない。代替に別ライブラリを使用する必要があ る。自分の場合はPrismaのマイグレーション機能および Kyselyのデータベースの型生成として使用してい る。
ユースケース 移行した効果(メリット) • コンテナのデプロイまでの時間がかかる → デプロイ時間が8分前後が1分未満に短縮 • コールドスタートを短く抑えないといけない → 最大5秒前後が200ミリ秒程度まで高速化
• コンピュータリソースあたりの単価は高め → 数万円/月のAPIサーバ費が数千円/月に低下(約1/10)
ユースケース 移行に際した注意点(デメリット) • Node.jsが必要な場合は別途サーバを用意する必要がある ◦ Cloud Runで構築した場合はリクエスト時間に影響しないようにする (非同期処理にする、起動時間を早くする etc) •
TCPの接続はリクエスト処理している間だけ接続可能である ◦ waitUntilに接続するような処理があるとうまくいかない場合がある ◦ DataLoaderも動作しない場合がある
まとめ • Cloudflare WorkersでAPIサーバを構築する のは既に実用的な段階にある ◦ オリジンの”味付け”ではなく、単体でサーバとして機 能する • Cloudflareにロックインはするが、それに見
合ったメリットは十分にある
Thanks! • name: chimame / rito • job: Webエンジニア •
field: Cloudflare, GCP, AWS, Ruby, Node.js, TypeScript, React, Next.js, Remix, Docker etc • company: Goens株式会社( https://about.goen-s.com ) • twitter: @chimame_rt • GitHub: chimame