REST to gRPC Migration Guide
Migrating from REST (typically JSON over HTTP/1.1 or HTTP/2) to gRPC (Protocol Buffers over HTTP/2 with multiplexing, streaming, and type safety) improves performance, reduces bandwidth, enables bidirectional streaming, and enforces contracts via .proto files. However, it's not a flip-switch—plan for coexistence (running both in parallel), adapters (bridging old/new clients), telemetry (observability during transition), and training (team upskilling).
This guide assumes a microservices architecture (e.g., Go, Java, Node.js services) with Kubernetes/Envoy for deployment. Adapt as needed.
1. Preparation Phase
Assess Your Stack
Pitfalls
- REST is human-readable; gRPC is binary—use
protoc --decode for debugging.
- HTTP/2 required for gRPC (no HTTP/1.1 fallback).
2. Coexistence Strategies
Run REST + gRPC in parallel to avoid downtime. Goal: 100% coverage before deprecating REST.
Dual Endpoints (Simplest)
- Expose both on the same service:
// Go example with Gin (REST) + gRPC server
func main() {
// gRPC listener on :9090
lis, _ := net.Listen("tcp", ":9090")
s := grpc.NewServer()
pb.RegisterUserServiceServer(s, &server{})
go s.Serve(lis)
// REST on :8080
r := gin.Default()
r.GET("/users/:id", getUserHandler) // Delegates to gRPC impl
r.Run(":8080")
}
- Routing: Use API Gateway (Envoy, Kong, AWS API Gateway) to route
/v1/* → REST, /grpc/* → gRPC.
# Envoy config snippet
virtual_hosts:
- name: rest
domains: ["api.example.com"]
routes:
- match: { prefix: "/v1/" }
route: { cluster: rest_service }
- name: grpc
domains: ["grpc.example.com"]
routes:
- match: { prefix: "/" }
route: { cluster: grpc_service }
Gradual Rollout
| Strategy | Pros | Cons | Use Case |
|---|
| Feature Flags (e.g., LaunchDarkly) | Toggle per-user/service | Flag fatigue | Internal services |
| Canary Deployments (Kubernetes) | % traffic split | Complex metrics | High-traffic APIs |
| Strangler Pattern | Rewrite behind facade | Long-lived | Monoliths → Microservices |
| Versioned APIs | /v1/rest, /v2/grpc | Proliferation | Public APIs |
- Deprecation Plan: Announce 6-month sunset; redirect REST → gRPC (301) after.
3. Adapters & Proxies
Bridge legacy REST clients without rewrites.
gRPC-Gateway (Recommended)
Generates a reverse-proxy from .proto → RESTful JSON API.
# Install
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest
// Annotate proto for REST mapping
service UserService {
option (google.api.http) = {
get: "/v1/users/{id}"
};
rpc GetUser(GetUserRequest) returns (User) {}
}
# Generate
protoc -I. --grpc-gateway_out . user.proto
- Run:
grpc-gateway binary proxies gRPC calls, serves REST on :8080.
- Supports OpenAPI docs:
--openapi_out .
Other Adapters
| Tool | Language | Features |
|---|
| gRPC-Web | JS/TS, browsers | gRPC over HTTP/1.1/2 + Envoy proxy |
| Unidirectional Gateway | Any | REST → gRPC only (no vice versa) |
| Connect-ES | JS | gRPC + REST + gRPC-Web in one lib |
| Tyk/Kong | Gateways | Plugin-based translation |
4. Telemetry & Observability
Ensure visibility across both protocols. Use OpenTelemetry (OTel) for unified tracing/metrics/logs.
Setup
Key Metrics
| Metric | REST | gRPC | Tool |
|---|
| Requests/sec | http_server_requests_seconds | grpc_server_handled_total | Prometheus |
| Latency (p99) | Histogram | grpc_server_handling_seconds | Grafana |
| Error Rate | 5xx/4xx | grpc_server_handled_total{grpc_status_code="UNAVAILABLE"} | |
| Traffic Shift | Proxy logs | Envoy access logs | Loki |
- Tracing: Jaeger/Zipkin spans link REST → gRPC calls.
- Alerts: "gRPC traffic > 80% → Greenlight REST deprecation."
- Tools Stack: OTel Collector → Prometheus → Grafana + Loki.
Pitfalls
- gRPC status codes (e.g.,
UNAUTHENTICATED) ≠ HTTP 401—map in gateway.
- Streaming RPCs: Monitor
grpc_server_stream_messages_sent.
5. Training & Team Enablement
Skill gap kills migrations—invest upfront.
Resources
| Format | Resource | Time | Focus |
|---|
| Docs | grpc.io/docs | 2h | Core concepts |
| Tutorials | gRPC Quickstart | 4h | Hands-on proto/codegen |
| Courses | Udemy "gRPC [Lang]" or free YouTube (e.g., "gRPC 101") | 1 day | Full stack |
| Books | gRPC: Up and Running (O'Reilly) | 1 week | Advanced |
| Internal | Workshops: Proto design reviews, migration hackathons | Ongoing | Coexistence |
Training Plan
- Week 1: All-hands intro (1h) + proto best practices.
- Week 2-4: Pair programming for first 5 endpoints.
- Ongoing: Code owners for
.proto files; lint with buf.
- Metrics: Track "Endpoints migrated" + "Team gRPC proficiency survey."
Migration Checklist
Expected Wins: 50-80% latency drop, 70% bandwidth savings. Questions? Ping for lang-specific examples! 🕵️♂️