gRPC vs REST โ Choosing the Right Protocol
Decide between gRPC and REST for your .NET services: performance comparison, browser compatibility, tooling, streaming support, and the decision framework for internal vs external APIs.
The Core Difference
REST (JSON over HTTP/1.1 or HTTP/2):
Format: JSON โ human-readable, text-based
Contract: OpenAPI spec (often generated post-hoc)
Transport: HTTP verbs (GET, POST, PUT, DELETE)
Streaming: Possible but HTTP-based (SSE, WebSockets separate)
Browser: Native fetch/XMLHttpRequest support
Tooling: Universal (curl, Postman, browsers)
gRPC (Protobuf over HTTP/2):
Format: Binary โ compact, fast, not human-readable
Contract: .proto file (primary artifact, code-generated)
Transport: 4 patterns: unary, server streaming, client streaming, bidirectional
Streaming: Built-in, first-class feature
Browser: Requires gRPC-Web proxy or transcoder
Tooling: grpcurl, Postman gRPC, BloomRPCPerformance Comparison
Benchmark: sending 1,000 CreatePatient requests
REST (JSON):
Request size: ~200 bytes JSON
Response size: ~180 bytes JSON
Latency (avg): 3.2ms
Throughput: ~8,000 req/s
gRPC (Protobuf):
Request size: ~60 bytes binary (3x smaller)
Response size: ~50 bytes binary
Latency (avg): 1.1ms (3x faster)
Throughput: ~25,000 req/s (3x higher)
gRPC advantages:
โ Smaller payloads (Protobuf vs JSON)
โ Binary parsing faster than JSON text parsing
โ HTTP/2 multiplexing (multiple calls on one connection)
โ Header compression (HPACK)When to Choose gRPC
Choose gRPC for:
โ Internal service-to-service communication (no browser)
โ High-throughput data pipelines (device telemetry, observation ingestion)
โ Real-time streaming (vitals monitoring, lab result feeds)
โ Polyglot environments (C#, Java, Go, Python all use same .proto)
โ Strict API contracts with generated client code
โ Latency-sensitive paths (medication dispensing confirmation, alert routing)
โ When you have 10+ RPCs and want type-safe client generationWhen to Choose REST
Choose REST for:
โ Public-facing APIs consumed by browsers, third parties
โ Simple CRUD APIs with no streaming requirements
โ APIs that must be easily explored with curl or Postman
โ APIs consumed by mobile apps (iOS, Android โ better REST tooling)
โ Teams new to gRPC where onboarding cost outweighs benefits
โ Simple webhooks and callbacks
โ APIs where human-readable payloads aid debuggingMixed Architecture (Most Common in Production)
SystemForge Clinical API (production):
External facing (browsers, mobile apps, third parties):
REST + JSON โ /api/v1/patients, /api/v1/prescriptions
Internal service communication:
gRPC โ PharmacyService, LabService, NotificationService, BillingService
Real-time (ward dashboards, vitals monitoring):
SignalR (WebSocket) โ /hubs/clinical
This is not "REST vs gRPC" โ it is using the right tool for each context.gRPC-Web for Browser Support
// If you need browsers to call gRPC, add gRPC-Web transcoder
// NuGet: Grpc.AspNetCore.Web
app.UseGrpcWeb(new GrpcWebOptions { DefaultEnabled = true });
app.MapGrpcService<ClinicalPatientGrpcService>().EnableGrpcWeb();
// Browser uses fetch API via @grpc/grpc-js or grpc-web package
// Server transcodes gRPC-Web to standard gRPC internally
// Performance: some overhead vs native gRPC, but still better than REST/JSONAPI Contract Approaches
REST: API contract is an afterthought (usually)
Code first โ OpenAPI generated from code annotations
Contract drift is possible (annotations lag implementation)
Breaking changes detectable via schema diff tools
gRPC: contract is the source of truth
.proto first โ code generated FROM the contract
Implementation must match the contract exactly
Breaking changes detectable at compile time (field number changes)
Proto evolution rules enforce backward compatibilityDecision Framework
Is the caller a browser or public API consumer?
YES โ REST
NO โ consider gRPC
Does the call require streaming?
YES โ gRPC (first-class) or SignalR (WebSocket, better browser support)
NO โ either, but gRPC if performance matters
Is performance/throughput critical?
YES, high volume (>1000 req/s) โ gRPC
NO, standard web API โ REST is fine
Do you need a strict, versioned contract?
YES (multiple teams, polyglot clients) โ gRPC
NO (one team, one language) โ REST is simpler
Is the team familiar with gRPC?
YES โ gRPC for internal services
NO โ REST until team is ready (gRPC onboarding cost is real)gRPC Disadvantages (Honest Assessment)
gRPC disadvantages:
โ Binary format โ not human-readable (debugging requires grpcurl or reflection)
โ Browser support requires gRPC-Web proxy (not native fetch)
โ .proto file management (schema drift between services, shared library needed)
โ Steeper learning curve than REST
โ Less tooling than REST (though improving rapidly)
โ Firewall/proxy issues (some infrastructure does not support HTTP/2 trailers)
โ No native support for browser EventSource / SSE fallback
REST disadvantages:
โ Verbose JSON payloads (larger, slower parsing)
โ No native streaming (requires WebSockets or SSE separately)
โ No code-generated typed clients (requires OpenAPI codegen separately)
โ No formal streaming call semanticsRed Flag / Green Answer
Red Flag: "We use gRPC for everything โ our public API, our internal services, and our browser client โ because it is faster."
Browsers cannot call gRPC natively without a proxy. Third-party consumers expect REST. The performance advantage is irrelevant for a public API where latency is dominated by network RTT, not payload size. Using the wrong tool for the context adds complexity without benefit.
Green Answer:
REST for public-facing API (browsers, mobile apps, third parties). gRPC for internal service-to-service calls where latency and throughput matter. SignalR for real-time browser connectivity.
Key Takeaway
gRPC and REST are not competitors โ they are tools for different contexts. gRPC wins on performance, streaming, and strict contracts for internal services. REST wins on browser compatibility, simplicity, and universal tooling for external APIs. Production systems often use both: REST for public endpoints, gRPC internally. The decision should be based on who the caller is, whether streaming is needed, and whether the performance difference matters at your traffic level.
gRPC Knowledge Check
5 questions ยท Test what you just learned ยท Instant explanations
Found this helpful?
Leave a comment
Have a question, correction, or just found this helpful? Leave a note below.