{"id":13818,"date":"2022-07-31T07:03:51","date_gmt":"2022-07-31T07:03:51","guid":{"rendered":"https:\/\/engineering.lusha.com\/blog\/?p=13818"},"modified":"2023-03-16T08:16:34","modified_gmt":"2023-03-16T08:16:34","slug":"an-introduction-to-grpc-in-node-js","status":"publish","type":"post","link":"https:\/\/engineering.lusha.com\/blog\/an-introduction-to-grpc-in-node-js\/","title":{"rendered":"An Introduction to gRPC in Node.js"},"content":{"rendered":"<p>gRPC is a new technology that is gaining more and more popularity, leading companies use it as the default way to communicate between internal services, in this blog post I will introduce gRPC, explain about its fundamentals, and demonstrate a client\/server coding example in Node.js.<\/p>\n<h2>gRPC Motivation<\/h2>\n<p>Nowadays Microservices are everywhere, this kind of architecture has many advantages, for example services can be scaled separately, services can be developed in different languages and more.<br \/>\nHuge amount of data flows between those services, hence they must be able to communicate with each other &#8211; for that we need to define an API contract, but building an API requires us to consider many important stuff, such as:<\/p>\n<ul>\n<li>The client\/server communication protocol (REST, graphQL, SOAP, etc)<\/li>\n<li>The payload format (JSON, XML, Binary, etc)<\/li>\n<li>The data modeling<\/li>\n<li>How to handle errors<\/li>\n<li>How to authenticate your users<\/li>\n<li>Scale &#8211; what happens when your service needs to handle large amount of concurrent requests<\/li>\n<\/ul>\n<p><span style=\"font-size: 16px;\">Sounds like a lot of work! Well&#8230; this is exactly what the gRPC framework is trying to resolve, the contributors of gRPC came to the conclusion that client server communication should be efficient and simple, they designed a framework that lets the developers focus on the core logic of the application and the framework will do the rest&#8230;<\/span><\/p>\n<h2>So what is gRPC?<\/h2>\n<p>gRPC (google Remote Procedure Call) is a technology developed by Google, it was released in 2016 and is now part of the Cloud Native Computing Foundation (CNCF open source projects) &#8211; like Prometheus and Kubernetes.<br \/>\nIt uses HTTP\/2 as a communication protocol, and protocol buffers as a messaging format.<br \/>\nThe project maintains official client libraries for 11 programing languages, it&#8217;s fast and efficient, supports low latency and bi-directional streams. It is language agnostic with pluggable features like authentication, load balancing, loggings and monitoring.<\/p>\n<p>In gRPC the client invokes methods in a remote server without specifying the details of the server, unlike REST for example when the client needs to specify the address and resource (i.e &lt;BASE_URL&gt;\/users\/:id), in simple words it looks like the client calls to a method that is located directly in the client app. gRPC is based on the RPC idea of defining a service, declaring the methods and their schema objects.<br \/>\nThe server must implement those methods, while the\u00a0client has stubs that provide the same methods as the server.<br \/>\ngRPC is used by top companies like: Netflix, Lyft, Cisco, Block (formerly Square) which are also contributors of the project and of course Google themselves.<\/p>\n<h2>What makes gRPC efficient?<\/h2>\n<p>There are two main things that makes gRPC so efficient<\/p>\n<h3 style=\"text-align: left; padding-left: 40px;\">Protobufs<\/h3>\n<p style=\"text-align: left; padding-left: 40px;\">In high level protobuf is a mechanism developed by google that supplies tools to define a schema that is going to be serialized\/ deserialized to binary format. Other than that, it supplies rules to support backward and forward compatibility for API evolving.<br \/>\nUsing binary format as the request-response payload is a huge advantage, since binary format is closer to how data is represented by machines &#8211; the serialization\/ deserialization is faster and consumes less CPU, which is very important for devices with limited network conditions like mobile and IoT devices as it improves the battery life and the latency. In addition, binary format compared to JSON format is much smaller hence it improves the network utilization.<br \/>\nprotobuf schema is defined in a .proto file as shown in this example:<\/p>\n<p style=\"text-align: left; padding-left: 40px;\"><script src=\"https:\/\/gist.github.com\/67a3d0f9e6c09beb8eccb384a0449a33.js\"><\/script><\/p>\n<p style=\"text-align: left; padding-left: 40px;\">The syntax keyword defines the version, the latest protobuf version is 3.<br \/>\nA message is an object that defines the schema and can include nested messages, in this case we have an Animals message that contains an array of messages from the type Animal.<br \/>\nThe Animal message itself has strongly typed fields which are numbered, the numbering helps the encoding process to binary format.<br \/>\nprotobuf offers a protoc compiler for each programing language, its output is an auto generated code that includes interfaces and functions to create instances of the messages, populate them with data and then serialize them to binary format.<br \/>\nin gRPC all of these steps are being done by the framework itself, all we have to do is just to define the proto file which we will see in the coding example.<\/p>\n<h3 style=\"text-align: left; padding-left: 40px;\">HTTP\/2<\/h3>\n<p style=\"text-align: left; padding-left: 40px;\">HTTP\/2 was released in 2015 after being tested for many years by Google, because of the way it&#8217;s designed it supports headers compression which makes the packets even smaller and saves bandwidth, the frames are in binary format which is very performant, thus it works great with protocol buffers.<br \/>\nThe most important feature is multiplexing &#8211; unlike HTTP\/1.1 which needs to open a single TCP connection for each request-response, in HTTP\/2 multiple requests\/ responses are sent in parallel over a single TCP connection, which reduces latency and improves network utilization.<\/p>\n<p><strong>So the advantages of HTTP\/2 and protobufs are crystal clear and we get all these benefits with all the best practices as is! without any configuration, just by using the gRPC framework.<\/strong><\/p>\n<h2>API types of gRPC<\/h2>\n<p>gRPC has 4 API types that cover all the cases we need:<\/p>\n<p><img decoding=\"async\" class=\"wp-image-13826 size-full\" src=\"https:\/\/engineering.lusha.com\/wp-content\/uploads\/2022\/07\/Screen-Shot-2022-07-21-at-19.37.47.png\" alt=\"types of gRPC API's\" width=\"1081\" height=\"361\" srcset=\"https:\/\/engineering.lusha.com\/wp-content\/uploads\/2022\/07\/Screen-Shot-2022-07-21-at-19.37.47.png 1081w, https:\/\/engineering.lusha.com\/wp-content\/uploads\/2022\/07\/Screen-Shot-2022-07-21-at-19.37.47-300x100.png 300w, https:\/\/engineering.lusha.com\/wp-content\/uploads\/2022\/07\/Screen-Shot-2022-07-21-at-19.37.47-1024x342.png 1024w, https:\/\/engineering.lusha.com\/wp-content\/uploads\/2022\/07\/Screen-Shot-2022-07-21-at-19.37.47-768x256.png 768w\" sizes=\"(max-width: 1081px) 100vw, 1081px\" \/><\/p>\n<p><strong>Unary<\/strong> &#8211; Normal request response, very similar to REST but works with protobufs and HTTP\/2 under the hood.<br \/>\n<strong>Client streaming\u00a0<\/strong>&#8211; The client send messages in a stream to the server and when the client finishes the server sends response.<br \/>\n<strong>Server streaming\u00a0<\/strong>&#8211; The client asks for a resource from the server and the server responses with a stream of messages.<br \/>\n<strong>BI &#8211; directional streaming\u00a0<\/strong>&#8211; Both client and server are sending messages in the same TCP channel.<\/p>\n<h2>Let&#8217;s get hands-on<\/h2>\n<p>Now after we understand why gRPC was invented and how it works let&#8217;s get our hands dirty and implement a client\/ server example in node.js.<br \/>\nOur App will be an &#8216;Employees App&#8217;, where we will implement 2 methods: Unary and Server stream.<\/p>\n<p><img decoding=\"async\" class=\"wp-image-13828 size-full\" src=\"https:\/\/engineering.lusha.com\/wp-content\/uploads\/2022\/07\/Screen-Shot-2022-07-21-at-19.52.14.png\" alt=\"employees methods\" width=\"576\" height=\"391\" srcset=\"https:\/\/engineering.lusha.com\/wp-content\/uploads\/2022\/07\/Screen-Shot-2022-07-21-at-19.52.14.png 576w, https:\/\/engineering.lusha.com\/wp-content\/uploads\/2022\/07\/Screen-Shot-2022-07-21-at-19.52.14-300x204.png 300w\" sizes=\"(max-width: 576px) 100vw, 576px\" \/><br \/>\nAs shown in the figure above, we will have a unary method that will add employees to in memory database, and another server stream method that will read all the employees one by one in a stream instead of a big array chunk.<\/p>\n<h2>Setting up our project<\/h2>\n<p>We will need node.js and NPM installed on our machine, in case you don&#8217;t have it you can download it <a href=\"https:\/\/nodejs.org\/en\/\" rel=\"nofollow noopener\" target=\"_blank\">here.<\/a><\/p>\n<p>Now create a folder for the project:<br \/>\n<code>mkdir employees-app\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><\/p>\n<p>Move inside the project and initialize our node environment:<br \/>\n<code>cd employees-app &amp;&amp; npm init -y<\/code><\/p>\n<p>Next, install our dependancies:<br \/>\n@grpc\/grpc-js &#8211; the gRPC library for node.js that supplies the server and client functionality<br \/>\n@grpc\/proto-loader &#8211; the package to load our proto files and convert it to the messages objects and methods<br \/>\n<code>npm install @grpc\/grpc-js @grpc\/proto-loader<\/code><\/p>\n<h2>Defining our contract<\/h2>\n<p>First we need to define our protobuf contract, for this we need to create the proto file and implement the schema.<br \/>\n<code>touch employees.proto<\/code><\/p>\n<p>Our proto file will look as follow:<\/p>\n<script src=\"https:\/\/gist.github.com\/80cdbedc4d34ca4c32a343a8f5fef07b.js\"><\/script>\n<p>Let&#8217;s explain it, we are using the latest version which is proto3, we then declare a package and name it employees, the package name is the identifier of the proto file and we will use it to load it later.<br \/>\nBelow we are declaring the Service which includes the methods that we will need to implement in our server, we have 2 methods:<br \/>\n&#8211; <code><span class=\"pl-k\">rpc<\/span> <strong><span class=\"pl-en\">addEmployee<\/span><\/strong> (<span class=\"pl-en\">EmployeeRequest<\/span>) <span class=\"pl-k\">returns<\/span> (<span class=\"pl-en\">EmployeeResponse<\/span>) {}<\/code> &#8211; which implements unary API that sends EmployeeRequest from the client and receives EmployeeResponse from the server.<br \/>\n&#8211; <code><span class=\"pl-k\">rpc<\/span> <strong><span class=\"pl-en\">readEmployees<\/span><\/strong> (<span class=\"pl-en\">Empty<\/span>) <span class=\"pl-k\">returns<\/span> (<span class=\"pl-k\">stream<\/span> <span class=\"pl-en\">EmployeeResponse<\/span>) {}<\/code> &#8211; which implements server streaming API, the\u00a0<strong><em>stream<\/em><\/strong><em>\u00a0<\/em>keyword in the response defines that this is a server stream, the method sends empty request and gets a stream of EmployeeResponse.<\/p>\n<p>Our request and response messages are defined in the bottom of the file:<br \/>\n&#8211; EmployeeRequest includes name and last_name which are strings.<br \/>\n&#8211; EmployeeResponse includes name, last_name and email which are strings and id which is an integer.<\/p>\n<h2>Implementing the server<\/h2>\n<p>The server will run on a gRPC port and will implement the methods that are defined in the service of the proto file.<br \/>\nLet&#8217;s go ahead and create it.<\/p>\n<p><code>touch server.js<\/code><\/p>\n<p>Our server boilerplate will look as follow:<br \/>\n<script src=\"https:\/\/gist.github.com\/be10d5bb715616d856817170a76b2cd5.js\"><\/script><\/p>\n<p>We first import the @grpc\/grpc-js which is the official gRPC library for node.js and the helper package @grpc\/proto-loader that deals with the proto file.<br \/>\n<code>const grpc = require(\"@grpc\/grpc-js\");<\/code><br \/>\n<code>const protoLoader = require(\"@grpc\/proto-loader\");<\/code><\/p>\n<p>We then use the helper function <code>protoLoader.loadSync<\/code> to load the employee package definition with the default configurations while supplying the path to our proto file.<br \/>\nThe package definition we got, is then being loaded to the grpc object<br \/>\n<code>const employeesProto = grpc.loadPackageDefinition(packageDefinition).employees;<\/code><br \/>\nNow we have an object that contains the methods and the interfaces that we defined in the proto file and we are ready to use it.<br \/>\nWe are creating a new server instance, adding the Employee service and its methods, finally we are running it on port 50050.<\/p>\n<p>It&#8217;s time to implement our methods:<br \/>\n<script src=\"https:\/\/gist.github.com\/b36819301ea818ac548a26d20b0e78ab.js\"><\/script><\/p>\n<p>Our unary method <strong>addEmployee<\/strong> accepts the arguments call and callback, the call object holds the info of the entire call\/channel and the callback function returns the response to the client.<br \/>\nThe implementation is simple, we are destructing name and lastName from the request, composing the employee object based on the schema that is defined in our proto file (EmployeeResponse), pushing it to our in memory database\u00a0 (the employees array), at last we are sending the specific employee response back to the client.<\/p>\n<p>Our server streaming method <strong>readEmployee\u00a0<\/strong>accepts only single argument which is the call object because it uses the stream itself to send responses to the client.<br \/>\nIn the implementation we are looping over the employees database and we&#8217;re using <strong>call.write\u00a0<\/strong>to stream the messages to the client. (a sleep is added for better visibility).<br \/>\nAfter all the employees data was streamed to the client, the server is closing the call and notifying the client about it, so the client can gracefully shut down.<\/p>\n<p>Our final unified server file should look like this:<br \/>\n<script src=\"https:\/\/gist.github.com\/24f07a4eaadead6569b85da52f2be86a.js\"><\/script><\/p>\n<h2>Implementing the client<\/h2>\n<p>The client will connect to the gRPC server and will invoke methods.<br \/>\nLet&#8217;s create it.<br \/>\n<code>touch client.js<\/code><\/p>\n<p>The client boilerplate will look as follow:<br \/>\n<script src=\"https:\/\/gist.github.com\/b54b1b8d1f3f4fb67aafa28c68ba4550.js\"><\/script><\/p>\n<p>The loading process of the proto file is similar to what we have done in the server, since they both need to apply the protobuf contract.<br \/>\nThe only difference between them is that instead of creating a server, we are creating a client instance so it will be able to invoke methods that are defined in our Employee service, this is done by:<br \/>\n<code>const client = newemployeesProto.Employee(<\/code><code>\"localhost:50050\",<\/code><code>grpc.credentials.createInsecure()<\/code><code>);<\/code><\/p>\n<p>Now we can add the code that invokes the methods to our client.js file:<br \/>\n<script src=\"https:\/\/gist.github.com\/de41f13e63975b7a06fee6a99fd6eea7.js\"><\/script><\/p>\n<p>As you can see we have a condition that if we run the client with args (name, lastName) it will invoke the unary method and will forward the payload to the server in order to compose a new employee, otherwise the server stream method will be invoked.<br \/>\nOur unary stub in the client invokes the addEmployee method and passes the EmployeeRequest message, and a callback that returns from the server after success or failure.<br \/>\nOur server streaming stub starts a stream with the server, and gets a reference to this stream, as declared in:<br \/>\n<code>const call = client.readEmployees();<\/code><br \/>\nWe then register to\u00a0 the events of this call:<br \/>\n<strong>&#8211; call.on(&#8220;data&#8221;)<\/strong> which will be called on each response that we get in our stream from the server, in this case we are getting the EmployeeResponse and logging it to the screen.<br \/>\n<strong>&#8211; call.on(&#8220;end&#8221;)<\/strong> which indicates the server finished to stream all its data and we can gracefully shutdown the client.<\/p>\n<h2>Running our app<\/h2>\n<p>We have implemented our employees app, let&#8217;s run it!<br \/>\nOpen 2 terminal windows and first run the server<br \/>\n<code>node server.js<\/code><\/p>\n<p>You should see the following message:<br \/>\n<code><strong>-&gt; employees-app<\/strong> node server.js<br \/>\n<\/code><code>gRPC Server started...<\/code><\/p>\n<p>Now Let&#8217;s add our employees by running the client from the second terminal window and invoking the unary method, We will add 3 employees as follow:<br \/>\n<code><strong>-&gt; employees-app<\/strong> node client.js tony stark<br \/>\n<\/code><code>Employee tony stark was added successfully<\/code><\/p>\n<p><code><strong>-&gt; employees-app<\/strong> node client.js peter parker<br \/>\n<\/code><code>Employee peter parker was added successfully<\/code><\/p>\n<p><code><strong>-&gt; employees-app<\/strong> node client.js steve rogers<br \/>\n<\/code><code>Employee steve rogers was added successfully<\/code><\/p>\n<p>It&#8217;s time for the big moment! let&#8217;s get all our employees in a stream, for that simply run the client.js file without args at all.<\/p>\n<p><code>node client.js<\/code><br \/>\nand Voila! we got our employees in a stream.<\/p>\n<p><code>Employee details {\"id\":1,\"email\":\"tony.stark@lusha.com\",\"name\":\"tony\",\"lastName\":\"stark\"}<\/code><\/p>\n<p><code>Employee details {\"id\":2,\"email\":\"peter.parker@lusha.com\",\"name\":\"peter\",\"lastName\":\"parker\"}<\/code><\/p>\n<p><code>Employee details {\"id\":3,\"email\":\"steve.rogers@lusha.com\",\"name\":\"steve\",\"lastName\":\"rogers\"}<\/code><br \/>\n<code>Server has closed the call, Bye bye...<\/code><\/p>\n<h2>Wrapping up<\/h2>\n<p>In this blog post, we introduced gRPC, we explained what problem gRPC tries to resolve and motivation of it.<br \/>\nIn addition we covered advanced topics like protocol buffers and HTTP\/2 which are the gRPC fundamentals and what makes it so efficient.<br \/>\nWe then moved to a hands on example where we implemented client server application with the gRPC node.js library.<br \/>\nBut still, there are a lot more to discover, I encourage you to read the documents, posts and the roadmap of the <a href=\"https:\/\/grpc.io\/\" rel=\"nofollow noopener\" target=\"_blank\">official project<\/a>, get confidence by developing your own apps.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>gRPC is a new technology that is gaining more and more popularity, leading companies use it as the default way to communicate between internal services, in this blog post I will introduce gRPC, explain about its fundamentals, and demonstrate a client\/server coding example in Node.js. gRPC Motivation Nowadays Microservices are everywhere, this kind of architecture [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":13852,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[155,109],"tags":[],"class_list":["post-13818","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-grpc","category-nodejs"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>An Introduction to gRPC in Node.js - Lusha Engineering Blog<\/title>\n<meta name=\"description\" content=\"An introduction to gRPC and protocol buffers, why it is so efficient, with hands on example of gRPC client\/server application in node.js.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/engineering.lusha.com\/blog\/an-introduction-to-grpc-in-node-js\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"An Introduction to gRPC in Node.js - Lusha Engineering Blog\" \/>\n<meta property=\"og:description\" content=\"An introduction to gRPC and protocol buffers, why it is so efficient, with hands on example of gRPC client\/server application in node.js.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/engineering.lusha.com\/blog\/an-introduction-to-grpc-in-node-js\/\" \/>\n<meta property=\"og:site_name\" content=\"Lusha Engineering Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/LushaData\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-31T07:03:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-16T08:16:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/engineering.lusha.com\/wp-content\/uploads\/2022\/07\/efficient.png\" \/>\n\t<meta property=\"og:image:width\" content=\"996\" \/>\n\t<meta property=\"og:image:height\" content=\"561\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Guy Lisak\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@lushadata\" \/>\n<meta name=\"twitter:site\" content=\"@lushadata\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Guy Lisak\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/an-introduction-to-grpc-in-node-js\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/an-introduction-to-grpc-in-node-js\\\/\"},\"author\":{\"name\":\"Guy Lisak\",\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/#\\\/schema\\\/person\\\/2e98e500cc222b520e7bc0414ec30ff1\"},\"headline\":\"An Introduction to gRPC in Node.js\",\"datePublished\":\"2022-07-31T07:03:51+00:00\",\"dateModified\":\"2023-03-16T08:16:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/an-introduction-to-grpc-in-node-js\\\/\"},\"wordCount\":2136,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/an-introduction-to-grpc-in-node-js\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/engineering.lusha.com\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/efficient.png\",\"articleSection\":[\"gRPC\",\"Node.js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/an-introduction-to-grpc-in-node-js\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/an-introduction-to-grpc-in-node-js\\\/\",\"url\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/an-introduction-to-grpc-in-node-js\\\/\",\"name\":\"An Introduction to gRPC in Node.js - Lusha Engineering Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/an-introduction-to-grpc-in-node-js\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/an-introduction-to-grpc-in-node-js\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/engineering.lusha.com\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/efficient.png\",\"datePublished\":\"2022-07-31T07:03:51+00:00\",\"dateModified\":\"2023-03-16T08:16:34+00:00\",\"description\":\"An introduction to gRPC and protocol buffers, why it is so efficient, with hands on example of gRPC client\\\/server application in node.js.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/an-introduction-to-grpc-in-node-js\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/an-introduction-to-grpc-in-node-js\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/an-introduction-to-grpc-in-node-js\\\/#primaryimage\",\"url\":\"https:\\\/\\\/engineering.lusha.com\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/efficient.png\",\"contentUrl\":\"https:\\\/\\\/engineering.lusha.com\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/efficient.png\",\"width\":996,\"height\":561,\"caption\":\"gRPC introduction\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/an-introduction-to-grpc-in-node-js\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"An Introduction to gRPC in Node.js\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/\",\"name\":\"Lusha Engineering Blog\",\"description\":\"Search less. Sell more.\",\"publisher\":{\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/#organization\",\"name\":\"Lusha\",\"url\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/engineering.lusha.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/cropped-fav.png\",\"contentUrl\":\"https:\\\/\\\/engineering.lusha.com\\\/wp-content\\\/uploads\\\/2021\\\/07\\\/cropped-fav.png\",\"width\":512,\"height\":512,\"caption\":\"Lusha\"},\"image\":{\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/LushaData\\\/\",\"https:\\\/\\\/x.com\\\/lushadata\",\"https:\\\/\\\/www.instagram.com\\\/lifeatlusha\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/lushadata\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCZNqzgRZFBub6WJxeaQcxUQ\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/#\\\/schema\\\/person\\\/2e98e500cc222b520e7bc0414ec30ff1\",\"name\":\"Guy Lisak\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cb1a94c9a099b6b0804a814df63921d7785a185b20d236fdceb3c7c976c66b6e?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cb1a94c9a099b6b0804a814df63921d7785a185b20d236fdceb3c7c976c66b6e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cb1a94c9a099b6b0804a814df63921d7785a185b20d236fdceb3c7c976c66b6e?s=96&d=mm&r=g\",\"caption\":\"Guy Lisak\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/guy-lissak-235a9a109\\\/\"],\"url\":\"https:\\\/\\\/engineering.lusha.com\\\/blog\\\/author\\\/guy\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"An Introduction to gRPC in Node.js - Lusha Engineering Blog","description":"An introduction to gRPC and protocol buffers, why it is so efficient, with hands on example of gRPC client\/server application in node.js.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/engineering.lusha.com\/blog\/an-introduction-to-grpc-in-node-js\/","og_locale":"en_US","og_type":"article","og_title":"An Introduction to gRPC in Node.js - Lusha Engineering Blog","og_description":"An introduction to gRPC and protocol buffers, why it is so efficient, with hands on example of gRPC client\/server application in node.js.","og_url":"https:\/\/engineering.lusha.com\/blog\/an-introduction-to-grpc-in-node-js\/","og_site_name":"Lusha Engineering Blog","article_publisher":"https:\/\/www.facebook.com\/LushaData\/","article_published_time":"2022-07-31T07:03:51+00:00","article_modified_time":"2023-03-16T08:16:34+00:00","og_image":[{"width":996,"height":561,"url":"https:\/\/engineering.lusha.com\/wp-content\/uploads\/2022\/07\/efficient.png","type":"image\/png"}],"author":"Guy Lisak","twitter_card":"summary_large_image","twitter_creator":"@lushadata","twitter_site":"@lushadata","twitter_misc":{"Written by":"Guy Lisak","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/engineering.lusha.com\/blog\/an-introduction-to-grpc-in-node-js\/#article","isPartOf":{"@id":"https:\/\/engineering.lusha.com\/blog\/an-introduction-to-grpc-in-node-js\/"},"author":{"name":"Guy Lisak","@id":"https:\/\/engineering.lusha.com\/blog\/#\/schema\/person\/2e98e500cc222b520e7bc0414ec30ff1"},"headline":"An Introduction to gRPC in Node.js","datePublished":"2022-07-31T07:03:51+00:00","dateModified":"2023-03-16T08:16:34+00:00","mainEntityOfPage":{"@id":"https:\/\/engineering.lusha.com\/blog\/an-introduction-to-grpc-in-node-js\/"},"wordCount":2136,"commentCount":0,"publisher":{"@id":"https:\/\/engineering.lusha.com\/blog\/#organization"},"image":{"@id":"https:\/\/engineering.lusha.com\/blog\/an-introduction-to-grpc-in-node-js\/#primaryimage"},"thumbnailUrl":"https:\/\/engineering.lusha.com\/wp-content\/uploads\/2022\/07\/efficient.png","articleSection":["gRPC","Node.js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/engineering.lusha.com\/blog\/an-introduction-to-grpc-in-node-js\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/engineering.lusha.com\/blog\/an-introduction-to-grpc-in-node-js\/","url":"https:\/\/engineering.lusha.com\/blog\/an-introduction-to-grpc-in-node-js\/","name":"An Introduction to gRPC in Node.js - Lusha Engineering Blog","isPartOf":{"@id":"https:\/\/engineering.lusha.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/engineering.lusha.com\/blog\/an-introduction-to-grpc-in-node-js\/#primaryimage"},"image":{"@id":"https:\/\/engineering.lusha.com\/blog\/an-introduction-to-grpc-in-node-js\/#primaryimage"},"thumbnailUrl":"https:\/\/engineering.lusha.com\/wp-content\/uploads\/2022\/07\/efficient.png","datePublished":"2022-07-31T07:03:51+00:00","dateModified":"2023-03-16T08:16:34+00:00","description":"An introduction to gRPC and protocol buffers, why it is so efficient, with hands on example of gRPC client\/server application in node.js.","breadcrumb":{"@id":"https:\/\/engineering.lusha.com\/blog\/an-introduction-to-grpc-in-node-js\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/engineering.lusha.com\/blog\/an-introduction-to-grpc-in-node-js\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/engineering.lusha.com\/blog\/an-introduction-to-grpc-in-node-js\/#primaryimage","url":"https:\/\/engineering.lusha.com\/wp-content\/uploads\/2022\/07\/efficient.png","contentUrl":"https:\/\/engineering.lusha.com\/wp-content\/uploads\/2022\/07\/efficient.png","width":996,"height":561,"caption":"gRPC introduction"},{"@type":"BreadcrumbList","@id":"https:\/\/engineering.lusha.com\/blog\/an-introduction-to-grpc-in-node-js\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/engineering.lusha.com\/blog\/"},{"@type":"ListItem","position":2,"name":"An Introduction to gRPC in Node.js"}]},{"@type":"WebSite","@id":"https:\/\/engineering.lusha.com\/blog\/#website","url":"https:\/\/engineering.lusha.com\/blog\/","name":"Lusha Engineering Blog","description":"Search less. Sell more.","publisher":{"@id":"https:\/\/engineering.lusha.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/engineering.lusha.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/engineering.lusha.com\/blog\/#organization","name":"Lusha","url":"https:\/\/engineering.lusha.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/engineering.lusha.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/engineering.lusha.com\/wp-content\/uploads\/2021\/07\/cropped-fav.png","contentUrl":"https:\/\/engineering.lusha.com\/wp-content\/uploads\/2021\/07\/cropped-fav.png","width":512,"height":512,"caption":"Lusha"},"image":{"@id":"https:\/\/engineering.lusha.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/LushaData\/","https:\/\/x.com\/lushadata","https:\/\/www.instagram.com\/lifeatlusha","https:\/\/www.linkedin.com\/company\/lushadata","https:\/\/www.youtube.com\/channel\/UCZNqzgRZFBub6WJxeaQcxUQ"]},{"@type":"Person","@id":"https:\/\/engineering.lusha.com\/blog\/#\/schema\/person\/2e98e500cc222b520e7bc0414ec30ff1","name":"Guy Lisak","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cb1a94c9a099b6b0804a814df63921d7785a185b20d236fdceb3c7c976c66b6e?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cb1a94c9a099b6b0804a814df63921d7785a185b20d236fdceb3c7c976c66b6e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cb1a94c9a099b6b0804a814df63921d7785a185b20d236fdceb3c7c976c66b6e?s=96&d=mm&r=g","caption":"Guy Lisak"},"sameAs":["https:\/\/www.linkedin.com\/in\/guy-lissak-235a9a109\/"],"url":"https:\/\/engineering.lusha.com\/blog\/author\/guy\/"}]}},"_links":{"self":[{"href":"https:\/\/engineering.lusha.com\/blog\/wp-json\/wp\/v2\/posts\/13818","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/engineering.lusha.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/engineering.lusha.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/engineering.lusha.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/engineering.lusha.com\/blog\/wp-json\/wp\/v2\/comments?post=13818"}],"version-history":[{"count":10,"href":"https:\/\/engineering.lusha.com\/blog\/wp-json\/wp\/v2\/posts\/13818\/revisions"}],"predecessor-version":[{"id":13858,"href":"https:\/\/engineering.lusha.com\/blog\/wp-json\/wp\/v2\/posts\/13818\/revisions\/13858"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/engineering.lusha.com\/blog\/wp-json\/wp\/v2\/media\/13852"}],"wp:attachment":[{"href":"https:\/\/engineering.lusha.com\/blog\/wp-json\/wp\/v2\/media?parent=13818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/engineering.lusha.com\/blog\/wp-json\/wp\/v2\/categories?post=13818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/engineering.lusha.com\/blog\/wp-json\/wp\/v2\/tags?post=13818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}