Home Web Development Practical gRPC

Practical gRPC

By Joshua B. Humphries , David Konsumer , David Muto and 2 more
books-svg-icon Book
eBook $24.99 $16.99
Print $54.99
Subscription $15.99 $10 p/m for three months
$10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
BUY NOW $10 p/m for first 3 months. $15.99 p/m after that. Cancel Anytime!
eBook $24.99 $16.99
Print $54.99
Subscription $15.99 $10 p/m for three months
What do you get with a Packt Subscription?
This book & 7000+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook + Subscription?
Download this book in EPUB and PDF formats, plus a monthly download credit
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with a Packt Subscription?
This book & 6500+ ebooks & video courses on 1000+ technologies
60+ curated reading lists for various learning paths
50+ new titles added every month on new and emerging tech
Early Access to eBooks as they are being written
Personalised content suggestions
Customised display settings for better reading experience
50+ new titles added every month on new and emerging tech
Playlists, Notes and Bookmarks to easily manage your learning
Mobile App with offline access
What do you get with eBook?
Download this book in EPUB and PDF formats
Access this title in our online reader
DRM FREE - Read whenever, wherever and however you want
Online reader with customised display settings for better reading experience
What do you get with video?
Download this video in MP4 format
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with video?
Stream this video
Access this title in our online reader
DRM FREE - Watch whenever, wherever and however you want
Online reader with customised display settings for better learning experience
What do you get with Audiobook?
Download a zip folder consisting of audio files (in MP3 Format) along with supplementary PDF
What do you get with Exam Trainer?
Flashcards, Mock exams, Exam Tips, Practice Questions
Access these resources with our interactive certification platform
Mobile compatible-Practice whenever, wherever, however you want
  1. Free Chapter
    1. Introduction
About this book
While building systems that contain several components, you need a framework that is fast and has minimal network overhead. gRPC is one such open-source tool that is quickly becoming popular and gaining popularity with programmers. Practical gRPC introduces you to gRPC and explains how it compares and contrasts with similar technologies. You’ll be introduced to key technologies such as Protocol Buffers, and work your way up from basic gRPC usage, all the way through to its more advanced capabilities. You’ll learn the best practices for defining and evolving your gRPC APIs, and discover how different tools can be leveraged to get the most out of gRPC and even extend it. By the end of this book, you'll have all the information you need to get started building systems with gRPC.
Publication date:
November 2019
Publisher
Packt
Pages
169
ISBN
9781839211744

 

Chapter 1. Introduction

This book aims to provide a practical approach to learning and using gRPC. It attempts to catalog and teach not only the basics of gRPC, which you could also find in countless blog posts and the gRPC home page itself, but also to show the more interesting (perhaps less well-documented) aspects of gRPC. The book even demonstrates some of the gRPC pitfalls, and what you need to know to overcome them.

The first few chapters in this book introduce gRPC, describing what it is and how it compares and contrasts to other technologies in the same space. We’ll also dive into how to actually use and apply it. Next, the book will venture into more advanced techniques. These advanced chapters will arm you with the tools to use gRPC to the fullest, so you can truly harness its features for solving problems and building software systems. There are also more practical concerns covered, like best practices for evolving your RPC interfaces and schemas. The later chapters in the book will detour into related technologies, some that complement gRPC in production environments and some that aid developers in building and testing applications that use gRPC.

 

Computer networks and distributed computing

The earliest ideas for connecting multiple computers to form a network came about in the 1960’s. Shortly after, the ARPANET (the precursor to the Internet) was created. In the 1970’s, email was invented, which became the most widely used distributed application on the ARPANET. In these early days, the power of the network was mostly for sharing information by sending data from one computer to another on the other side of the country. Distributed computing became its own field of computer science in the 1970’s. So the study of how multiple computers could be used to solve larger problems than a single computer could solve was of great interest. This fledgling Internet connected the computing resources of numerous universities and government organizations, creating a large pool of compute power.

The ARPANET eventually grew into the Internet we know today, connecting millions of computers all across the globe. It powered the rise of the World Wide Web in the 1990’s, and today the Internet is a utility, much like electricity or water. It is available almost everywhere in the USA and also in most of the world. With more recent innovations in mobile computing and embedded systems, the Internet has become an integral component in modern life, not just in business.

 

Request-response protocols

Numerous networking protocols have been developed for sharing information from one point of the Internet to the other. Almost all of the protocols use the TCP/IP Internet protocol suite. This has enabled the free flow of information across the globe, and it has also had an immeasurable impact on modern business and commerce, which rely greatly on computer networks and distributed computing.

clients and servers

This diagram shows a very simple but typical arrangement. In enterprise settings, the two halves will likely be on the same network, or perhaps a VPN is used to securely connect clients to the servers. For eCommerce, SaaS (Software as a Service) and other Internet offerings, the servers might be hosted in the provider’s datacenter or even with a third-party provider like Amazon Elastic Compute Cloud (EC2), Google Cloud Platform, or Microsoft Azure. The main components of interest here are clients, on the left, and servers, on the right.

A client is a program that initiates communication-usually by creating a TCP connection. It may be an end-user program, initiating communication to request information or resources that it presents to a user. In web applications, for example, the client is a web browser such as Chrome or Firefox.

A server is a program that accepts these client connections and in turn processes their requests. There are many kinds of servers. The diagram shows an application server, so named because it serves data to the client application. (It is also called a web server if it uses HTTP as the communication protocol). As shown in the diagram, the application server may involve other computers in order to serve responses. In that case, the server also acts as a client. In the diagram, the application server acts as a database client, requesting information from the database server.

Most networking protocols follow this pattern: a client creates a network connection to the server and sends requests. The server accepts requests, performs some processing, and then sends responses. This request-response flow was conceived in the early days of networking in the 1960’s and has been foundational to distributed computing ever since.

 

Remote Procedure Calls

RPC stands for Remote Procedure Calls. It is a programming model built on top of request-response network protocols. Issuing an RPC in a client amounts to invoking a procedure from application code. For a server, servicing an RPC amounts to implementing a procedure with a particular signature.

In the client, the objects that expose these procedures are called stubs. When application code invokes a procedure on a stub, the stub translates the arguments into bytes and then sends a request to the server, the contents of which are the serialized arguments. When it gets back a response from the server, it translates the bytes into a result value, which is then returned back to the application code that called it.

In the server, the objects that expose these procedures are service implementations. The server machinery receives the request, translates the bytes back into procedure arguments, and then invokes a procedure on the service implementation, passing it those arguments. The service implementation performs its business logic and then returns a result, either a value on success or an error code on failure. (In some RPC implementations, servers can return both values and an error code). The server machinery then translates this result into bytes, which then become the response that is sent back to the client.

RPC flow

RPC is not a new programming idiom: proposals for remote procedure call semantics were written in the 70’s, and practical RPC implementations appeared in the 80’s, such as the Network File System (NFS).

gRPC is a cross-platform RPC system that supports a wide variety of programming languages. It excels at providing high performance and ease of use, to greatly simplify the construction of all types of distributed systems.

 

Summary

This chapter introduced the domain in which gRPC is used (distributed computing), and provided a brief overview of how this domain has evolved over time.

In the next chapter, we will go into greater detail as to what exactly gRPC is, and how it compares to similar technologies.

About the Authors
  • Joshua B. Humphries

    Joshua Humphries (jhump on GitHub) has been working with Protocol Buffers and building RPC systems and related facilities for over six years. He was first introduced to Protocol Buffers and Stubby (gRPCs forebearer) while working at Google. Afterward, he led a team that worked on protobuf-based RPC at Square, including smart clients in Java, Go, and Ruby that handled service discovery, load balancing, automatic retries, and automatic geographic failover. Joshua has been an advocate of gRPC since its initial release. He continues his work with Protocol Buffers and gRPC as part of an infrastructure team at FullStory, a customer experience management platform. He is a contributor to the Go open-source projects for gRPC and Protocol Buffers, the author of a Go library for Protocol Buffer reflection named protoreflect, and the author of gRPC-related projects open-sourced by FullStory, including grpcurl.

    Browse publications by this author
  • David Konsumer

    David Konsumer (konsumer on GitHub, davidkonsumer on Twitter) has been working with open-source for about 20 years, with a strong focus on JavaScript. Before working with Node.js, he used PHP and Python to accomplish his daily programming tasks. He worked at NodeSource, to make N|Solid, Plex, Janrain, and Intel on the App Developer Program website. He also did lots of agency, freelance, and contract work, mostly for the web and cloud-based backend work. He taught programming classes at Free Geek, Portland. David is an advocate for accessible programming and the idea that everyone can learn to code, and it should be easy enough to get cool stuff done. He made grpcnode, node-protoc-plugin, and json2x, useful tools for getting things done with gRPC/protobuf in Node.js. David currently works as Lead of Engineering at Gummicube, an app-store optimization company based in San Jose, running the development department in Portland, OR.

    Browse publications by this author
  • David Muto

    David Muto (pseudomuto on GitHub, pseudomuto on Twitter) has been writing software professionally for over 15 years and is a strong believer in continuous learning. Over the years he has written production quality code in over a dozen languages, taught application development at George Brown College (in Toronto) and worked on everything from web and mobile apps to low-level systems and RPC services. Hes a serial OSS contributor and the author of protoc-gen-doc, a tool for generating documentation from Protocol Buffers. He also recently published proto kit, a library for building your own protoc plugins in Go. David currently works at Shopify, leading a team that develops highly-available, low-latency, distributed services in the Data Science and Engineering department.

    Browse publications by this author
  • Robert Ross

    Robert Ross, also known as Bobby Tables (bobbytables on GitHub, bobbytables on Twitter), is a full-time staff software engineer at Namely, where he works on the architecture team. He writes with Go and Ruby primarily but can swing some JavaScript if needed. He operates FireHydrant on the side while listening to the Hamilton soundtrack an unhealthy amount.

    Browse publications by this author
  • Carles Sistare

    Carles Sistare (carlessistare on GitHub, CarlesSistare on Twitter) is a challenge trotter eager for projects which offer the opportunity to learn about the most recent technologies. Keeping a close eye on the open-source community, three years ago, he became interested in gRPC, and quickly saw the benefits when it comes to microservice communication optimizations. Since then he has given several talks in France to evangelize gRPC. Carles is a co-founder of OGURY, an ad-tech company based in Paris, where he currently works as Head Architect.

    Browse publications by this author
Latest Reviews (3 reviews total)
Nuttige informatie compact
Great book. I could learn the history of gRPC and around of it sufficiently.
RAS
Practical gRPC
Unlock this book and the full library FREE for 7 days
Start now