SERVICE GRPC
WITH
GOLANG
gRPC is a high-performance, open-source Remote Procedure Call (RPC) framework developed by Google. It lets applications running on different machines (or in different services) talk to each other as if they were calling local functions.
About GRPC
1. Protocol
- check_circle Uses HTTP/2 as the transport layer (faster, multiplexed connections, streaming support).
- check_circle Data is serialized with Protocol Buffers (protobuf) by default (compact, fast, strongly typed).
2. Cross-language
- check_circle Supports many languages: Go, Java, Python, C#, C++, Node.js, etc.
- check_circle A client written in one language can easily communicate with a server written in another.
3. Service definition
- check_circle You define your APIs in a .proto file.
- check_circle gRPC generates client and server code for you from this definition.
4. Communication styles
- check_circle Unary RPC (single request → single response)
- check_circle Server streaming (single request → stream of responses)
- check_circle Client streaming (stream of requests → single response)
- check_circle Bidirectional streaming (stream of requests ↔ stream of responses)
5. Use cases
- check_circle Microservices communication
- check_circle Low-latency real-time apps
- check_circle Connecting backend services in different languages
- check_circle Mobile to server communication
Requirements
- check_circle Go 1.23.11
- check_circle Go grpc
- check_circle Protobuf cmd
- check_circle Grpc cmd
Let's get start
Create folder learn-grpc then open it with Goland IDE
We have to prepare some dependencies first
Download go grpc
go get google.golang.org/grpc

Install protoc, im using mac so i will execute with syntax:
brew install protoc-gen-go-grpc

or you can install binary on GOBIN:

Init package project:
go mod init id.pandz/learn/grpc-sample from path /learn-grpc

Create folder name it student
Now, create student/student.proto file
syntax = "proto3";
option go_package = "id.pandz/learn/grpc-sample/student";
package student;
service DataStudent {
rpc FindStudentByEmail(Student) returns (Student);
}
message Student {
string name = 1;
int32 age = 2;
string email = 3;
}Then we need to generate student.proto to golang language

So it will generated files

Start server:

Run client to get data:

That's it!
Link code: Here
Reference: Extraodev