gRPC Explained: Next-Level API Communication

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
traditional communication between multiple Services relies on HTTP based rest protocol which uses bulky and verbose data formats like Json or XML this results in excessive bandwidth consumption and high latency this is not suitable in highly distributed microservices architecture microservices need fast and reliable communication and to fix this Google came with framework called as grpc today we will write two services in node and Python and Implement grpc based client and server to see implementation and working demo stay tuned till the end of the video instead of relying on text-based formats grpc uses a highly efficient binary protocol called protocol buffers this means smaller payloads and faster communication reducing bandwidth usage and latency significantly grp PC uses http2 protocol this allows us to send multiple requests concurrently over single connection this is called as multiplexing let's see how to write Proto file we are going to write a calculator service having two remote procedure calls add and multiply let's create file to Define Proto buff for calculator let's define service service is like defining controller with bunch of RPC calls let's define add endpoint which accepts numbers message as a input and returns result message as a output let's define one more endpoint with name multiply and it again takes numbers message as a input and returns result message as a output remember these both messages are strongly typed so we have to Define these messages in protuff file let's define numbers message numbers message has two inputs of type in 32 and each one has field number one and two respectively field numbers help to identify field inside encoded message let's define second message result it has only one field called value of type int 32 this is our final calculator Proto buff file in some strongly typed languages like Python and Java these protuff needs to be compiled and converted into language specific structures like class but but in weekly typed languages like JavaScript this is not necessary today we will see both approaches where on server side we will use JavaScript and for client python let's create new node AIDS project using npm init here we will keep all details as a default next we will install grpc packages using npm we will need three packages in this case let's create new index.js file and write our G grpc server let's import grpc and grpc protol loader in our newly created file next we will load our calculator Proto file and load package definition into grpc object next we will fetch calculator Proto from grpc object now our Proto buff is ready to use remember due to JavaScript being weekly typed we don't have to do protuff compilation here now we need two server side functions to perform add and multiply operation let's define first function add it takes two parameter call and call back call will consist of request information and call back will help us to send result back to client multiply function will be exact copy of add function except change in operation let's define main function we will declare one address and create grpc server let's register our calculator service and function with this grpc server here we will bind Port of Local Host with server and finally start our server that's it let's call main function by default if we now run our index.js file grpc server is ready to serve incoming requests let's write our grpc client in Python remember python is strongly typed language and because of same hour protuff needs to be compiled I have already downloaded python grpc compiler let's compile our calculator. prototo file and it will generate two python files for our Proto buff file we need to create app.py file to write our grpc client here we will import grpc and newly created two files inside main method we will specify address and create grpc channel next we will load stub for calculating addition and multiplication we need to read two numbers from user using these numbers we will create numbers message which we will pass to add and multiply methods and finally we print response on Terminal our server is already running let's run our client and specify two numbers we can see Server responded with results so that's all about grpc if you don't subscribe then maybe you will never meet us again so if you liked this video then give thumbs and subscribe thank you
Info
Channel: Dispatch
Views: 6,495
Rating: undefined out of 5
Keywords: gRPC, Protocol Buffers, RPC Framework, API Communication, Remote Procedure Calls, Protobufs, High-Performance APIs, API Development, Efficient APIs, Scalable APIs, Software Development, Distributed Systems, Microservices, Backend Development, Programming, Technology
Id: 2KIFNdpiwT4
Channel Id: undefined
Length: 5min 33sec (333 seconds)
Published: Sun Dec 31 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.