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
gRPC入門
Search
Taiga Sakaguchi
November 19, 2022
Technology
0
210
gRPC入門
Taiga Sakaguchi
November 19, 2022
Tweet
Share
More Decks by Taiga Sakaguchi
See All by Taiga Sakaguchi
トランクベース開発のすすめ
taigaskg
0
110
クリーンアーキテクチャのすすめ
taigaskg
0
290
Other Decks in Technology
See All in Technology
読んで学ぶ Amplify Gen2 / Amplify と CDK の関係を紐解く #jawsug_tokyo
tacck
PRO
1
140
Cursor AgentによるパーソナルAIアシスタント育成入門―業務のプロンプト化・MCPの活用
os1ma
14
4.8k
Running JavaScript within Ruby
hmsk
3
330
AWS Control Towerを 数年運用してきての気づきとこれから/aws-controltower-ops-tips
tadayukinakamura
0
150
“パスワードレス認証への道" ユーザー認証の変遷とパスキーの関係
ritou
1
590
AIでめっちゃ便利になったけど、結局みんなで学ぶよねっていう話
kakehashi
PRO
0
160
Dynamic Reteaming And Self Organization
miholovesq
3
510
SREからゼロイチプロダクト開発へ ー越境する打席の立ち方と期待への応え方ー / Product Engineering Night #8
itkq
2
840
AI Agentを「期待通り」に動かすために:設計アプローチの模索と現在地
kworkdev
PRO
2
450
LangfuseでAIエージェントの 可観測性を高めよう!/Enhancing AI Agent Observability with Langfuse!
jnymyk
1
230
The Tale of Leo: Brave Lion and Curious Little Bug
canalun
1
120
【Λ(らむだ)】最近のアプデ情報 / RPALT20250422
lambda
0
110
Featured
See All Featured
Thoughts on Productivity
jonyablonski
69
4.6k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
5
520
We Have a Design System, Now What?
morganepeng
52
7.5k
Building an army of robots
kneath
304
45k
4 Signs Your Business is Dying
shpigford
183
22k
Scaling GitHub
holman
459
140k
Six Lessons from altMBA
skipperchong
27
3.7k
Rails Girls Zürich Keynote
gr2m
94
13k
Agile that works and the tools we love
rasmusluckow
328
21k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Transcript
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