Golang / GoLang System Architecture and Testing Interview Questions
Compare REST/JSON with gRPC/Protocol Buffers. When would you choose gRPC for a Go microservice?
REST and gRPC solve the same problem — remote procedure calls — but make very different trade-offs. Understanding these trade-offs is central to microservice architecture decisions.
| Aspect | REST / JSON | gRPC / Protobuf |
|---|---|---|
| Protocol | HTTP/1.1 or HTTP/2 | HTTP/2 (mandatory) |
| Serialisation | JSON: text, ~30 bytes/field, human-readable | Protobuf: binary, ~3-5 bytes/field, 5-10× smaller |
| Schema | Optional (OpenAPI), not enforced at compile time | Required (.proto file), compile-time checked |
| Code generation | Optional | Required (protoc + language plugins) |
| Browser support | Native | Needs grpc-web proxy layer |
| Streaming | Workarounds: SSE, WebSockets | Built-in: unary, server, client, bidirectional |
| Latency | Higher (text parsing overhead) | Lower (binary + HTTP/2 multiplexing) |
| Best for | Public APIs, browser clients, simple integrations | Internal service-to-service, high-throughput, typed contracts |
// user.proto
syntax = "proto3";
package user;
service UserService {
rpc GetUser(GetUserRequest) returns (User); // unary
rpc StreamUsers(Empty) returns (stream User); // server streaming
rpc BatchCreate(stream CreateUserRequest) // client streaming
returns (BatchCreateResponse);
rpc Chat(stream Message) returns (stream Message); // bidirectional
}
message GetUserRequest { int64 id = 1; }
message User {
int64 id = 1;
string name = 2;
string email = 3;
}
// Generate Go code:
// protoc --go_out=. --go-grpc_out=. user.protoWhy Go excels at gRPC: Go's goroutine model maps naturally to gRPC's concurrent streaming model. Each RPC handler runs in its own goroutine; the Go runtime multiplexes thousands of concurrent streams efficiently. Protobuf's generated Go code is idiomatic and integrates with Go's type system. Go's standard net/http and context packages align with gRPC's design.
Decision guide: choose gRPC for internal service-to-service calls where typed contracts, performance, and streaming matter. Use REST/JSON for public APIs consumed by browsers or third parties where human readability and broad tooling matter.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
