惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
Jina AI
Jina AI
月光博客
月光博客
博客园 - Franky
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
Visual Studio Blog
有赞技术团队
有赞技术团队
V
V2EX
IT之家
IT之家
阮一峰的网络日志
阮一峰的网络日志
Stack Overflow Blog
Stack Overflow Blog
H
Help Net Security
Apple Machine Learning Research
Apple Machine Learning Research
腾讯CDC
D
DataBreaches.Net
Hugging Face - Blog
Hugging Face - Blog
Martin Fowler
Martin Fowler
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
WordPress大学
WordPress大学
C
Check Point Blog
Microsoft Azure Blog
Microsoft Azure Blog
Microsoft Security Blog
Microsoft Security Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
When to choose gRPC over REST and Other Alternatives?
Hossein Esmati · 2026-06-26 · via DEV Community

Hossein Esmati

Quick Decision Tree: Which to choose?

  • Public APIs / external clientsREST (simple, widely compatible).
  • Internal service-to-service (microservices)gRPC (typed, fast, low-latency).
  • Streaming data pipelinesgRPC streaming or SignalR (depending on consumer type).
  • Frontend-heavy apps (Blazor/React)GraphQL if you want client-driven queries; otherwise REST with projections is simpler.
  • Real-time dashboards, chat, trading feedsSignalR/WebSockets.
  • Data-heavy querying → consider OData or GraphQL for flexible filters.

✅ My Recommendation for .NET 9:

  • Use REST at the edges (public endpoints, B2B).
  • Use gRPC for internal service-to-service calls between projects (AppHost, backends, workers).
  • Consider GraphQL if your frontends need flexible data shaping.
  • Add SignalR for real-time streaming to browsers.

1. Core Concepts

1.1) REST (Representational State Transfer)

  • Transport: HTTP/1.1 (can also run on HTTP/2/3).
  • Format: Typically JSON (but can be XML, HAL, etc.).
  • Style: Resource-oriented, CRUD-like verbs (GET/POST/PUT/DELETE).
  • Strengths:

    • Simple, universally understood, widely supported by tooling.
    • Works well for public APIs and external consumers.
  • Weaknesses:

    • Over-fetching/under-fetching (fixed DTOs).
    • Less efficient serialization compared to binary protocols.
    • No native streaming (must fake it with chunked responses, SignalR, or SSE).

1.2) gRPC

  • Transport: HTTP/2 (HTTP/3 support coming in .NET 9).
  • Format: Protocol Buffers (binary, compact, schema-driven).
  • Style: RPC (Remote Procedure Calls), proto-first design.
  • Strengths:

    • Low latency: Binary serialization and multiplexed HTTP/2 streams reduce overhead.
    • Strong typing: Proto schema compiles into C# types; no runtime surprises.
    • Streaming: Native support for server streaming, client streaming, and bidirectional.
    • Best for internal service-to-service (S2S) calls within a microservice mesh.
  • Weaknesses:

    • Harder for browser/JS clients (though gRPC-Web mitigates this).
    • Tooling is heavier (must manage .proto files and codegen).
    • Debugging is less straightforward than JSON over HTTP.

1.3) Other Alternatives

  • GraphQL: Flexible queries, avoids over/under-fetching. Best for frontend-heavy apps with diverse client needs. Slightly heavier CPU compared to REST projections.
  • SignalR / WebSockets: Real-time bidirectional messaging. Best for notifications, dashboards, chat, trading, telemetry. Not a general-purpose API style.
  • OData: REST with query semantics ($filter, $select, $expand). Good for data-heavy apps but complex and less popular today.
  • JSON-RPC: Lightweight RPC over HTTP. Rare in .NET ecosystem compared to gRPC.

2. Key Terms to know about

  • Low latency: gRPC avoids JSON serialization/deserialization overhead by using Protocol Buffers (binary).
  • Typed: Strongly typed contracts generated from .proto files → compile-time safety.
  • Internal S2S calls: Ideal inside a microservice cluster or Aspire-based distributed app, where both ends are .NET or support Protobuf.

2.1) Streaming

  • gRPC natively supports:
    • Unary (request → response, like REST).
    • Server streaming (one request → many responses, e.g. live feed).
    • Client streaming (many requests → one response).
    • Bidirectional streaming (both sides send streams simultaneously).
  • REST needs hacks (polling, SignalR, SSE) for this.

2.2) HTTP/2

  • Multiplexes multiple streams over a single TCP connection (fewer sockets, less head-of-line blocking).
  • Header compression (HPACK) saves bandwidth.
  • Required by gRPC (classic implementation).

2.3) Proto-first design

  • Define schema in .proto files:
  service OrderService {
    rpc GetOrder (GetOrderRequest) returns (OrderResponse);
    rpc StreamOrders (OrderFilter) returns (stream OrderResponse);
  }

  • From this, C# classes and service stubs are generated. The schema is the contract—language-neutral and stable.
  • Helps maintain backward/forward compatibility (additive fields, field numbers fixed).

3. REST vs gRPC vs Alternatives

Aspect REST gRPC GraphQL SignalR/WebSockets
Perf (latency/CPU) Higher (JSON parsing, more bytes) Lowest (binary, compact) Medium (parsing & resolver overhead) Low latency
Typed contracts JSON schema optional Proto = strongly typed Schema strongly typed Custom, looser typing
Streaming No (workarounds needed) Yes, native (uni/bi-directional) Subscription queries (but heavier) Yes, designed for real-time
Browser support Native Needs gRPC-Web Native Native
Use case fit Public APIs, external consumers Internal microservices, high-perf S2S, streaming Complex client-driven queries Real-time updates
.NET 9 support Minimal APIs, controllers, JSON source-gen → very fast First-class gRPC support, HTTP/3 coming HotChocolate GraphQL SignalR (mature)
.NET Aspire fit Easy integration with frontends, API gateways Perfect for inter-service calls inside Aspire distributed app Good for complex UI queries in Aspire frontends Aspire dashboard/telemetry scenarios