We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
2 system design questions lean on this idea. Each walks through the full answer.
System Design Masterclass · Api Design Protocols
Free preview: the first 2 parts of this 11-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Api Design Protocols
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
It is easy and good
“It is really nice and good Please join the course”
REST works great for the web. Human-readable JSON, simple verbs, universal tooling. But behind the scenes, microservices at Google, Netflix, Square, and Spotify need something faster. Much faster.
When Service A calls Service B 100,000 times per second, every byte of overhead matters. JSON parsing is slow. HTTP/1.1 creates a new connection per request (or blocks on the existing one). Text-based headers eat . No native streaming support.
Google built gRPC (Google Remote Procedure Call) to solve these problems for their internal services, where millions of communicate billions of times per day. It uses Protocol Buffers (binary serialization, 3-10x smaller than JSON), HTTP/2 (multiplexed connections, bidirectional streaming), and auto-generated client/server code from a service definition file.
The result: gRPC is typically 5-10x faster than REST for service-to-service communication. But it is not meant for browsers (though gRPC-Web exists). It is designed for backend services talking to backend services, where performance trumps human readability.
Cloudflare's internal handles over 32 million requests per second between edge services. They use gRPC for the speed and the type safety that comes from shared .proto files across their Go and Rust services.
Every gRPC service starts with a .proto file, a language-neutral definition of the service's methods and message types:
syntax = "proto3";
service OrderService {
// Unary: one request, one response
rpc GetOrder (GetOrderRequest) returns (Order);
// Server streaming: one request, stream of responses
rpc ListOrders (ListOrdersRequest) returns (stream Order);
// Client streaming: stream of requests, one response
rpc UploadOrders (stream Order) returns (UploadSummary);
// Bidirectional streaming: streams in both directions
rpc OrderChat (stream OrderMessage) returns (stream OrderMessage);
}
message GetOrderRequest {
string order_id = 1; // Field number, not value
}
message Order {
string id = 1;
string customer_id = 2;
double total = 3;
OrderStatus status = 4;
repeated LineItem items = 5;
}
enum OrderStatus {
PENDING = 0;
PAID = 1;
SHIPPED = 2;
}
The protoc compiler generates client and server code in any language. Go, Java, Python, C++, Node.js, Rust, C#. The generated code handles serialization, deserialization, connection management, and error handling. You just implement the business logic.
The four communication patterns:
| Pattern | Request | Response | Use Case |
|---|---|---|---|
| Unary | Single | Single | Standard request-response (GetOrder) |
| Server streaming | Single | Stream | Live feeds, large dataset download (ListOrders) |
| Client streaming | Stream | Single | File upload, sensor data collection (UploadOrders) |
| Bidirectional | Stream | Stream | Chat, real-time collaboration (OrderChat) |