Teach your (micro)services speak Protocol Buffers with gRPC.

Video in TIB AV-Portal: Teach your (micro)services speak Protocol Buffers with gRPC.

Formal Metadata

Teach your (micro)services speak Protocol Buffers with gRPC.
Title of Series
CC Attribution - NonCommercial - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this license.
Release Date

Content Metadata

Subject Area
Teach your (micro)services speak Protocol Buffers with gRPC. [EuroPython 2017 - Talk - 2017-07-12 - PythonAnywhere Room] [Rimini, Italy] When it comes to microservices, there're a lot of things worth keeping in mind. Designing such fine-grained, loosely-coupled services requires paying lots of attention to various patterns and approaches to make them future-proof. A very important thing to consider, is the way those services will communicate with each-other in production. Usually the communication is done over the network using a technology-agnostic protocol. At the next level the service should provide an API for its friend services. Then, the data should be serialized without altering its meaning and transferred to the picked endpoint. Nowadays, exposing a REST API that operates with JSON over plain HTTP is a usual way to lay the grounds of communication for the services. It is easy to accomplish, but it has some drawbacks. First of all, JSON is a human readable format, and it’s not as other serialization approaches. Also, with JSON it’s not possible to natively enforce the schema, and evolving the API may be painful. This talk’s purpose is to describe in deep detail the benefits of protocol buffers, that offer us for free an easy way to define the API messages in the proto format, and then reuse them inside different services, without even being locked to use the same programming language for them. Moreover, with gRPC we can define the API’s endpoints easily in the same proto format. All these offer us a robust schema enforcement, compact binary serialization, and easy backward compatibility
Intel View (database) Real number Multiplication sign Host Identity Protocol Formal language Web service Different (Kate Ryan album) Term (mathematics) Buffer solution Object (grammar) String (computer science) Software Representation (politics) Communications protocol Message passing Injektivität Demon Coma Berenices Bit Interprozesskommunikation Message passing Process (computing) Personal digital assistant Web service Buffer solution Right angle Object (grammar) Communications protocol Computer worm
Programming language Arithmetic mean Content (media) Data structure Formal language
Implementation Multiplication Software developer Boilerplate (text) Numbering scheme Instance (computer science) Client (computing) Cartesian coordinate system Formal language Mechanism design Message passing Exterior algebra Different (Kate Ryan album) Buffer solution Buffer solution Computing platform Energy level Object (grammar) Communications protocol Typprüfung Data type
Slide rule Software developer Interface (computing) Content (media) Formal language Formal language Mechanism design Data model Message passing Term (mathematics) Buffer solution String (computer science) Buffer solution Computing platform Communications protocol Message passing Family
Trail Identifiability Electronic mailing list Binary file Field (computer science) Number Type theory Message passing Personal digital assistant Buffer solution String (computer science) String (computer science) Integer Codierung <Programmierung> Communications protocol Message passing
File format Civil engineering Forcing (mathematics) Boilerplate (text) File format Line (geometry) Binary file Field (computer science) Symbol table Compiler Formal language Type theory Latent heat Message passing Process (computing) Buffer solution String (computer science) Buffer solution Energy level Codierung <Programmierung> Communications protocol Message passing Error message
Enterprise architecture Mobile app Real number Client (computing) Perspective (visual) Field (computer science) Formal language Different (Kate Ryan album) Buffer solution Buffer solution Revision control Cuboid Communications protocol Communications protocol
Message passing Befehlsprozessor Semiconductor memory Code Buffer solution String (computer science) View (database) Ideal (ethics) Communications protocol Message passing Spacetime
Web service String (computer science) Projective plane Energy level Parameter (computer programming) Message passing
Parsing Web service Message passing Host Identity Protocol Interprozesskommunikation
Email Addition Dependent and independent variables Email Dependent and independent variables Codierung <Programmierung> Bit Parameter (computer programming) Control flow Content (media) Mereology Zugriffskontrolle Cache (computing) Computer worm Data type
Email Overhead (computing) Dependent and independent variables Average Forcing (mathematics) Cuboid Speech synthesis Data compression Information security
Object (grammar) Object (grammar) Evolute
Context awareness Uniform resource locator Software Term (mathematics) Object (grammar) Universe (mathematics) 1 (number) Cuboid Object (grammar) Perspective (visual) Local ring
Software Different (Kate Ryan album) Object (grammar) Order (biology) Right angle Object (grammar) Procedural programming System call Local ring 10 (number)
Topology System administrator System administrator Computer network Infinity Neuroinformatik Band matrix Mathematics Software Band matrix Network topology Authorization Information security
Topology Server (computing) Open source Physical law System administrator Computer network Client (computing) Infinity Mathematics Band matrix Software framework Musical ensemble Remote procedure call
Building Message passing Web service Web service Object (grammar) Software framework Remote procedure call Message passing Connected space Physical system
Web service Message passing Logic Web service Object (grammar) Software developer Object (grammar) Function (mathematics) Message passing Computing platform
Axiom of choice Web service Message passing Befehlsprozessor Identifiability Semiconductor memory Different (Kate Ryan album) Java applet Electronic mailing list Client (computing) Limit (category theory) Mereology
Point (geometry) Web service Java applet Java applet Android (robot) Client (computing) Diagram Client (computing) Mereology Formal language
Multiplication Dependent and independent variables Electric generator Computer file Web service Message passing Uniform resource locator Term (mathematics) Web service Buffer solution Router (computing) Message passing Family
Message passing Latent heat Computer file Network topology Code Server (computing) Computer file Code Directory service Compiler
Context awareness Context awareness Dependent and independent variables Server (computing) Multiplication sign Java applet Android (robot) Code Client (computing) Parameter (computer programming) Web service Latent heat Message passing Web service Implementation Social class
Context awareness Web service Implementation Server (computing) Web service Server (computing) Network socket Code Implementation Metadata
Dependent and independent variables Server (computing) Multiplication sign Code Client (computing) Client (computing) System call Web service Message passing Network socket Buffer solution Object (grammar) Communications protocol
Web service Code Client (computing) Quicksort Endliche Modelltheorie System call Resultant
Dependent and independent variables Computer file Dependent and independent variables Correspondence (mathematics) Field (computer science) Subject indexing Message passing Latent heat Personal digital assistant Web service Representation (politics) Right angle Family Routing Resultant
Web service Dependent and independent variables Message passing Divisor Dependent and independent variables Web service Multiplication sign Streaming media Streaming media
Web service Uniform resource locator Web service Client (computing) Streaming media
Dependent and independent variables Implementation Dependent and independent variables Web service Streaming media Bit Streaming media Wave packet
Dependent and independent variables Weight Multiplication sign Chain System call
Group action Multiplication sign Chain System call Row (database)
Expected value Web service Response time (technology) Different (Kate Ryan album) Term (mathematics) System call
Dependent and independent variables Process (computing) Multiplication sign Chain Adaptive behavior 1 (number) System call
Multiplication sign System call
Point (geometry) Dependent and independent variables Context awareness Multiplication sign Client (computing) Line (geometry) Instance (computer science) System call Timestamp Wave Goodness of fit Natural number Absolute value Absolute value Resultant Form (programming)
Multiplication sign Content (media) Summierbarkeit Line (geometry) System call Thresholding (image processing) Timestamp Absolute value
Point (geometry) Ocean current Dependent and independent variables Multiplication sign Bit Line (geometry) Client (computing) Timestamp Lattice (order) Entire function Chain Resultant Exception handling
Point (geometry) Server (computing) Server (computing) Client (computing) Remote procedure call Client (computing)
Gateway (telecommunications) Point (geometry) State of matter Server (computing) Java applet Android (robot) Client (computing) Database Representational state transfer Instance (computer science) Streaming media Formal language Formal language Mathematics Web service Process (computing)
Android (robot) Dialect Java applet Java applet Android (robot) Demoscene Personal computer Process (computing) IRIS-T Googol Computing platform Speech synthesis Computing platform Window
Observational study Software Multiplication sign Square number Software framework Open set Instance (computer science) Interprozesskommunikation Square number
Logic Design by contract Design by contract Energy level Focus (optics)
Point (geometry) Web service Web service Operator (mathematics) Mobile Web Moment (mathematics) Design by contract Cuboid Focus (optics) Formal language Product (business)
lower about and and welcome to our journey on the land of micro-services I will have an opinionated sulk about different ways of communication between services these days
of given introduction to political buffers and inject BC by covering the main concepts as
mentioned they'll generally talk about things needed for the communication process between micro-services that will include a message sterilization this realization of the message transport over the wire of course the wide diversity of Europe services in terms of ecological stack they're running gone from the right of languages to the right of blood from the should should support in a real world use case I you'll have some services that communicate with each other in this case service 80 relies separately on B C and D a however things could look like that of the essential difference is that there are more interdependencies between those services that are not exposed to the user denoted by the note uh at the same time the all day the user should not even care much about those dependencies in natural simplifying the view there is usually clear client-server communication over the communication can be done over a city B and the messages could be sterilized to adjacent strings I also the communication could go over some proprietary protocol and instead of sterilized objects in the payload on you'll have references to the actual remote objects will come back to that 1 bit later we are now considering Jason for object representation was take a brief look to its advantages and disadvantages so 1st of
all human readable so it's easy to perceive and debug but it's also schema-less so you have the liberty to form your Jason in anyway there's nothing being forced it to follow some of structure whatsoever and i its language agnostic is all this realizes and hospitalizes so available in mainly all the programming languages are speaking of
disadvantages of 1st of all it's human readable and it dust herself is that the benefit well not really human means that it's not to compare those seats more consuming convinced of size also it's schema-less so you of you thus herself again argues that the benefit as well well actually not as you always have to map the contents
of your adjacent to meaningful objects not only doing more work but also introduce things lots of repetitive boilerplate called for instance when you have multiple clients consuming the same endpoint In fact you implement in artificial scheme of the application level whereas it could be done and it should be done with it 1 a lower level but also there is an old type-safety whatsoever within the message i which could lead to serious problems when interpreting a valley in different ways of 4 different implementations as an alternative to
Jason we could consider practicable offers a prodigal buffers are Google language a
neutral platform-neutral extensible MacKinnon's personalizing structured data thinking similar but smaller faster and simpler so the Fisher LDA commendation island at the we small
correction thing Jason but smaller faster and simpler that I may refer to prodigal buffers later using terms like broad term for the messages of brother lost are the Interface Definition Language looks like the entire content from this slide defines a message
so it's called person and is denoted by the message keyword I'd has 3 fields are the first 1 is called name and it's the type string are the 2nd 1 is an integer uh and the 3rd 1 is a repeated field there be the field is essentially a list of items would at an all-time I take a closer look to the numbers in each field of that's the field identifier you its use for binary encoding and decoding is very important to keep in mind that these identifiers
should be unique and you should not be reused in case the deprecation of some field to help you that I to to to keep track that the potato fields others a reserved keyword but to denote fields that are prohibited to be reused you by
any chance you'll try to reuse on of the reserve fields the proto C compiler will give you a specific error In general lines that's the entire theory behind
tropical buffers let's see some of the benefits so 1st of all other binary encoded so this means that there very complex and the encoding and decoding process is very fast messages are can be also sterilized adjacent 3 4 other formats if needed of the schema using force from the ideal level up and the messages are strongly typed which is definitely benefit over volatile and type messages of moreover him being the symbol wait a single way to define messages in messages you save lots of boilerplate called for civilization this realization but it is also language its
role as it has official support in 10 different languages and of course Jason could be even better than and it gives us some out of the box backward compatibility features on avoiding this kind of cold but in real world you
have wires clients and you won't be able to guarantee that all of them are running the freshest app with Protocol buffers it's easy to add new fields of deprecates in existing fields or even intervals and is generally faster or from the enterprise perspective on small are
sees consume less space and the transmitted faster also the memory and CPU usage R is smaller because less data is red and processed while encoding or decoding it brought about yeah the no this
is it an ideal message innovation and it's similar to the example that was shown earlier armed From these ideals of the generated cold it's rather simple to create new objects like that Our sorry this is just the generated called you the generated code provides a view a builder of ancestors gets worse and so on
however in Python the you thinks looks pretty much similar and a given more elegant see you can I use the keyword arguments construct the superstructure projects I know that you have the rudimentary understanding of all the data that's generated and consumed by the
services was taken of of above level it's taken briefly to the way these
messages are exchanged between services on the rest foolish
API usually entities have some distinct your eyes are you a fire and HTTP request to them you get some plaintext encoded data and of you pass it the whatever's needed but this is foundation to be 1 that 1 request looks like I
ascended bunch of plaintext headers to the 2nd and this is just a small amount of them usually so as litigation with additional headers and perhaps a bit of some other parameters the on the response
we start with a bunch of feathers again but this is just a small part of them not
surprisingly some Pentagon receive a big amount of feathers and amount of the payload itself and this is your actual response failed of with to be too you could get
some performance improvements out of the box are the request become cheaper as the average request overhead is reduced with multiplexing header compression of stock also even though it's to be 2 doesn't force you to use TLS is encouraged to
be the only correct way of doing things in a speech also you'll gain some extra security features I won't go any further and into tails are as it's not in the scope of this so
bottom for interesting to learn more about this should be 2 and grasp of the entire ACP to evolution as definitely recommend watching an anabolic stuck on this to be shoestring performance is a great so covering lots of technical aspects I
mentioned earlier the distributed objects
so let's get back to them for a while in the late nineties and further the concept of distributed objects became more and more popular if you're it looks very nice you do with some
object in a don't care much whether their local or accessory network are the
concept of location transparency implies that the remote objects have the same look and feel as local ones from my own perspective the term should be rather called a box is your universe awareness is really limited but with this in mind like to cold Martin follower so the 1st full distributed objects used do not distribute
objects 1st of all we should acknowledge the fact that there is a huge difference between calling some procedure locally and going somewhere remotely in being so the
most obvious difference to be delayed as as a simple local call AUC could take something like a few nanoseconds to produce it's also good for a simple metaphor call is expected to be tremendous work in orders of tens or even hundreds of milliseconds the difference would be the network reliability and that recall may and will fail eventually whereas a local call will always succeed so hiring these facts from the user in a transparent objects is not the right the ideal thing that we could to yeah also
in the early nineties him with the forces of
distributed computing was established by the engineers at Sun Microsystems and there are the following that the network is reliable the latencies 0 the bandwidth is infinite then authority Secure topology doesn't change there's 1 administrator transport goes to 0 and the network is homogeneous even though the never
gets faster the band with wider and so on it looks like being tireless is still accurate as to actual and this is not gonna change in the near future so let's keep in mind Mahfouz law which says that if something could go wrong it will go wrong eventually so do not ignore any of the possibilities and be always prepared to handle them no juror
perceive our is an open-source Remote Procedure Call framework that can run anywhere it enables the client and server applications to communicate transparently and makes it easier to
build connected systems GER perceive promises us to solve the issues that I mentioned before larger season uh of the recursive acronym it stands for a juror pursue remote procedure call i is melt mainly developed by Google as the rework of internal framework cost of it the and the 1st
principle of Japanese cities to camp services and messages instead of references to
the remote distributed objects the message is a start the container uh with diet data in that respect schema and it's pretty much all of it messages don't have any behavior whatsoever the service itself has all of its business logic inside so you give it an input and expect the static output from it In this sense
it's pretty similar with the bill of RESTful services with some extra features like streaming must look let's give it for now another important principle is that the stack should be available on every popular development platform and should be easy for someone to someone to build the on the platform of
choice should be viable as well on the devices with limited CPU and memory and for the full list of the major PC principles you can follow linked article a service and your
PC looks pretty much similar to RESTful service it has some end points and you can pass messages over them the only difference is that the entity identifier is not the part of the end point in its use as
it's usually in other approaches like the rest and in the diagram the service is implemented in C + + clients in Ruby and Java and that's
of who just an example as any part can be implemented in any of the supported languages journalism design a service
that will provide Roberts between 2 specified points 1st of all we need a
service and our services cold rolled planner a service can have multiple copies standpoints and in this case of hazardous 1 it's called get
of the get shots but endpoint takes a
get throats request message and 2 terms in gets out response message now this is a broader definition of the service should be kept brother files just like any other political buffer messages the the their request and response messages are defined just like any other for the messages and the location and router or some user-defined messages to generate Python cold off from Protocol Buffers
definition only need to do is to run the proto compiler it can be done through Brighton as well we specify the proto path on the would benefit generated messages and dealt with that for dead generated Jervis's specific code and finally the path to or from the file yeah
and this will result in 2 files the 1st 1 holds the brought messages specific gold and the 2nd 1 did Europe is the specific functional as we already have the generated code
from the Protoss dive into implementing the service using Python this time the on
so this is basically our entire service on this class implements the wrote when the servicer
that was generated by proto C and each
method are from this class implements a specific RPC endpoint it gives the request and the context as parameters it returns the response message of the contexts called a
RPC metadata like deadlines cancelations and so on I will get to this 1 in this lecture on to actually make use of our
implementation we create a major persist over entity with the ThreadPoolExecutor are the actual implementation has to be bound to the server and then we specify the socket for service and started
and that's basically it so as we already have a service someplace let's try to implement the our clients in Python this time on to
access the service the client must create a channel on to the listening socket and then create a stop from the generated code and form the request message I'm busy for many other Protocol Buffers met object from the generated gold I you'll get the request from that in a blocking manner there is also the possibility to make a synchronous calls 2 1 calling the service it could be done like that in
in a synchronous call on you will get some sort of a future might not form of by the 3 feature which from which you could get synchronously the result has some callback check if is on and so on I the
Fisher's model was backported to Python 2 as well if for any reason still have to use Python to have also you can play with your
service using that Europe command line tool party is it you just have to you should the juror pursued still I call on to Europe so
that and after that the right the of RPC endpoint name and then goes your request brought up this just the here documentation are you can also start a brother request message index files and provide those to the CLI tool if needed yeah as a result from the juror pieces
so I call will get the text representation of your response i in this case is a repeated field called routs with their corresponding data on let's get back to our wrote planner servants and imagine a specific use case what is depending
on the time and some external factors the service once to all of you to to get to rewrite the dishonest some neurons become available all this
is now this is possible to be done with streaming are in proto definition you just
have to add the streaming the stream keywords of before your response message and implemented accordingly but also let's say that
our client is existing RAK from a mobile phone while traveling around the city and his coordinates constantly change it'd be nice after
some out there strolled to stream this due to the service you're new location so the answer could be recalculated
as well well this is as well possible to be done with our the stream would the
streaming I don't have separately the response training and their request remains 1 of the
walls of course we could have more of
are we just have to add that was this
stream keyword for both of the request and response and voyages
have you have implemented and enforced of want go into the implementation details as it's bit of the scope of this talk but they hold that they managed to give it a few of those features we
all know that you know the basics of the RBC definition on let's try to go into some more sophisticated features of Jefferson and let's keep in mind that thinks will go wrong and we
should be very well prepared for that I when
shooting a request is not for the weight of an definitely for a response but there should be always the time onset but how do we determine the was the proper time out for different calls in the chain let's try different approaches we could put
in a uniform time out on all the subsequent calls let's see even action
so all we have said these 500 ms time out on all of the rows subsequent calls for live for a week in our chain and the 1st 3 calls go pretty well so but there is still some time remaining for or from any of those timeouts but note the for some reason is quite slow so by the time it responds declined his that time out and fails accordingly None of the nodes are really aware of that so they're are continuing to do the always that already on useless work until there on time
all get excited and that's obviously not the best approach In reality for different
services we have different expectations in terms of their
response times and that means that we can have custom also just like that again for the 1st 3 calls everything looks good so far but when the node
b response it violates the time allowed by a very small amount of time so the corresponding node fails we could have done a better job was probably the entire chain would've succeeded and would have taken less than those initial 300 ms let's try to adopt some other time on and adaptive out what sounds like a better option and adaptive in the sense of Cusco think
of the time out from the 1st call to the all the subsequent ones so astride the
previous example but in this way so the initial out would be 200
ms and the 1st call it takes 20 milliseconds that means that the next time out would be 100 80 ms the next 1 takes 3 countries you 30 ms and so the subsequent call uh would have a time out of 150 ms
the note have all the time out said nature our from the initial 1 the
response wave goals well on the client is
happy with its result this looks looks like a good approach but it's rather difficult to operate with timeouts
are the same old is a relative relative a delta from a specific point on the deadline would mean an absolute value say a timestamp milliseconds the a GeForce he operates with lines cover there so the specified by the user in the form of a timeout is computed internal on the deadline is propagated automatically with and you're perceived to all the subsequent calls uh and you can you can access the deadline our at any point move from the context the country that I mentioned before our for instance you we should do some have a lifting
before making another RPC call and you want me to issue whether the that line is within some the normal threshold but you do you were it makes another issue to be call and it 1 to manually propagated that line there it's rather simple yeah as you could simply get it from the contents How listen example deadlines and for simplicity was use a fictive starting timestamp in
milliseconds a time of that would be say 200 and the that line would be the sum of those 2 because of that line art is an absolute value on all into today's tissue at each step of the current timestamp is smaller than that that line so
we just go and at any step we just compare the current timestamp and that line and if it's the content smaller than we just proceed and the entire request response chain goes well and at the end the last time timestamp is still small and that line so the client is have to its result no what's in example 1 that line gets succeeded at some point I would have the exact same
set up was in previous example but probably a bit slower never so by the time the request gets to denote a the deadline get succeeded the aided exceeded exception is propagated back to the client that OK on we failed
Intel didn't I recall uh at an
early point so the node B was never touched this is obviously a good thing to do but in the same way the deadline exceeded was propagated back to the client
on a manual cancelation could be
propagated hidden the cancelation can be initiated by both the client and server are you the immediately terminates democracy and all the subsequent of obstacles that are that are pending and keep in mind that it's not
the all soul if you need for some reason to all you need she did some changes some choose the database for to some state are you should keep in mind to do their role but by ourselves and it's
automatically as mentioned before yeah
when migrating our for
instance adjacent RESTful API service to GR perceived a backward compatibility where can be assured temporarily with that Europe is the gateway this will translate that your PC and points to a RESTful API but keep in mind it won't work with streams and other nifty features of your PC the juror perceive has a tremendous language support with C + + Python job
goal Ruby to shop GS Android Java Objective-C Ph.D. and it also supports most of the EU's platforms like Linux Windows 100 Iris speaking of success stories
have like to mention Google as is there were regional creator of jobs scene and yeah PC's volition of
study the googly on internal RPC framework which is widely used there for quite a long time also the adoption of
jerks external is evolving rather fast companies like care square Netflix Corylus Siskel carbon 3 the Juniper Networks and other so using it extensively alright for instance docker containers the implements a Europe this here API and they're swarm communication between nodes is done in On pursue holiday another is interesting example is Juniper Networks lead the most the software defined networks and they implement their as dn open coffee on top of Jefferson's thus summing GOP would
solve lined the benefits of
Jervis PCM Protocol Buffers 1st of all you focus on the design of your
API and you establish a strong contract with her clients and if have this schema defined in 1 place at a different level than your business logic also to use of something is supported by major
PC out of the box you have the bi-directional streaming for freeing and you have the freedom to speak any suitable language for in a specific service and have the freedom to change your of specific service at any point the use services services service to mobile friendly and even more importantly is production red so just you define all
thanks for operations I believe I won't take any questions at the moment but we can catch me at any point later and I'll be happy to discuss discuss anything which is and as they believed alleges only serve you