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
gRPC入門
Search
Taiga Sakaguchi
November 19, 2022
Technology
300
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
gRPC入門
Taiga Sakaguchi
November 19, 2022
Transcript
32 slides
gRPC 入門 Taiga Sakaguchi 1
Sakaguchi Taiga 教員→Web エンジニア 歴3 年 バックエンドエンジニア 都内メガベンチャーに勤務 2
gRPC とは Google によって開発されたRPC フレームワーク 3
RPC とは Remote Procedure Call の頭字語(遠隔手続き呼び出し) ネットワークを通じて別のコンピュータ上で動作するソフトウェア の関数を呼び出すための仕様 4
一般的な関数呼び出し 5
RPC における関数呼び出し 6
RPC の何が嬉しいのか ローカルの関数かリモートの関数かを意識せずにコードを書くこと ができる 7
type Server struct {} type User struct{ ID string }
func (s *Server) GetUser(id string) *User {} type Client struct {} func (c *Client)DoSomething() { u := c.GetUser("userid") } 8
REST だったら type Server struct {} func main() { r
:= gin.Default() r.GET("/user/:id", getUser) r.Run() } func getUser(c *gin.Context) {} type Client struct {} func (c *Client) DoSomething() { resp, err := http.Get("http://user/1") } 9
https://grpc.io/docs/what-is-grpc/introduction/ 10
Protocol Buffers Google により開発 IDL (インターフェース定義言語) 通信や永続化での利用を目的としたシリアライズフォーマット コードやDocs など自動生成できる 11
syntax = "proto3"; service User { rpc GetUser(GetUserRequest) returns (GetUserResponse)
{} } message GetUserRequest { string id = 1; } message GetUserResponse { string id = 1; string name = 2; } 12
サーバー用の生成コード // ... type UserServer interface { GetUser(context.Context, *GetUserRequest) (*GetUserResponse,
error) mustEmbedUnimplementedUserServer() } // ... 13
クライアント用の生成コード // ... type UserClient interface { GetUser(ctx context.Context, in
*GetUserRequest, opts ...grpc.CallOption) (*GetUserResponse, error) } func NewUserClient(cc grpc.ClientConnInterface) UserClient { return &userClient{cc} } // ... 14
ここでクイズ gRPC の「g 」の意味はなんでしょうか? 1. Google 2. Good 3. Great
4. Game 15
ここでクイズ gRPC の「g 」の意味はなんでしょうか? 1. Google 2. Good 3. Great
4. Game 16
gRPC の「g 」はバージョンごとに意味がかわるらしい https://github.com/grpc/grpc/blob/master/doc/g_stands_for.md 17
gRPC のメリット HTTP/2 で通信 Protocol Buffers によるシリアライズ ストリーミング処理 多くの言語に対応(Go, Java,
Kotlin, Node, PHP, Python, Ruby,... ) 18
4 つの通信方式 Unary RPC Server streaming RPC Client streaming RPC
Bidirectional streaming PRC 19
Unary RPC 1 Request - 1 Response 20
Server streaming RPC 1 Request - N Response 例)push 通知など
21
Client streaming RPC N Request - 1 Response 例)データを分割して複数回に分けてアップロード 22
Bidirectional streaming PRC WebSocket のような双方向通 例) チャット 23
gRPC のデメリット PRC の設計に気をつけないと破綻する 実装に時間がかかる ブラウザでのサポートが十分でない 24
gRPC が向いているケース Microservice プライベートなAPI モバイル、IoT 25
ブラウザ - サーバー間で導入するには grpc-web grpc-gateway connect 26
grpc-web 27
grpc-gateway 28
connect https://connect.build/ 29
connect 30
参考 https://grpc.io/ https://zenn.dev/hsaki/books/golang-grpc-starting https://christina04.hatenablog.com/entry/2017/11/13/190000 https://qiita.com/gold-kou/items/a1cc2be6045723e242eb 31
32
More Decks by Taiga Sakaguchi
See All by Taiga Sakaguchi
トランクベース開発のすすめ
taigaskg
0
150
クリーンアーキテクチャのすすめ
taigaskg
0
360
Other Decks in Technology
See All in Technology
変更差分を読むために環境を整備しよう
pipepasta
1
580
セキュリティチームは どのコンテナイメージの脆弱性対応を優先すべきか 〜CISA新指針とSCCで作る脆弱性トリアージ〜
swdtkuy
0
270
その修正で本当に速くなったのか? k6とOpenTelemetryで確かめる性能改善 / Performance review with k6 and OpenTelemetry
ymotongpoo
3
420
常時稼働エージェントの作り方(Claude公式ブログを資料化)
minorun365
PRO
18
29k
AWS Well-Arhitected Frameworkセキュリティの柱 について
miu_crescent
PRO
2
160
自動計装なしでECSサービスをApplication Signalsに載せるまで
ota1022
2
450
共通基盤の実装に Kotlin - Quarkus を選定した理由と採用したアーキテクチャ
nealle
1
150
SORACOM × AWS IoT Core でSREする
butadora
0
120
AIネイティブ組織の作り方。1人のPOとAIから始める、自社での実験
ama_ch
2
1.3k
人の努力に頼らないセキュリティをエンジニアリングする在り方 / An approach to engineering security that does not rely on human effort
carta_engineering
0
240
みん強Lightning! データ基盤ひとりでできるかな
endonanana
0
160
市販IoT機器や自作IoT機器とHomeAssistantを駆使して家の電気代をできる限り見える化する方法の考案
harutiro
0
410
Featured
See All Featured
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
640
So, you think you're a good person
axbom
PRO
2
2.3k
The Cult of Friendly URLs
andyhume
79
7.1k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
121
130k
From π to Pie charts
rasagy
1
460
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
310
How to train your dragon (web standard)
notwaldorf
96
6.9k
How to Think Like a Performance Engineer
csswizardry
28
2.9k
A Modern Web Designer's Workflow
chriscoyier
699
190k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
490
Accessibility Awareness
sabderemane
1
310
Darren the Foodie - Storyboard
khoart
PRO
5
4.1k