123DevOps··8 min read

What is gRPC? HTTP/2, Protocol Buffers, streaming, and deadlines in practice

Learn what gRPC is, how it uses HTTP/2 and Protocol Buffers, the four RPC types, why deadlines are mandatory, how it compares to REST, and how to run a Go server and client with the health checking service.

Kubernetes

When one service calls another hundreds of times per second, the details start to add up: JSON that has to be parsed, contracts that only exist in a document, hand-written clients in every language, timeouts nobody configured. gRPC was born to solve exactly this kind of service-to-service communication, with a strong contract, a compact binary format, and native streaming.

What gRPC is

gRPC is a high-performance, open source RPC (Remote Procedure Call) framework. You describe the service in a .proto file, and the compiler generates server and client code in your language. For the caller, a remote call looks like a local function call.

It was created by Google, which internally used an RPC infrastructure called Stubby; in 2015 the company decided to build its next version as an open project. gRPC joined the CNCF in February 2017 and, as of November 2026, it is an incubating project (check the project page). The license is Apache 2.0.

There is no single “gRPC”: there are per-language implementations, each with its own repository and versions. On the GitHub releases pages, the most recent ones I saw were v1.85.4 of grpc/grpc (the C++ core, used by Python, Ruby, PHP, and others) and v1.85.0 of grpc-go.

What problem it solves

  • Explicit contract: the .proto is the source of truth. Client and server are generated from it, and breaking changes show up at compile time, not in production.
  • Efficiency: Protocol Buffers messages are binary and smaller than the equivalent JSON, and serialization is cheaper on CPU.
  • Streaming: the server, the client, or both can send sequences of messages within the same call.
  • Polyglot: a Go service can be called by Java, Python, or C# clients generated from the same contract.
  • Built-in production features: deadlines, cancellation, metadata, standardized status codes, health checking, and client-side load balancing.

How it works

gRPC combines two pieces:

  • HTTP/2 as the transport: each call is a stream inside a TCP connection. Many streams run in parallel over the same connection (multiplexing), with binary framing and header compression (HPACK). The call status travels in HTTP/2 trailers.
  • Protocol Buffers as IDL and format: it defines services and messages, with numbered fields that let you evolve the contract without breaking older clients.

A .proto with the four RPC types:

syntax = "proto3";

package orders.v1;

service Orders {
  // unary: one request, one response
  rpc Get(GetRequest) returns (Order);
  // server streaming: the server sends many orders
  rpc List(ListRequest) returns (stream Order);
  // client streaming: the client sends many items and gets a summary
  rpc Import(stream Order) returns (ImportSummary);
  // bidirectional streaming: both sides send whenever they want
  rpc Track(stream Event) returns (stream Event);
}

message GetRequest    { string id = 1; }
message ListRequest   { string customer_id = 1; }
message Order         { string id = 1; int64 total_cents = 2; }
message ImportSummary { int32 imported = 1; }
message Event         { string order_id = 1; string status = 2; }
Type Request Response Typical use case
Unary 1 message 1 message Common queries and commands
Server streaming 1 message N messages Large listings, feeds, Watch
Client streaming N messages 1 message Batch uploads, telemetry
Bidirectional streaming N messages N messages Chat, sync, real-time control

Code is generated with protoc and each language’s plugins (in Go, protoc-gen-go and protoc-gen-go-grpc).

Deadlines

The gRPC documentation is clear: by default, gRPC does not set a deadline. Without one, a client can wait indefinitely on a stuck server, holding connections and memory. Always set a realistic deadline on the client. When it expires, the call ends with the DEADLINE_EXCEEDED status, and the server receives the cancellation. In Go, the deadline travels in the context; if the server passes that context to its own outgoing calls, the limit propagates down the whole chain of services.

Hands-on example

To run without protoc, the example uses the standard health checking service (grpc.health.v1.Health), which ships with generated code in the google.golang.org/grpc module. It has a unary call (Check) and a server streaming call (Watch). I built it with Go and google.golang.org/grpc v1.84.0.

mkdir grpc-demo && cd grpc-demo
go mod init example.com/grpc-demo
go get google.golang.org/[email protected]
mkdir server client

The server registers health checking and reflection, and changes the status of the orders service after one second:

// server/main.go
package main

import (
	"log"
	"net"
	"time"

	"google.golang.org/grpc"
	"google.golang.org/grpc/health"
	healthpb "google.golang.org/grpc/health/grpc_health_v1"
	"google.golang.org/grpc/reflection"
)

func main() {
	lis, err := net.Listen("tcp", "127.0.0.1:50051")
	if err != nil {
		log.Fatal(err)
	}

	srv := grpc.NewServer()
	hs := health.NewServer()
	healthpb.RegisterHealthServer(srv, hs)
	reflection.Register(srv) // lets tools such as grpcurl list the services

	// the "orders" service starts SERVING and, after 1s, becomes NOT_SERVING
	hs.SetServingStatus("orders", healthpb.HealthCheckResponse_SERVING)
	go func() {
		time.Sleep(1 * time.Second)
		hs.SetServingStatus("orders", healthpb.HealthCheckResponse_NOT_SERVING)
	}()

	log.Println("gRPC server listening on", lis.Addr())
	log.Fatal(srv.Serve(lis))
}

The client runs a Check with a 500 ms deadline and then a Watch with a 2 s deadline:

// client/main.go
package main

import (
	"context"
	"log"
	"time"

	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	healthpb "google.golang.org/grpc/health/grpc_health_v1"
	"google.golang.org/grpc/status"
)

func main() {
	conn, err := grpc.NewClient("127.0.0.1:50051",
		grpc.WithTransportCredentials(insecure.NewCredentials())) // local testing only!
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()
	client := healthpb.NewHealthClient(conn)

	// 1) Unary: one request, one response, with a 500 ms deadline
	ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
	defer cancel()
	resp, err := client.Check(ctx, &healthpb.HealthCheckRequest{Service: "orders"})
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Check:", resp.GetStatus())

	// 2) Server streaming: the server sends a message on every status change
	ctx2, cancel2 := context.WithTimeout(context.Background(), 2*time.Second)
	defer cancel2()
	stream, err := client.Watch(ctx2, &healthpb.HealthCheckRequest{Service: "orders"})
	if err != nil {
		log.Fatal(err)
	}
	for {
		msg, err := stream.Recv()
		if err != nil {
			st := status.Convert(err)
			log.Printf("Watch ended: code=%s msg=%q", st.Code(), st.Message())
			return
		}
		log.Println("Watch:", msg.GetStatus())
	}
}
go run ./server &
go run ./client

The client’s real output:

2026/11/25 04:53:54 Check: SERVING
2026/11/25 04:53:54 Watch: SERVING
2026/11/25 04:53:55 Watch: NOT_SERVING
2026/11/25 04:53:56 Watch ended: code=DeadlineExceeded msg="context deadline exceeded"

Look at the stream: the server sent two messages, one per status change, and the call ended exactly when the 2 s deadline expired. With reflection enabled, grpcurl can explore the server without the .proto (commands as per the official documentation; I did not run grpcurl in this test):

grpcurl -plaintext localhost:50051 list
grpcurl -plaintext -d '{"service":"orders"}' localhost:50051 grpc.health.v1.Health/Check

On Kubernetes, this same health checking service powers the native gRPC probes:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: orders
spec:
  replicas: 2
  selector:
    matchLabels:
      app: orders
  template:
    metadata:
      labels:
        app: orders
    spec:
      containers:
      - name: orders
        image: ghcr.io/your-org/orders:1.0.0
        ports:
        - containerPort: 50051
        readinessProbe:
          grpc:
            port: 50051
            service: orders
          periodSeconds: 5

gRPC or REST?

If you’re coming from the other side, see what is a REST API.

gRPC REST (JSON over HTTP)
Contract Mandatory .proto, generated code Optional (OpenAPI)
Format Protocol Buffers (binary) JSON (text, human-readable)
Transport HTTP/2 HTTP/1.1, HTTP/2, or HTTP/3
Streaming Native, both directions Limited (SSE, WebSockets separately)
Browser Needs gRPC-Web and a proxy Direct support
Debugging grpcurl, reflection curl, any browser
HTTP caching Doesn’t benefit Benefits (GET, ETag, CDN)
Best for Internal service-to-service communication Public APIs and integrations

When to use it (and when not to)

Use gRPC when:

  • the communication is between services you control, with high volume or tight latency;
  • several teams in different languages need the same contract;
  • there are real streaming flows, such as events, sync, or Watch.

Prefer REST when:

  • the API is public or consumed by partners, browsers, and third-party tools;
  • HTTP caching and CDNs matter;
  • the team benefits more from the simplicity of debugging with curl.

A Kubernetes trap: gRPC keeps long-lived HTTP/2 connections, and kube-proxy balances per connection, not per request. The result is one pod receiving almost all the traffic. Fix it with an L7 proxy such as Envoy, a service mesh such as Istio, or client-side load balancing with a headless Service.

Alternatives

Option Idea
REST + OpenAPI Optional contract, JSON, maximum compatibility
GraphQL The client picks the fields; good for frontends
Connect RPC Compatible with gRPC and with plain HTTP/JSON calls
Apache Thrift IDL and binary RPC, with a long history outside the gRPC ecosystem

Summary

  • gRPC is an RPC framework created by Google, CNCF incubating (as of November 2026)
  • It uses HTTP/2 as the transport and Protocol Buffers as contract and format
  • Four RPC types: unary, server streaming, client streaming, and bidirectional
  • There is no deadline by default: always set one on the client
  • The grpc.health.v1.Health service powers Kubernetes gRPC probes
  • For public APIs and browsers, REST is usually the better choice
  • Long-lived connections require L7 or client-side load balancing

gRPC trades JSON’s freedom for a strict contract, and between services that strictness almost always pays off.

Get updates on new posts and stay in the loop!