From REST To GRPC
From REST To GRPC
3
What is gRPC?
4
Why should we use gRPC?
5
Why is gRPC awesome?
Performance
6
Performance Benefits
HTTP / REST
7
Performance Benefits
9
Why is gRPC awesome?
Performance
10
Why is gRPC awesome?
Performance
Remote Procedure Calls
11
REST setup is tedious
headers = {}
headers.put(“X-FooBar-User”,
user.getFooBarID())
headers.put(“FooBarTransaction”,
app.getNextTxnIDAtomic())
headers.put(“FooBarAlgoType”,
ApproximateFoo.toHeaderString())
12
REST setup is tedious
@JsonProperty(name=”foo_id”)
String id;
@JsonProperty(name=”bar”)
int bar;
...
}
13
REST setup is tedious
request = FooService.RequestBuilder()
.setId(foo.getId())
.setBar(foo.getBar())...
.build();
response = fooClient.DoFooBar(request);
15
Why is gRPC Awesome?
Performance
Remote Procedure Calls
16
Why is gRPC Awesome?
Performance
Remote Procedure Calls
Strategic Direction of our Platform
17
18
<insert slick demo here>
19
Just one problem…
20
21
Business Constraints
22
The Transition Plan
23
DESIGN THE API
Phase I
24
Designing a gRPC API
REST: gRPC:
25
Designing a gRPC API
REST: gRPC:
REST: gRPC:
27
Designing a gRPC API
REST: gRPC:
28
Designing a gRPC API
REST: gRPC:
message Bar{
POST BarID id = 1;
/api/foo/{foo_id}/bar int baz = 2;
}
GET
/api/foo/{foo_id}/bar/ message BarID {
{bar_id} FooID foo_id = 1;
string bar_id = 2;
}
29
Designing a gRPC API
Bar service:
/api/foo/{foo_id}/bar/{bar_id}
Buzz service:
/api/foo/{foo_id}/buzz/{buzz_id}
30
SERVE REST AND GRPC
Phase II
31
Current: REST Only
REST
Caller
FooBar
Service
32
Future: REST and gRPC
REST gRPC
Caller Caller
FooBar
Service
33
We need to evolve our API without
damaging basic functionality.
34
Current: Layers View
Rest Service
Code Package
Business Logic Models
is allowed to
use Datastore Access
35
Future: Layers View
Rest gRPC
Service Service
Code Package
Business Logic Models
is allowed to
use Datastore Access
36
Layer Pattern Rocks!
37
Evolving the code went really well…
38
39
Things that suddenly became a problem
• Health Checks
• API Discovery
• No curl
• Headers?
• SSL?
• Simple community examples
40
TRANSITION FUNCTIONAL TESTS
Phase III
41
Specification by Example
42
Specification by Example- REST
43
Ruby metaprogramming
request = Object::const_get(
”FooBar::#{message_name}").decode_json(json)
response = client.method(method_name.to_sym)
.call(request)
44
Specification by Example- gRPC
45
200+ tests transitioned in 1 week
46
Why did this go so well?
47
REMOVE REST FUNCTIONALITY
Phase IV
48
rm –rf src/*rest*
49
We need to retain some REST endpoints
REST gRPC
Caller Caller
FooBar
Service
50
51
Current Layered Architecture
54
NOW WE’RE READY FOR
RELEASE…?
55
New problems we created
• Health Checks
• API Discovery
• No curl
• Headers?
• SSL?
56
New problems we created
• Health Checks
• API Discovery
• No curl
• Headers?
• SSL?
57
API Discovery
58
API Discovery
59
60
Tools support
• Basically Nonexistent
• Our solutions:
• Hand roll mocks for testing
• Write new functional tests each time we
wanted to use curl
61
Adios,
REST!
62
INTERESTING THINGS WE
LEARNED
63
• The right kinds of abstractions promote
extensibility
• Focus on the domain model
• Create a specification by example
• Take care when choosing frameworks
• Deal with risks of technology adoption
64
Would we do it again?
65
Would we do it again?
Yes.
• Super easy to integrate with a service
• Promotes small polyglot services
• Difficult to do bad things
• Performance is 🔥 🔥 🔥
66
Thank you!
Michael Keeling Joe Runde
@michaelkeeling @joerunde
neverletdown.net
68
69
70
71
72