Spring Boot 3 + gRPC - Types of gRPC
In this tutorial we will look at the different gRPC types. We need different types of gRPC calls to be used in different use cases. Each type of gRPC provides a specific communication pattern, allowing developers to choose the most appropriate type based on their needs, resource constraints, and desired behavior. By offering various types, gRPC ensures flexibility and efficiency in handling different data exchange scenarios.

gRPC - Table of Contents
Spring Boot+ gRPC Hello World Example Spring Boot gRPC Server + C# gRPC Client Example Spring Boot 3 + gRPC - Types of gRPC Spring Boot 3 + gRPC Unary Example Spring Boot 3 + gRPC Server Streaming Example Spring Boot 3 + gRPC Client Streaming Example Spring Boot 3 + gRPC Bidirectional Streaming Example Spring Boot + gRPC Deadline Example Spring Boot + gRPC Error Handling Example Spring Boot + gRPC Error Handling - Using Trailer Metadata Spring Boot + gRPC Error Handling - Global Exception Handler Using GrpcAdvice
Video
This tutorial is explained in the below Youtube Video.Types of gRPC
-
Unary gRPC
Unary gRPC is a type of communication protocol that allows client-server interactions where the client sends a single request to the server and gets a single response back. This means that the client sends one piece of data to the server and waits for a response.
For example, if you want to fetch a single item from a database, authenticate a user, or perform a calculation and obtain the result, unary gRPC can be a good choice.
Use Case
Consider a banking service where the the client needs to get the account balance. For this a unary gRPC call is made to the server which returns the balances.service AccountBalanceService { rpc GetAccountBalance (AccountRequest) returns (AccountBalanceResponse) {} }
-
Server Streaming gRPC
Server streaming gRPC is a communication protocol that allows the server to send a stream of responses to the client. This pattern is useful in scenarios where the server needs to push a large amount of data or a continuous stream of updates to the client.
For example, it can be used for real-time updates like stock market prices, weather updates, news feeds, or even sending a large file in chunks.Use Case
Consider a banking service where the the client needs to get transaction information of 30 days. This transaction information is processed by the server. But this is very large information which cannot be sent to the client as a single response. So it is sent as stream to the client.service TransactionService { rpc streamTransactions(AccountRequest) returns (stream TransactionDetailList); }