$30 off During Our Annual Pro Sale. View Details »
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
80
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
50
Other Decks in Programming
See All in Programming
FluorTracer / RayTracingCamp11
kugimasa
0
180
connect-python: convenient protobuf RPC for Python
anuraaga
0
350
dnx で実行できるコマンド、作ってみました
tomohisa
0
130
【CA.ai #3】Google ADKを活用したAI Agent開発と運用知見
harappa80
0
240
Why Kotlin? 電子カルテを Kotlin で開発する理由 / Why Kotlin? at Henry
agatan
2
6.1k
スタートアップを支える技術戦略と組織づくり
pospome
8
15k
ID管理機能開発の裏側 高速にSaaS連携を実現したチームのAI活用編
atzzcokek
0
180
【Streamlit x Snowflake】データ基盤からアプリ開発・AI活用まで、すべてをSnowflake内で実現
ayumu_yamaguchi
1
110
Google Antigravity and Vibe Coding: Agentic Development Guide
mickey_kubo
2
130
[堅牢.py #1] テストを書かない研究者に送る、最初にテストを書く実験コード入門 / Let's start your ML project by writing tests
shunk031
11
6.7k
Microservices Platforms: When Team Topologies Meets Microservices Patterns
cer
PRO
1
900
【レイトレ合宿11】kagayaki_v4
runningoutrate
0
220
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
463
34k
It's Worth the Effort
3n
187
29k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.8k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Six Lessons from altMBA
skipperchong
29
4.1k
Building Adaptive Systems
keathley
44
2.9k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
What's in a price? How to price your products and services
michaelherold
246
12k
GitHub's CSS Performance
jonrohan
1032
470k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
196
69k
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