"Get a comprehensive understanding of gRPC fundamentals through real-world examples. With this practical guide, you'll learn how this high-performance interprocess communication protocol is capable of connecting polyglot services in microservices architecture, while providing a rich framework for defining service contracts and data types. Complete with hands-on examples written in Go, Java, Node, and Python, this book also covers the essential techniques and best practices to use gRPC in production systems. Authors Kasun Indrasiri and Danesh Kuruppu discuss the importance of gRPC in the context of microservices development."--Amazon.com Copyright 4 Table of Contents 5 Preface 9 Why Did We Write This Book? 9 Who Is This Book For? 9 How This Book Is Organized 10 Using Code Examples 11 Conventions Used in This Book 11 O’Reilly Online Learning 12 How to Contact Us 13 Acknowledgments 13 Chapter 1. Introduction to gRPC 15 What Is gRPC? 16 Service Definition 18 gRPC Server 19 gRPC Client 21 Client–Server Message Flow 22 Evolution of Inter-Process Communication 22 Conventional RPC 22 SOAP 23 REST 23 Inception of gRPC 25 Why gRPC? 25 gRPC Versus Other Protocols: GraphQL and Thrift 28 gRPC in the Real World 29 Netflix 30 etcd 30 Dropbox 31 Summary 31 Chapter 2. Getting Started with gRPC 33 Creating the Service Definition 34 Defining Messages 35 Defining Services 36 Implementation 38 Developing a Service 39 Developing a gRPC Client 50 Building and Running 53 Building a Go Server 54 Building a Go Client 54 Running a Go Server and Client 54 Building a Java Server 55 Building a Java Client 55 Running a Java Server and Client 55 Summary 56 Chapter 3. gRPC Communication Patterns 57 Simple RPC (Unary RPC) 57 Server-Streaming RPC 60 Client-Streaming RPC 63 Bidirectional-Streaming RPC 67 Using gRPC for Microservices Communication 72 Summary 74 Chapter 4. gRPC: Under the Hood 75 RPC Flow 76 Message Encoding Using Protocol Buffers 77 Encoding Techniques 81 Length-Prefixed Message Framing 83 gRPC over HTTP/2 85 Request Message 86 Response Message 88 Understanding the Message Flow in gRPC Communication Patterns 90 gRPC Implementation Architecture 93 Summary 94 Chapter 5. gRPC: Beyond the Basics 95 Interceptors 95 Server-Side Interceptors 96 Client-Side Interceptors 101 Deadlines 104 Cancellation 107 Error Handling 109 Multiplexing 113 Metadata 115 Creating and Retrieving Metadata 116 Sending and Receiving Metadata: Client Side 117 Sending and Receiving Metadata: Server Side 118 Name Resolver 120 Load Balancing 121 Load-Balancer Proxy 122 Client-Side Load Balancing 123 Compression 125 Summary 125 Chapter 6. Secured gRPC 127 Authenticating a gRPC Channel with TLS 127 Enabling a One-Way Secured Connection 128 Enabling an mTLS Secured Connection 131 Authenticating gRPC Calls 136 Using Basic Authentication 136 Using OAuth 2.0 141 Using JWT 144 Using Google Token-Based Authentication 145 Summary 146 Chapter 7. Running gRPC in Production 149 Testing gRPC Applications 149 Testing a gRPC Server 149 Testing a gRPC Client 151 Load Testing 152 Continuous Integration 153 Deployment 153 Deploying on Docker 154 Deploying on Kubernetes 156 Observability 162 Metrics 162 Logs 170 Tracing 171 Debugging and Troubleshooting 175 Enabling Extra Logging 175 Summary 176 Chapter 8. The gRPC Ecosystem 177 gRPC Gateway 177 HTTP/JSON Transcoding for gRPC 184 The gRPC Server Reflection Protocol 185 gRPC Middleware 188 Health Checking Protocol 190 gRPC Health Probe 192 Other Ecosystem Projects 194 Summary 194 Index 197 About the Authors 203 Colophon 203