Compare a browser-facing address book with an internal streaming service. See how client support, caching and schema changes affect the choice.
· 2 min read
Last updated on

gRPC or REST for a Go API? Choose by client and workload


For a public Go API that people will call from a browser or a shell, an HTTP resource with a JSON representation is a good starting point. For internal services that you deploy together and that exchange a stream of typed messages, consider gRPC. HTTP version alone cannot decide this: both designs can run over HTTP/2.

What does the same address book look like in each design?

Suppose you need to display a contact in a browser and push changes to an internal search index. The browser could fetch GET /people/42 with the ordinary Fetch API and receive JSON. If the service supplies an ETag, a returning client can send If-None-Match and get a 304 when the representation is still current. Choose cache controls appropriate to who may read the contact. HTTP conditional requests

The indexer has a different job. It wants one connection that delivers a sequence of changes using a contract shared with the Go service. Here is a complete protobuf definition for that interface:

syntax = "proto3";
package contacts;

service Directory {
  rpc WatchPeople(WatchRequest) returns (stream PersonChange);
}
message WatchRequest { string after_cursor = 1; }
message PersonChange {
  string cursor = 1;
  string person_id = 2;
  string display_name = 3;
}

The indexer can persist the cursor after applying each change and send it again on reconnect. The server has to implement replay and document cursor expiry. Declaring a streaming RPC supplies the stream; the application supplies those recovery guarantees. gRPC core concepts

Which trade-offs matter in Go?

QuestionHTTP resource APIgRPC
Who writes the client?Browsers, shell scripts and external callers can issue ordinary HTTP requests.Protobuf definitions and generated clients give teams a shared contract. Browsers commonly use gRPC-Web with a compatible proxy.
How are changes delivered?Polling, conditional requests or server-sent events can fit a browser client.Native gRPC supports unary, server-streaming, client-streaming and bidirectional methods. Check the chosen browser client’s streaming support.
How do consumers detect breaking changes?Define a contract, e.g. with OpenAPI, and test existing clients against it.Keep protobuf field numbers stable, reserve retired numbers, and check compatibility before release.
Which will be faster?Measure representative payloads, concurrency and connection reuse.Measure the same workload, including serialization and streaming overhead. The protocol name gives no latency guarantee.

For the address book, I would expose the cacheable resource to the browser and give the indexer the streaming RPC if a maintained event stream is already part of the service. A small application that only needs occasional lookups can serve both clients with the resource API. Adding the second interface buys something only when a particular client needs it. gRPC-Web browser support · Protobuf field compatibility

If you choose gRPC, the next design decision is which status code to return. The production gRPC course covers implementing, testing and deploying those services in Go.