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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
200
知って得する@cloudflare_vite-pluginのあれこれ
chimame
2
670
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
510
エッジで輝くフロントエンド
chimame
11
7k
Cloudflare Workersと状態管理
chimame
4
2.1k
Other Decks in Programming
See All in Programming
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
530
テストを司るデーモンに会いに行く 〜隔離した仮想マシンでテストを通すまで〜
h1d3mun3
1
550
手動確認はもう限界 〜XCUITestでCustom URL Schemeの遷移を起動種別ごとに自動テストする〜 / Testing Custom URL Schemes with XCUITest
otouto
0
320
FreeBSDでZabbixを動かす
kenkino
0
320
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
160
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
350
Building an Out-of-Order CPU
latte72
1
790
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
300
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
130
Vibes Containers 〜AIで変わるコンテナ設計と運用〜
tkikuc
3
560
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
7
2.2k
TiDB Cloudのカスタムコントローラーによるオートスケール対応
takaidohigasi
0
130
Featured
See All Featured
ラッコキーワード サービス紹介資料
rakko
1
5M
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
65k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
6.2k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.6k
A Soul's Torment
seathinner
8
3.6k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
710
Joys of Absence: A Defence of Solitary Play
codingconduct
1
530
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
440
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
BBQ
matthewcrist
89
10k
Skip the Path - Find Your Career Trail
mkilby
1
240
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