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
77
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
32
Other Decks in Programming
See All in Programming
코틀린으로 멀티플랫폼 만들기
pangmoo
0
120
Designing for tomorrow's programming workflows
honnibal
PRO
2
110
StoreKit2によるiOSのアプリ内課金のリニューアル
kangnux
0
100
コーンフレークから始める モデリング会話入門
ogurotakayuki
0
280
スクラムガイドのスプリントレトロスペクティブを改めて読みかえしてみた / Re-reading the Sprint Retrospective Section in the Scrum Guide
mackey0225
3
330
エンターテイメント業界で利用されるAWS
demuyan
0
200
CircleCIを活用して AWSへの継続的デリバリーを 実践する
coconala_engineer
1
230
try! Swift Tokyo 2024 参加報告 / try! Swift Tokyo 2024 Report
hironytic
0
170
両面どころかインフラもTSでできるよ ~ 全方位TypeScriptによるプロダクト開発 ~
myfinder
9
3.2k
Elm 0.19.0 Changes
bkuhlmann
0
480
[技育CAMPアカデミア]アイディアを形に!【超入門】スマホアプリ開発〜リリースまでの流れをご紹介
teamlab
PRO
0
350
CQRS/ES avec Symfony, c’est (trop) bien !
jeremyfreeagent
1
630
Featured
See All Featured
The Brand Is Dead. Long Live the Brand.
mthomps
48
28k
How STYLIGHT went responsive
nonsquared
92
4.8k
A designer walks into a library…
pauljervisheath
199
23k
The Cult of Friendly URLs
andyhume
74
5.7k
Fashionably flexible responsive web design (full day workshop)
malarkey
397
65k
Designing with Data
zakiwarfel
95
4.8k
Building a Modern Day E-commerce SEO Strategy
aleyda
16
6.4k
Product Roadmaps are Hard
iamctodd
43
9.7k
Navigating Team Friction
lara
177
13k
Designing the Hi-DPI Web
ddemaree
276
33k
Intergalactic Javascript Robots from Outer Space
tanoku
266
26k
Automating Front-end Workflow
addyosmani
1355
200k
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