open source · conference talk
One schema, the whole backend.
How a single .proto becomes storage, services, REST, streams, SDKs and AI tools.
Who I am · Bengaluru
I work on seams: the places where two systems have to agree on something, and don’t.
Including a humanoid robot that guided patients through surgery in San Diego. Most of that work wasn’t robotics.
One queryable model of spaces, equipment and points over BACnet, KNX, DALI, OSDP and ONVIF, in Go and Rust.
Proto, migration, ORM model, OpenAPI, SDK. None could see the others. I wanted to write it once.
The inception
“I had the idea. I didn’t have a way to show it.”
Write the contract once; derive the database, the API and the clients from it. Nothing to show it with yet.
Proving it means a generator per target, each agreeing with the others. Too much to hand-write alone.
Building for real, with people I trust, asking one question: does a schema hold a whole backend?
Generate natively, compile, deploy whenever you like. The rest of this talk is how.
A short history
the contractHTML forms for people; WSDL and XML for machines.
the contractJSON won over XML. OpenAPI described it, beside the code, drifting from it.
the contractA contract ABI. The API on top is still a resource with CRUD.
the contractA JSON Schema per tool, an Agent Card per agent. A schema, again.
Layer one
POST /v1/shelves/1/books HTTP/1.1Host: api.shop.example.comContent-Type: application/json{"title": "Dune", "pages": "412"}
HTTP/1.1 201 CreatedContent-Type: application/json{"name": "shelves/1/books/42", "title": "Dune", "pages": "412"}
A verb, a path, headers, a body, a status code.
That title is required, that pages is a number (it just got a string), that shelf 1 exists.
In a wiki, an OpenAPI file, a Postman collection. Kept beside the code, where the two can drift.
Same meaning, binary frames, many streams on one connection. The ground gRPC is built on.
Layer two
Underlined: the tag, field number << 3 | wire type. No names on the wire, only numbers.
31 BSame message, same schema. gRPC's codec is pluggable: JSON, FlatBuffers, Cap'n Proto, or your own.
77 BLayer three
generated stub
generated base
Plus deadlines, cancellation, status codes and metadata, defined once for every language.
// the codec is a registry, not a givenimport "google.golang.org/grpc/encoding"type jsonCodec struct{}func (jsonCodec) Name() string { return "json" }func (jsonCodec) Marshal(v any) ([]byte, error) {return protojson.Marshal(v.(proto.Message))}// …Unmarshal likewiseencoding.RegisterCodec(jsonCodec{})// same service, same stub, JSON on the wire:client.GetBook(ctx, req,grpc.CallContentSubtype("json"))
Content type becomes application/grpc+json. FlatBuffers and Cap’n Proto plug in the same way.
Same thing, different names
Transport, encoding, call shape, contract. MCP and A2A included.
Only the top row is about your business. Write it once, and the supported columns below it are generated.
The usual way
Learn it from the people who built it
We learned protobuf as gRPC’s wire format. Google uses it as an API design language, and published how.
api-linter · in the editor and in CI
Each rule is named after its AIP. Each finding links to it.
$ api-linter shop/v1/book.protoshop/v1/book.proto:9:3core::0203::field-behavior-requiredgoogle.api.field_behavior annotation must be seton "title" and contain one of, {"IMMUTABLE","OPTIONAL", "OUTPUT_ONLY", "REQUIRED"}linter.aip.dev/203/field-behavior-required
// beforestring title = 2;// after the quick fixstring title = 2 [(google.api.field_behavior) = REQUIRED];
The schemais the network.
Not the JSON on the wire. The agreement underneath it. Write it down once, in a form a machine can read, and everything downstream is derived instead of authored.
— “Why this project exists”, the-protobuf-project.org/blog
Protobuf + Google AIP
syntax = "proto3";package shop.v1;message Book {option (google.api.resource) = {pattern: "shelves/{shelf}/books/{book}"};string name = 1 [(google.api.field_behavior) = IDENTIFIER];string title = 2 [(google.api.field_behavior) = REQUIRED,(buf.validate.field).string.max_len = 200];int32 pages = 3;string author = 4[(google.api.resource_reference).type = "shop.example.com/Author"];google.protobuf.Timestamp create_time = 5[(google.api.field_behavior) = OUTPUT_ONLY];}service BookService {rpc GetBook(GetBookRequest) returns (Book) {option (google.api.http) = { get: "/v1/{name=shelves/*/books/*}" };}}
Intermediate representation
Many inputs, one IR, many targets: N plus M parts instead of N times M.
int add(int a, int b) {return a + b;}
define i32 @add(i32 %a, i32 %b) {%sum = add i32 %a, %bret i32 %sum}
; x86-64lea eax, [rdi + rsi]ret; ARM64add w0, w0, w1ret
message Book {option (google.api.resource) = {pattern: "shelves/{s}/books/{b}"};string title = 2[(google.api.field_behavior) = REQUIRED];}
{"table": "books","parent": "shelves","columns": [{ "name": "name", "key": true },{ "name": "title", "required": true }]}
-- protoc-gen-storetitle TEXT NOT NULL,-- protoc-gen-mcp"required": ["title"]
How it works
Every plugin reads the same model, so no decision is reimplemented per output.
Twelve projects, one schema
protoc-gen-service
Recognised by name and shape alone. You write only the rule your business has.
type bookHooks struct {shopv1svc.NopBooksHooks // the rest: no-opsauthors shop.AuthorRepository}// A book's author must exist.func (h bookHooks) ValidateBook(ctx context.Context, _ servicex.Op,b *shopv1.Book, paths []string,) error {if !servicex.Touches(paths, "author") {return nil}_, err := h.authors.Get(ctx, b.GetAuthor())return servicex.NotFoundAs(err,"shop.example.com/Author", b.GetAuthor())}
runtime-go · runtime-rs
One request, every layer
Nine hops. One of them is code you wrote.
Same request, another database
Your hook and the generated code talk to one interface, never to a database.
// before: Postgres, through GORMp := orm.NewProvider(gormDB)// after: MongoDB, the only lines that changeclient, _ := mongodb.NewClient(ctx, cfg)p := mongodb.NewProvider(client)
// a second store: one more hookfunc (h bookHooks) AfterCreate(ctx context.Context, b *shopv1.Book) error {return h.graph.Create(ctx, b) // ArangoDB}
A second store is a consistency choice: when its write fails, you retry, queue it, or reconcile from the change feed. The hook is where that choice lives; it is not free.
protoc-gen-service app=shop
func provision(d *server.Deps) (server.Provision, error) {return server.Provision{// around the standard methodsHooks: server.Hooks{Books: bookHooks{d.Repos}},// the hybrid serverOptions: []grpc.Option{grpc.WithUnaryInterceptors(auth)},}, nil}func main() { app.Main(app.Options{Provider: provision}) }
$ buf generate # store, service, http, mcp, cache…$ go run ./cmd/shop # gRPC + REST + MCP on :8080
Case study · Freebusy
Availability and booking for courts, rooms and equipment. The application owns the booking rules.
Search
Hold
Settle elsewhere
Reserve
Repositories and service scaffolding
Models, filters, database access and standard API methods.
Booking rules and invariants
Availability, allocation and hold lifecycles. Postgres prevents overlapping claims.
gRPC · REST · MCP · CalDAV · Postgres · github.com/shokki-engineering/freebusy
Freebusy 1.0.0-rc.1 · repository-reported results
70 / 120 ms
p50 / p99 for the whole flow
4.4 / 14.8 ms
p50 / p99 with cache enabled
1,882 requests/s
Includes competing attempts
One shared M3 Max laptop · two application replicas · Postgres + Redis + k6 on kind
10,001 resources · most concurrent runs: 40 seconds · separate workloads, not a capacity guarantee
Schema first, all the way
One .proto with AIP annotations. Lint it in the editor as you type.
Go, Rust, TypeScript, SQL: real code in your language, byte-identical on rerun.
Typed end to end. Rename or remove a field and every generated client that uses it stops compiling.
One binary, one port. Swap a backend with a line of wiring.
idl2proto rebuilds its .proto contract
gnostic converts it to protobuf
the-protobuf-project.org/editor runs the real plugins
Thank you
I work on seams: the places where two systems have to agree on something, and don’t.