Learning Library

← Back to Library

Video hVrwuMnCtok

Full Transcript

# Video hVrwuMnCtok **Source:** [https://www.youtube.com/watch?v=hVrwuMnCtok](https://www.youtube.com/watch?v=hVrwuMnCtok) **Duration:** 00:07:17 ## Sections - [00:00:00](https://www.youtube.com/watch?v=hVrwuMnCtok&t=0s) **Untitled Section** - ## Full Transcript
0:00hey everyone my name is brian trong and 0:01today we're going to be talking about 0:03grpc 0:05so grpc is a modern communication 0:09framework that was introduced in 2015 0:11and is governed by the cloud native 0:13computing foundation and today i'm just 0:15going to introduce the concept with a 0:17simple example and hopefully that will 0:19outline some of the benefits that i 0:20could bring to your application 0:22so let's say we have an application and 0:26we have a front end and i'm going to 0:28signify this with a little 0:30computer monitor 0:32and 0:34the majority of the talk today will be 0:35about the back end layer so let's say in 0:38our example we have a back-end micro 0:40services layer 0:41of 0:43python 0:45so let's say python handles something 0:46like analytics it doesn't really matter 0:48but python is one microservice 0:50and let's say 0:51we have another in java 0:54and one in golang for example 0:58and what i'm going to do is i'm going to 1:00go ahead and draw arrows between them to 1:02signify that these microservices 1:04need to 1:05connect and communicate with each other 1:08i do want to stop here and point out 1:10that i i'm specifically talking about 1:12communication between microservices and 1:15i'm not talking about communication 1:18between the front and the back end 1:20because 1:21communication uses communication via 1:23grpc 1:25does not natively work out of the box 1:27with 1:28web browsers so 1:30in particular grpc is more oriented for 1:33this type of communication 1:36so the first talking point that i want 1:38to mention with grpc is that it brings 1:40about 1:42significant improvements in convenience 1:44and scalability 1:46so i'll just write convenience here 1:49and 1:50if we weren't if we were to not use grpc 1:53it would be important to note that 1:54python has its own http client libraries 1:57java has its own golang has its own and 2:00these are client libraries that are 2:02supported by different groups 2:05and if we were to extend them it would 2:07be different individuals that are 2:09working to maintain these client 2:10libraries and it could get out of hand 2:12especially as we add 2:15more 2:15microservices that could be of different 2:17runtimes in different languages 2:19now grpc 2:21handles all the 2:23implementation to the http protocol for 2:25us so as a developer we don't have to 2:27worry about that level of detail since 2:31grpc implements the connections with ht 2:352.0 for us so that's something that we 2:37don't have to worry about moving forward 2:40now 2:41on top of that 2:42hand-in-hand with convenience is grpc 2:45offers code generation now you're 2:47probably wondering how does code 2:49generation work how does it know what 2:51code to generate and what not and the 2:53answer lies in protocol buffers 3:00and if you're not familiar with protocol 3:02buffers you can essentially think of 3:04them as 3:05a form of a contract for communication 3:08so traditionally with an api 3:11you don't necessarily have a 3:14api contract that is defined by the 3:17protocol itself so if we're using rest 3:18for example you're just sending json 3:21messages you know with key value pairs 3:23that aren't checked until you get to the 3:26receiving end and that's where it 3:27handles it but with these protocol 3:29buffers 3:30in 3:30the profile which is where you define 3:33the 3:34what is essentially a schema for the 3:35data that is being sent you can define 3:37things like the 3:40fields that you expect 3:42which fields are required which fields 3:43are optional as well as the object types 3:46for these fields 3:48on top of that 3:49in the protofile for the protocol buffer 3:52you also define the procedures that you 3:55expect to expose and these are 3:57essentially defining 3:59which procedures so rpcs standing for 4:02remote procedure calls 4:04you're essentially defining which 4:05procedures are callable remotely from 4:08other microservices 4:10and what happens is if you want to have 4:12the code generated you run the protofile 4:15against a compiler 4:17and what is output is 4:19source code in 4:21your respective language 4:24so for example if this was java and you 4:27defined 4:28in your protofile that you are expecting 4:31messages to have 4:33three fields of 4:35type in string etc 4:39what is output is essentially an 4:41interface that allows you to create 4:44these cloud that creates the classes for 4:46you 4:47that implements the object types that 4:49you outline in your protofile 4:52now the next point i want to talk about 4:54is 4:55performance 4:58and we already touched 4:59a bit about performance 5:01with http 2.0 being 5:04a much more modern protocol than http 5:061.1 that already delivers a significant 5:09number of improvements 5:11but performance is further 5:14delivered with protocol buffers as 5:16protocol buffers are serialized and sent 5:19as binaries 5:21across the wire 5:22so if you're familiar with json which i 5:25think is the de facto message type that 5:28is sent via rest api these days 5:31you're probably well aware that json 5:34messages are 5:35not 5:36compressed or flat by any means 5:39considering that they are key value 5:40pairs that 5:41certainly are not the most space 5:43efficient 5:44with these protocol buffer buffers these 5:47messages are sent as binaries which are 5:49significantly significantly smaller than 5:52the normal json message 5:54of course that begs the question what 5:56about 5:56using something like gzip to compress 5:59the json message before transmission and 6:02that kind of brings us back to 6:03convenience in that if we were to use 6:05something like gzip or tool to compress 6:08these json messages before being sent 6:10you would need to import gzip or 6:13whatever 6:14compression tool you're using on each of 6:16the microservices and that would be 6:19a bit of a pain over time since you're 6:20basically working on different micro 6:23services and you're implementing that 6:24yourself whereas with grpc this is all 6:27handled for you 6:29so to summarize grpc offers convenience 6:34and then in the form of code generation 6:36protocol buffers 6:39the client library being implemented for 6:41you 6:42and on top of that performance overall 6:44using http 2.0 and 6:47sending very small performant messages 6:50across the wire 6:51so hopefully this provided an example of 6:54grpc in a useful applicable format 6:58of course grpc is not the banded curl 7:01solution for communication but i did 7:03want to emphasize that this can be a 7:06good solution for your application here 7:07are some videos that may be of interest 7:09to you if you have any questions about 7:10this video add them in the comments 7:12below and be sure to like and subscribe 7:14thanks