Przemek Nowakowski: Podejście mikroserwisowe w naszym projekcie, oprócz oczywistych zalet, potrafi wygenerować też szereg problemów – między innymi z komunikacją pomiędzy poszczególnymi serwisami. W prezentacji omówimy od podstaw framework gRPC, dzięki któremu będziemy w stanie w szybki i przyjemny sposób połączyć nasze serwisy. Sprawdzimy też, do czego się nadaje, do czego nie oraz prześledzimy podstawowe problemy, jakie możemy napotkać przy takim podejściu. Nie obejdzie się również bez porównania z obecnymi na rynku alternatywami i sprawdzenia, co z tą obiecywaną wysoką wydajnością.
10. POWER UP SERVICES WITH GRPC
AGENDA
▸ How can we communicate our services currently?
▸ Protocol buffers
▸ Power up! GRPC explained
▸ Problems that might appear
▸ The summary - use cases, alternatives
11. POWER UP SERVICES WITH GRPC
WHOAMI?
Przemek Nowakowski @ TSH
fb.com/abuse.abuse
przemyslaw.nowakowski@thesoftwarehouse.pl
github.com/lapisangularis
keybase.io/lapisangularis
18. HOW WE CAN COMMUNICATE OUR SERVICES CURRENTLY?
REST IS GREAT!
▸ Easy to understand
▸ Built on top of HTTP
▸ Easy debugging, with many tools to inspection and modification
▸ Server and Client are not much dependent on each other
▸ Popular amongst community
19. HOW WE CAN COMMUNICATE OUR SERVICES CURRENTLY?
BUT NOT ALWAYS…
▸ Streaming is difficult
▸ Bi-directional streaming is impossible
▸ Operations are difficult to model
▸ Hard to get many resources in one request
▸ Inefficient
21. PROTOCOL BUFFERS
PROTOBUF
▸ Binary data serialization interface
▸ Developed by Google
▸ Definition language (IDL)
▸ Multi-platform support (JavaScript, Go, Python, Java, C++, etc.)
23. PROTOCOL BUFFERS
THE BASICS OF PROTOBUF - STATIC CODE GENERATION
▸ Install the protocol buffers compiler
$ brew install protobuf —devel
▸ Install protobuf runtime library for node
$ npm install google-protobuf
24. PROTOCOL BUFFERS
THE BASICS OF PROTOBUF - DYNAMIC AND STATIC CODE GENERATION
▸ Install the JS implementation of protobuf with typescript support
$ npm install protobufjs
25. PROTOCOL BUFFERS
DEFINING MESSAGES
▸ Messages are defined
in .proto files
▸ There are defined separate
messages for each data
structure you want to serialize.
▸ Every field has a name and type
▸ user.proto
30. PROTOCOL BUFFERS
STATIC CODE GENERATION - COMMANDLINE TOOL
▸ Can be used to translate between file formats to generate static code as
well as TypeScript definitions.
$ pbjs -t static-module -w commonjs -o compiled.js file1.proto file2.proto
▸ Will generate static code with definitions of both proto files to a
CommonJS module
31. PROTOCOL BUFFERS
DYNAMIC OR STATIC?
▸ Dynamic is easy editable, no compile step, interoperable between
libraries, however there’s some parsing
▸ Static is hard to edit, no reflections, and there’s a compile step
▸ Not much difference in performance, with very small advantage for
static
32. PROTOCOL BUFFERS
SUMMARY
▸ Protobuf is just a serialization tool…
▸ … but with binary format it’s striking fast and lightweight
▸ It is great for using inside application, if strong-typed, fast and reliable
data exchange protocol is needed.
35. POWER UP! GRPC EXPLAINED
GRPC
▸ Remote procedure call system
▸ Developed by Google
▸ Uses HTTP/2 for transport, Protobuf as IDL
▸ You can call it a layer on top of Protobuf
▸ Manages a way client/server interacts
▸ Has support for authentication, streaming, flow control, etc.
▸ Multi-platform support (JavaScript, Go, Ruby, many others)
36. POWER UP! GRPC EXPLAINED
GRPC WORKFLOW
Define Compile1 2
messages protoc nodejs
go
???
Implement3
server
client
38. POWER UP! GRPC EXPLAINED
GRPC IMPLEMENTATIONS
▸ Three high performance implementations
▸ C
▸ Node.js, Ruby, Python, PHP, C family are bindings to C core
▸ PHP via PECL extension (nginx/php-fpm or apache)
▸ Java
▸ Go - pure implementation using Go stdlib crypto/tls package
39. POWER UP! GRPC EXPLAINED
A LITTLE BIT OF HISTORY
▸ Developed internally in Google in the beginning
▸ A successor of another internal Google project called „Stubby”
▸ Currently an open source project with many contributors, however still
mainly executed by Google
52. THE PROBLEMS…
THE PROBLEMS
▸ Load balancing
▸ Error handling is quite bad
▸ Breaking API changes
▸ Poor documentation for some languages
▸ No standardization across languages
▸ It’s not good for handling files
53. THE PROBLEMS…
HOW TO DEBUG GRPC?
▸ protoc-gen-lint - enforcing coding standards and catching basic errors
▸ grpcc - interact by CLI with gRPC server via its protobuf file. Good for
quick endpoint testing
▸ omgrpc - Postman for gRPC endpoints, with GUI
55. SUMMARY
WHAT ABOUT SOAP/WSDL?
▸ It’s completely attached to XML
▸ It lacks lightweight, pretty bad definition format
▸ Inflexible, with no forward compatibility
▸ Performance is bad and lacks of streaming…
▸ Clients were responsible for generating libraries
57. SUMMARY
OK, SO WHERE IS THE PRODUCTION USE?
▸ Square - one of the first contributors to grpc. Replacement for all their
internal RPC
▸ CoreOS - production API for etc v3 is grpc
▸ Google - production APIs for Google Cloud Services
▸ Netflix, YikYak, VSCO, Cockroach and many more
58. SUMMARY
AND THAT’S GRPC
▸ Possibly the best framework for microservices communication
▸ Bright future, community active
▸ Many companies start using gRPC in their projects