Category: gRPC
-
gRPC Channel and Stub Lifecycle: How to Use Them Correctly in Real Applications
When developers first learn gRPC, they usually focus on getting their first remote call working. They create a channel, create a stub, send a request, receive a response, and feel satisfied that the system works. While this is a great starting point, real-world applications require a deeper understanding of how these components should be managed…
-
gRPC Client–Server Interaction
In earlier steps of a typical gRPC project, you usually focus on the server side first. You define your .proto file, generate source code using the Protocol Buffer compiler, implement the service, and start a gRPC server that exposes your API. Once that is done, you might test the API using tools or simple test…
-
gRPC Unary API Tutorial – Building a Simple Bank Service
1. Understanding Unary Communication in gRPC A unary RPC is the simplest communication pattern in gRPC. In a unary call: This is similar to a typical REST request–response interaction, but the internal implementation and protocol are very different because gRPC uses HTTP/2 and Protocol Buffers. To understand this clearly, we will create: The client will…
-
gRPC Communication Patterns
When developers first approach gRPC, they often assume that it works exactly like REST with a simple request–response cycle, but gRPC actually provides multiple communication patterns that allow much richer and more efficient interactions between clients and servers. Understanding these patterns is important because they directly influence how we design distributed systems, how we handle…
-
Protobuf Schema Evolution and Backward Compatibility
In real-world systems, APIs do not remain static. Requirements change, fields are added, names are improved, and sometimes structures evolve. When using Protocol Buffers, these changes must be handled carefully so that different versions of services can still communicate safely. This tutorial explains how Protobuf handles API changes, what happens when clients and servers use…
-
Field Numbers (Tags) in Protocol Buffers
When learning Protocol Buffers (Protobuf), many developers focus on message structure and data types but do not initially pay much attention to the numbers assigned to fields. These numbers, called field numbers or tags, are actually one of the most important parts of a Protobuf schema because they directly influence serialization, compatibility, and message size.…
-
Using optional in Proto3 for Presence Tracking
In earlier protobuf usage, wrapper types were the primary way to detect whether a primitive field was explicitly set or not. If you wanted methods like hasAge(), you had to use types such as Int32Value instead of plain int32. However, modern proto3 has introduced a much simpler and more natural mechanism: the optional keyword. This…
-
Using Protobuf Well-Known Types in Real Projects
When working with Protocol Buffers in simple demos, we often define all our own message types. However, in real production systems, repeatedly creating common utility messages is unnecessary and inefficient. Google already provides a set of reusable, standardized message types called Well-Known Types that cover many common needs. These types are designed to solve frequent…
-
Polymorphic Data Modeling in Protobuf with oneof
In Java, we commonly use interfaces and abstract classes to achieve polymorphism. A base type defines a contract, and multiple implementations provide different behaviors. For example, a Car interface might have a drive() method, and classes like SportsCar and LuxuryCar implement it differently. At runtime, the behavior depends on the concrete type passed. Protocol Buffers…
-
Default Values in Protocol Buffers
Default values in Protocol Buffers often surprise developers at first, especially those coming from typical Java object behavior. However, once you understand how Protobuf handles defaults, you realize that this design avoids many common problems, particularly null pointer issues. Instead of treating “unset” fields as null, Protobuf uses well-defined default values for every field type.…
