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

推荐订阅源

B
Blog RSS Feed
J
Java Code Geeks
H
Help Net Security
Google DeepMind News
Google DeepMind News
博客园 - 司徒正美
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
Stack Overflow Blog
Stack Overflow Blog
D
DataBreaches.Net
The GitHub Blog
The GitHub Blog
S
SegmentFault 最新的问题
U
Unit 42
博客园 - 三生石上(FineUI控件)
Last Week in AI
Last Week in AI
M
MIT News - Artificial intelligence
WordPress大学
WordPress大学
小众软件
小众软件
博客园 - 叶小钗
D
Docker
量子位
P
Proofpoint News Feed
博客园_首页
T
Tailwind CSS Blog
F
Fortinet All Blogs

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
🚀 REST vs gRPC Performance in Go: A Practical Benchmark-D...
Chiman Jain · 2026-04-24 · via DEV Community
Cover image for 🚀 REST vs gRPC Performance in Go: A Practical Benchmark-Driven Guide

Chiman Jain

When building high-performance microservices in Go, one question inevitably comes up:

Should you use REST or gRPC?

This isn’t just an architectural debate it directly impacts latency, throughput, infrastructure cost, and scalability. In this post, we’ll break down REST vs gRPC performance using real benchmarks, practical Go examples, and production insights.


🧠 Understanding the Core Difference

Before diving into benchmarks, it’s important to understand why performance differs.

REST

  • Uses HTTP/1.1 (typically)
  • Data format: JSON (text-based)
  • Stateless, resource-oriented

gRPC

  • Uses HTTP/2
  • Data format: Protocol Buffers (binary)
  • Supports streaming (bi-directional)

Why This Matters

  • Binary serialization is more compact and faster to parse
  • HTTP/2 enables multiplexing multiple requests over a single connection
  • Reduced payload size = faster network transfer

⚙️ Benchmark Setup (Go)

Reference repository:

👉 https://github.com/chimanjain/go-rest-grpc-bencmark

This project benchmarks:

  • REST API (JSON over HTTP)
  • gRPC API (Protobuf over HTTP/2)

Typical Test Conditions

  • Concurrent clients
  • Small to medium payload sizes
  • High request volume
  • Controlled environment for fair comparison

📊 Benchmark Results (What Actually Happens)

Across benchmarks (including the referenced repo), a few consistent patterns emerge.

🔥 Key Observations

  • gRPC shows:

    • Lower latency
    • Higher throughput
    • Better CPU efficiency
  • REST:

    • Performs well at low scale
    • Degrades faster under heavy load due to parsing and connection overhead

🧾 Why gRPC Is Faster

Factor REST gRPC
Serialization JSON (text) Protobuf (binary)
Transport HTTP/1.1 HTTP/2
Payload Size Larger Smaller
Parsing Cost Higher Lower
Streaming Limited Native

🧪 Sample Go Implementations

🌐 REST Example (net/http)

package main

import (
    "encoding/json"
    "net/http"
)

type User struct {
    ID   string `json:"id"`
    Name string `json:"name"`
}

func getUser(w http.ResponseWriter, r *http.Request) {
    user := User{ID: "1", Name: "John"}

    w.Header().Set("Content-Type", "application/json")
    json.NewEncoder(w).Encode(user)
}

Enter fullscreen mode Exit fullscreen mode


⚡ gRPC Example

package main

import (
    "context"
    pb "example/proto"
)

type server struct {
    pb.UnimplementedUserServiceServer
}

func (s *server) GetUser(ctx context.Context, req *pb.UserRequest) (*pb.UserResponse, error) {
    return &pb.UserResponse{
        Id:   "1",
        Name: "John",
    }, nil
}

Enter fullscreen mode Exit fullscreen mode


⚖️ Key Difference

  • REST: manual serialization using encoding/json
  • gRPC: strongly typed, auto-generated code via .proto files

📈 Performance Deep Dive

1. Latency

  • gRPC typically achieves lower p99 latency
  • Especially noticeable with:

    • High concurrency
    • Small payloads

Reason: smaller payloads + faster serialization


2. Throughput

  • gRPC supports more requests per second
  • HTTP/2 multiplexing reduces connection overhead

3. CPU Usage

  • JSON parsing is CPU-intensive
  • Protobuf significantly reduces CPU overhead

4. Network Efficiency

  • Protobuf messages are smaller than JSON
  • Less bandwidth usage leads to faster transfers

🤔 When REST Performs Just Fine

Despite the performance gap, REST is still a solid choice in many scenarios:

  • Low to moderate traffic
  • Large payloads (compression reduces differences)
  • Public APIs and browser-based clients
  • Faster development and easier debugging

In many real-world systems, the performance difference is not critical.


🧩 Real-World Tradeoffs

Choose gRPC when:

  • Internal microservices communication
  • High-throughput or low-latency systems
  • Real-time streaming (e.g., chat, telemetry)
  • Strong contract enforcement is needed

Choose REST when:

  • Building public-facing APIs
  • Browser compatibility is required
  • Simplicity and ecosystem support matter

Common Industry Pattern

Use gRPC internally and REST externally

This gives you performance where it matters and compatibility where it’s needed.


🧠 Key Takeaways

  • gRPC is faster by design due to:

    • HTTP/2
    • Protobuf serialization
    • Efficient connection handling
  • REST is:

    • Simpler
    • More widely supported
    • “Fast enough” for many applications

🏁 Final Thoughts

Performance decisions should always be context-driven.

  • Building high-scale backend systems? → gRPC
  • Building public APIs? → REST

The best architecture often combines both.


🔗 References


💬 If you’ve run your own benchmarks in Go, feel free to share your results!