Book Image

Microservices Communication in .NET Using gRPC

By : Fiodar Sazanavets
Book Image

Microservices Communication in .NET Using gRPC

By: Fiodar Sazanavets

Overview of this book

Explore gRPC's capabilities for faster communication between your microservices using the HTTP/2 protocol in this practical guide that shows you how to implement gRPC on the .NET platform. gRPC is one of the most efficient protocols for communication between microservices that is also relatively easy to implement. However, its official documentation is often fragmented and.NET developers might find it difficult to recognize the best way to map between C# data types and fields in gRPC messages. This book will address these concerns and much more. Starting with the fundamentals of gRPC, you'll discover how to use it inside .NET apps. You’ll explore best practices for performance and focus on scaling a gRPC app. Once you're familiar with the inner workings of the different call types that gRPC supports, you'll advance to learning how to secure your gRPC endpoints by applying authentication and authorization. With detailed explanations, this gRPC .NET book will show you how the Protobuf protocol allows you to send messages efficiently by including only the necessary data. You'll never get confused again while translating between C# data types and the ones available in Protobuf. By the end of the book, you’ll have gained practical gRPC knowledge and be able to use it in .NET apps to enable direct communication between microservices.
Table of Contents (17 chapters)
1
Section 1: Basics of gRPC on .NET
5
Section 2: Best Practices of Using gRPC
9
Section 3: In-Depth Look at gRPC on .NET

What this book covers

Chapter 1, Creating a Basic gRPC Application on ASP.NET Core, explains how to build a basic ASP.NET Core server application that uses gRPC. We will also build a basic console application that will act as a gRPC client.

Chapter 2, When gRPC Is the Best Tool and When It Isn't, outlines use cases where gRPC is the best tool for the job. It will also cover some scenarios where other tools would be more suitable than gRPC.

Chapter 3, Protobuf – the Communication Protocol of gRPC, takes you through the structure of Protobuf – the communication protocol that gRPC uses. You will be shown the basic structure of a proto file – a file that defines the interface that both the client and the server use to communicate with each other. All native data types available with Protobuf will be covered, along with other structural components of the protocol.

Chapter 4, Performance Best Practices of Using gRPC on .NET, explains how to apply gRPC inside the code in the most efficient way possible. You will learn a few ways to make your gRPC communication as fast as it can be.

Chapter 5, How to Apply Versioning to the gRPC API, emphasizes the importance of applying a good versioning strategy to your server-side gRPC endpoints, also known as application programming interfaces (APIs). You will also learn some techniques for making API versioning easy.

Chapter 6, Scaling a gRPC Application, explains how microservices are supposed to be designed in such a way that they can easily be scaled. An assumption of microservices architecture is that it should be possible to add new instances of any given microservices when needed, especially when they are stateless. As gRPC has been primarily designed to enable communication between microservices, it needs to be scalable too.

Chapter 7, Using All Different Call Types That gRPC Supports, covers the four different types of calls – unary, client-streaming, server-streaming, and bi-directional streaming – that gRPC supports.

Chapter 8, Using Well-Known Types to Make Protobuf More Handy, explains that since native Protobuf data types don't perfectly map to data types commonly used in programming languages, Google has created a library of so-called well-known types to make this process easier. This enables developers to send requests without payloads, use nullable fields, work with dates, and exchange loosely-typed payloads.

Chapter 9, Securing gRPC Endpoints in Your ASP.NET Core Application with SSL/TLS, explains that just like any standard HTTP endpoint, gRPC endpoints can be secured with SSL or TLS encryption and made accessible via the HTTPS protocol. This chapter will show you how to enable this encryption and protocol.

Chapter 10, Applying Authentication and Authorization to gRPC Endpoints, explains that, if needed, gRPC endpoints can be made accessible only to authenticated users or users with specific permissions. This chapter shows how to enable this functionality for gRPC endpoints on .NET.

Chapter 11, Using Logging, Metrics, and Debugging in gRPC on .NET, explains that it's important to be able to identify problems with an application while it is being developed. It's also important to monitor what the application is doing once it's been deployed. This chapter shows how to do all of these things. You will learn how to debug an application that's under development and how to use logging and metrics inside an application that has already been deployed.