gRPC API Development for Microservices and Web Apps
Imagine a microservice architecture with dozens of services, each communicating via REST. As load grows, problems arise — latency increases, type errors sneak into production, and integration requires constant contract negotiation. For real-time functionality, you have to reinvent the wheel with WebSocket. We've been down this path multiple times, and gRPC has become our standard tool for internal APIs.
gRPC is an RPC framework from Google based on Protocol Buffers and HTTP/2. It provides strict typing via .proto files, bidirectional streaming, and significantly lower overhead compared to JSON. It's most suitable for inter-service communication and mobile clients with limited bandwidth.
Why gRPC is Faster Than REST
Performance of gRPC is 5–10 times higher on large messages thanks to binary packing and HTTP/2 multiplexing. In our workloads, switching from REST to gRPC reduced response time from 45 ms to 8 ms, and traffic decreased by 60% due to compact protobufs. This is especially critical for services with high request frequency — for example, data aggregators or payment systems.
What Are Protocol Buffers?
The service contract is defined in .proto files:
syntax = "proto3";
package articles.v1;
import "google/protobuf/timestamp.proto";
message Article {
string id = 1;
string title = 2;
string body = 3;
string author_id = 4;
repeated string tag_ids = 5;
google.protobuf.Timestamp created_at = 6;
}
message GetArticleRequest { string id = 1; }
message ListArticlesRequest {
int32 page = 1;
int32 limit = 2;
string status = 3;
}
message ListArticlesResponse {
repeated Article articles = 1;
int32 total = 2;
}
service ArticleService {
rpc GetArticle(GetArticleRequest) returns (Article);
rpc ListArticles(ListArticlesRequest) returns (ListArticlesResponse);
rpc CreateArticle(CreateArticleRequest) returns (Article);
rpc WatchArticle(GetArticleRequest) returns (stream Article);
}
Code is generated from .proto for any language: protoc --go_out=. --go-grpc_out=.. Generating clients for TypeScript or Python is a couple of commands.
Server Implementation in Go with Interceptors
type ArticleServer struct {
pb.UnimplementedArticleServiceServer
db *sql.DB
}
func (s *ArticleServer) GetArticle(ctx context.Context, req *pb.GetArticleRequest) (*pb.Article, error) {
row := s.db.QueryRowContext(ctx, "SELECT id, title, body FROM articles WHERE id = $1", req.Id)
var a pb.Article
if err := row.Scan(&a.Id, &a.Title, &a.Body); err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, status.Error(codes.NotFound, "article not found")
}
return nil, status.Error(codes.Internal, err.Error())
}
return &a, nil
}
// Starting the server
lis, _ := net.Listen("tcp", ":50051")
grpcServer := grpc.NewServer(grpc.UnaryInterceptor(authInterceptor))
pb.RegisterArticleServiceServer(grpcServer, &ArticleServer{db: db})
grpcServer.Serve(lis)
Interceptors are analogous to middleware: authentication, logging, tracing (OpenTelemetry), rate limiting. Example interceptor:
func authInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return nil, status.Error(codes.Unauthenticated, "missing metadata")
}
token := md.Get("authorization")
if !validateToken(token[0]) {
return nil, status.Error(codes.Unauthenticated, "invalid token")
}
return handler(ctx, req)
}
We configure a chain of interceptors to isolate cross-cutting concerns from business logic.
How gRPC Supports Streaming
gRPC offers four interaction types:
// Unary (standard request/response)
rpc GetArticle(Request) returns (Response);
// Server streaming (one request → stream of responses)
rpc WatchUpdates(Request) returns (stream Event);
// Client streaming (stream of requests → one response)
rpc UploadChunks(stream Chunk) returns (UploadResult);
// Bidirectional streaming
rpc Chat(stream Message) returns (stream Message);
Server streaming is convenient for real-time notifications, exporting large volumes of data, and live search results. On one IoT platform project, we used bidirectional streaming for telemetry transmission from hundreds of devices — latency was under 20 ms.
gRPC in the Browser and Modern Alternatives
gRPC doesn't work directly in the browser due to HTTP/2 binary framing limitations. Solutions:
- gRPC-Web — a special protocol with an Envoy proxy on the server side.
- Connect (Buf) — a modern alternative that works with HTTP/1.1 and HTTP/2, compatible with gRPC.
buf generate --template buf.gen.yaml
Buf also provides a Schema Registry for centralized storage of .proto files and contract versioning.
What's Included in gRPC API Development
| Deliverable | Description |
|---|---|
| .proto contracts | Designing and versioning contracts |
| Code generation | Automatic generation of clients for Go, TypeScript, Python |
| Server side | Business logic implementation, interceptors, streaming |
| gRPC-Web integration | Configuring Envoy or Connect for browser clients |
| Documentation | Auto-generated documentation from .proto (Buf Schema Registry) |
| Testing | Unit, integration, and load testing |
| Monitoring | Metrics via OpenTelemetry, logging |
How to Develop a gRPC API: Step-by-Step Guide
- Define contracts in
.protofiles, design all message types and RPC methods. - Generate server and client code using
protocorbuf generate. - Implement server business logic, add interceptors for authentication and logging.
- Set up streaming if real-time data transfer is required.
- Integrate with gRPC-Web or Connect if clients are browser-based.
- Test the API with gRPCurl or Postman, verify type safety.
- Deploy services to Kubernetes, connect monitoring via OpenTelemetry.
Example using gRPCurl
grpcurl -plaintext localhost:50051 articles.v1.ArticleService/GetArticle
gRPC vs REST: Comparison
| Parameter | gRPC | REST |
|---|---|---|
| Data format | Protocol Buffers (binary) | JSON/XML (text) |
| Protocol | HTTP/2 | HTTP/1.1 / HTTP/2 |
| Streaming | Supported (all 4 types) | None (needs WebSocket) |
| Contract | Strict (.proto) | Loose (OpenAPI) |
| Performance | High (low overhead) | Medium |
| Browser support | Via gRPC-Web/Connect | Native |
Source: official gRPC documentation
When to Choose gRPC?
gRPC is justified for inter-service communication within one infrastructure, when a strict contract between teams is needed, for efficient binary protocol in IoT and mobile apps, and when bidirectional streaming is required. For public APIs and browser clients without gRPC-Web, REST or GraphQL are usually better choices. Request a consultation — we'll help you decide.
Our Experience
With over 10 years of experience building high-load APIs for fintech, e-commerce, and IoT, and a portfolio of 50+ successful projects in Go and TypeScript, we guarantee reliability and performance for your gRPC solution. Contact us for a project assessment.







