gRPC
Dharshana Ratnayake
Clearpoint
History of middleware
CORBA/RMI -> SOAP -> REST -> gRPC
REST
Application
Transport
Internet
Character
UUID id
Vector location
State state
UUID
Vector
x
y
z
State
ALIVE
DEAD
"characterRequest": {
"character": {
"id": "uuid",
"location": {
"x": 1234567890
"y": 1234567890
"z": 1234567890
}
"state": "ALIVE"
}
}
POST /index.html HTTP/1.1
Host: www.example.com
Content-Type
body{}
TCP
IP v4/v6
So what’s wrong with JSON over
HTTP
• Text not binary
• No multiplexing
• Needs something like swagger.
• GET, POST, DELETE, CREATE…. But what
else?
• Can see hacks appearing
REST vs gRPC
JSON
HTTP
Protocol Buffer
HTTP2
REST vs gRPC
"characterRequest": {
"character": {
"id": "13945de2-9743-4688-a88a-81002f311bc2",
"location": {
"x": 1234567890
"y": 1234567890
"z": 1234567890
}
"state": "ALIVE"
}
}
205 characters
205+bytes
1: {
1: {
1: "16 bytes",
2: {
1: 4 bytes
2: 4 bytes
3: 4 bytes
}
3: 1 byte
}
}
44+bytes
● What about 1000 messages per second
● Simpler parsing
● Better CPU utilisation
So, let’s write some code
Let’s look at some metrics
• Results of running against google compute
engine
• 3000ms vs 2700ms (post warm up)
• But wait.. We don’t have to play tennis
gRPC streaming example
Real world use case
● Naive approach 6 second lag
● UDP too much packet loss
● gRPC 150ms latancy
● Able to do server push
thanks
● http://www.grpc.io/
● https://github.com/darthShana
● Ray Tsang
● Able to do server push

gRPC