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
From PHP and REST to gRPC and Go
Search
Yuriy Tuz
December 04, 2019
Programming
0
81
From PHP and REST to gRPC and Go
Yuriy Tuz
December 04, 2019
Tweet
Share
More Decks by Yuriy Tuz
See All by Yuriy Tuz
From PHP and REST to gRPC and Go Full
yuriytuz
0
51
Other Decks in Programming
See All in Programming
AI によるインシデント初動調査の自動化を行う AI インシデントコマンダーを作った話
azukiazusa1
1
750
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
21
7.4k
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
650
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
1
990
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
2
4.4k
2026年 エンジニアリング自己学習法
yumechi
0
140
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
6.1k
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
2.5k
OSSとなったswift-buildで Xcodeのビルドを差し替えられるため 自分でXcodeを直せる時代になっている ダイアモンド問題編
yimajo
3
620
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
380
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
210
カスタマーサクセス業務を変革したヘルススコアの実現と学び
_hummer0724
0
730
Featured
See All Featured
From π to Pie charts
rasagy
0
130
Music & Morning Musume
bryan
47
7.1k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
330
Paper Plane
katiecoart
PRO
0
46k
GitHub's CSS Performance
jonrohan
1032
470k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3k
Test your architecture with Archunit
thirion
1
2.2k
How to train your dragon (web standard)
notwaldorf
97
6.5k
Code Reviewing Like a Champion
maltzj
527
40k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.1k
Transcript
From PHP and REST To gRPC and Go Winnipeg, December
4 2019 Yuriy Tuz Bold Commerce @yuriytuz
#GoTurns10
whoami
Objectives • Personal experience • Why gRPC • gRPC in
GO ◦ Simple implementation
In the beginning • Laravel 4.x / 5.x • PHP
7.x ◦ Introduced types
Back in the day
REST (HTTP + JSON) • Not a bad solution •
Service to service communications • JSON is not type safe in PHP • (De)Serialization performance • Text protocol
Thank you Questions?
REST in Laravel • api.php • Magic • response()->json([???]) •
Docs accuracy
Problem • Technology is driving demand • Languages and platforms
◦ Different dev experience • Software architecture is evolving ◦ Microservices and containers ◦ CI/CD
An Idea
An Idea • Bloated service ◦ 1000+ lines • Hack
Day • How?
No Idea
How/why? • Why split? • Why Go? • Why not
REST (HTTP+JSON)? ◦ No formal contract ◦ Hard to implement correctly
Possible Solution
What do we need? • PHP RPC client • RPC
server
Implementation/Findings • PHP client not fun ◦ Working POC •
First experience with Go • Refactoring • Benchmarks ◦ ~100x faster
time.Now()
Stack • Protocol buffers + gRPC • Thanks Google
Protocol buffers are a language-neutral, platform-neutral extensible mechanism for serializing
structured data. Protocol Buffers
What does this mean? • Serialization mechanism • Interface description
language
Serialization Mechanism • 0a 05 68 65 6c 6c 6f
• 68 65 6c 6c 6f -> hello • 05 -> length of “hello” • 0a is “0000 1010”, so • field_number = 1 • wire_type = 2 (length delimited)
Interface Definition Language message Person { string name = 1;
} Interface for your API
gRPC • Open source messaging system by Google that can
run anywhere • Low latency • Highly scalable • Great for distributed systems • Accurate, efficient, language independent
Adopted by many (and more)
Let’s do it
echo.proto
Let’s generate • protoc --go_out=:. ./echo.proto ◦ Default protobuf generation
• protoc --go_out=plugins=grpc:. ./echo.proto ◦ Client and Server interface ◦ gRPC
Success!
Server
Generated Interface
Server implementation
Server Spin up server
Client
Client interface
Client
So far • Server • Client
New Requirement Logging
gRPC middleware • Server or Client • Few exist in
gRPC ecosystem ◦ Prometheus ◦ Open tracing • https://github.com/grpc-ecosystem/go-grpc-middleware
How?
gRPC middleware
>1 interceptor?
Directory structure • Client & server implementation • echo.pb.go ◦
gRPC generated • echo.proto ◦ API definition
Helpful tools
grpcurl • “curl” for gRPC • Requires server reflection
None
Examples
grpcui • Postman for RPC • Also requires reflection
None
None
Final thoughts The good • Code generation ◦ Less error
prone • API spec • gRPC ◦ HTTP2 + language support • Type safety • Plugins • Dev ramp up speed The bad • Code generation • Model conversions ◦ Nested messages • Hard/scary to get started ◦ Documentation • API versioning
TL;DR • Use gRPC + Go • Generate code •
Implement stubs • Profit
Credits/Useful links • Gopher art by Ashley McNamara ◦ https://github.com/ashleymcnamara/gophers
• gRPC ◦ https://grpc.io/ • Google API Design Guide ◦ https://cloud.google.com/apis/design/ • Protobuf Style Guide ◦ https://developers.google.com/protocol-buffers/docs/style • rpcurl and grpcui ◦ https://github.com/fullstorydev
Questions? @yuriytuz
None