Defining Services and Messages with Protobuf IDL
Write .proto contracts and generate type-safe client and server stubs from them.
Why an IDL?
In a gRPC microservice, the contract comes before the code. You describe your data and your RPC methods in a language-neutral Interface Definition Language (IDL) called .proto, then generate type-safe stubs for Node.js, Go, Java, and more from that single file.
- One
.protofile is the single source of truth shared by client and server. - Protocol Buffers (protobuf) is both the IDL and the binary wire format.
- You never hand-write the serialization code — the compiler does it.
This lesson shows how to write .proto contracts and turn them into JavaScript client and server stubs.
Anatomy of a .proto file
Every modern .proto file starts by declaring the syntax version and a package. The package namespaces your symbols so two services can both define a User without colliding.
syntax = "proto3";— always use proto3 for new services.package— logical namespace, maps to a JS object path after generation.- The file groups
message(data shapes) andservice(RPC methods).
// user.proto
syntax = "proto3";
package users.v1;
// A data shape sent over the wire
message User {
string id = 1;
string email = 2;
bool active = 3;
}All lessons in this course
- Defining Services and Messages with Protobuf IDL
- Unary, Server, Client, and Bidirectional Streaming RPCs
- Interceptors, Deadlines, and Metadata
- Proto Evolution and Backward Compatibility