Why gRPC isn’t faster than REST in Node.js
In my engineering thesis, a crypto portfolio tracker split into three Node.js services, the main API talks to the auth service over gRPC. I chose gRPC because I believed it was faster than REST. When I finally measured gRPC vs REST in Node.js, plain HTTP with JSON won on a fast network, so in my setup I was wrong. The same test in Go came out the other way: gRPC was as fast or faster almost everywhere. The slow part is the Node.js implementation, not the protocol.
Key takeaways
- gRPC is RPC over HTTP/2: you describe the service in a
.protofile and call remote methods like local functions.- In Node.js on a fast network, REST beat
@grpc/grpc-json small messages: 0.22–0.31 ms against 0.39–0.58 ms per call.- In Go the same small call was a tie, and gRPC was 2–3 times faster on large lists.
- In Node.js most of the large-message gap came from
@grpc/proto-loader: encoding through it took 35–41 ms, against 6–10 ms with ts-proto.- On slow links, 100 and 20 Mbit/s, gRPC won in both languages, because its messages are about 45% smaller.
What gRPC is
RPC, remote procedure call, means calling a function that runs on another machine as if it were local. gRPC is Google’s RPC framework: you write the service and its messages in a .proto file, a code generator turns it into a typed client and server stubs, and calls travel over HTTP/2 as binary Protocol Buffers.
The difference from REST is where the contract lives. In REST it’s a convention: the URL, the method, the shape of the JSON, maybe an OpenAPI file that can drift away from the code. In gRPC the .proto file is the contract, and both sides are generated from it.
How my thesis used gRPC

The React app talks to main-server over HTTPS. Every authenticated request then goes one level down: main-server asks auth-service over gRPC whether the session is valid. That service-to-service call runs on every request, so it was the one I cared about. The third service runs BullMQ jobs and doesn’t use gRPC at all.
The contract, shortened:
service AuthService {
rpc LoginWithEmail(LoginWithEmailRequest) returns (LoginResponse);
rpc ValidateSession(ValidateSessionRequest) returns (ValidateSessionResponse);
rpc Logout(LogoutRequest) returns (LogoutResponse);
}
message ValidateSessionResponse {
bool isValid = 1;
string message = 2;
optional string entityId = 3;
int32 ttl = 4;
bool extended = 5;
string sessionId = 6;
}
The full service has 11 methods. extended and ttl handle sliding expiration: when auth-service extends a session, main-server refreshes the cookie. This is the middleware in main-server:
const userObject = await AuthSDK.validateSession(sessionId);
if (userObject.extended) {
res.cookie("sessionToken", userObject.sessionId, userObject.ttl * 1000, {
path: "/",
httpOnly: true,
secure: true,
sameSite: "none",
});
}
req.locals.user = { ...req.locals.user, uid: userObject.entityId, sessionId };
The services authenticate each other with an API key sent in gRPC metadata. In auth-service an interceptor checks it before any method runs. A wrong key gets status 16 UNAUTHENTICATED, a missing field gets 3 INVALID_ARGUMENT. Both are standard gRPC status codes, so I didn’t have to design an error format.
Getting protoc and code generation to work
gRPC is harder to start with than REST. With REST you can start with fetch and a JSON body. With gRPC, before the first call works, you need protoc, a plugin for your language, the right options and a place for the generated files. Most of my setup time went there.
I ended up with one npm script in a shared package, using ts-proto:
{
"scripts": {
"proto:generate": "protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=./clients --ts_proto_opt=esModuleInterop=true,outputServices=grpc-js,useOptionals=messages --proto_path=./protos ./protos/*.proto"
}
}
outputServices=grpc-js generates a typed client for @grpc/grpc-js. From then on every change went the same way: edit the .proto, run the script, and TypeScript points at every place that no longer matches. The generated client uses callbacks, so I wrapped it in a small SDK that returns promises and adds the API key:
validateSession: (sessionId: string): Promise<ValidateSessionResponse> =>
new Promise((resolve, reject) => {
const meta = new Metadata();
meta.add("Authorization", ApiKey);
authClient.validateSession({ sessionId }, meta, (err, res) => {
if (err) return reject(err);
resolve(res);
});
}),
How I measured gRPC vs REST
I didn’t measure anything while writing the thesis, so I did it now, as close to the thesis setup as I could:
- server in one Docker container, client in another, on one Windows 11 desktop with Docker 28.2
- Node.js 22.18: the gRPC server loads the
.protowith@grpc/proto-loader0.8 like auth-service, the client is generated with ts-proto 2.7 like main-server, both on@grpc/grpc-js1.14. REST is plainnode:httpwith a keep-alive agent - Go 1.23:
grpc-go1.67 againstnet/httpwithencoding/json - two messages: the 84-byte session response from the thesis, and a list of assets with 500, 5,000 or 20,000 items. In protobuf they weigh 41 KB, 422 KB and 1.7 MB, in JSON 73 KB, 748 KB and 3.1 MB
- four networks: the plain Docker network, fast and with almost no delay, then 1 Gbit/s with 0.5 ms delay, 100 Mbit/s with 1 ms, and 20 Mbit/s with 20 ms, the last three shaped with
tc netem - three rounds per setup. Each round has a warm-up, then calls one at a time for the median, then 50 calls in flight for requests per second. Ranges are the lowest and highest round.
The median comes from this loop:
async function medianLatency(call, n) {
for (let i = 0; i < 500; i++) await call();
const times = [];
for (let i = 0; i < n; i++) {
const start = process.hrtime.bigint();
await call();
times.push(Number(process.hrtime.bigint() - start) / 1e6);
}
times.sort((a, b) => a - b);
return times[Math.floor(n / 2)];
}
Small messages: REST won in Node.js, Go was a tie
The session check, median of one call:
| Network | Node gRPC | Node REST | Go gRPC | Go REST |
|---|---|---|---|---|
| Docker network | 0.39–0.58 ms | 0.22–0.31 ms | 0.29–0.30 ms | 0.28–0.30 ms |
| 1 Gbit/s, 0.5 ms | 0.92–1.07 ms | 0.77–0.84 ms | 0.79–0.81 ms | 0.80–0.81 ms |
| 100 Mbit/s, 1 ms | 1.46–1.60 ms | 1.30–1.37 ms | 1.33–1.38 ms | 1.36–1.39 ms |
| 20 Mbit/s, 20 ms | 21.3–22.0 ms | 20.9–21.3 ms | 20.7–20.8 ms | 20.9 ms |
With 50 calls in flight on the Docker network, Node handled 6.7k–9.4k requests per second over gRPC and 13.4k–18.0k over REST. Go handled 44.5k–54.9k over gRPC and 37.2k–42.9k over REST.
This is the call my thesis makes on every request. Sending 74 bytes fewer saves nothing measurable, and @grpc/grpc-js adds work to every call. I didn’t profile where that time goes, so I can’t split it between HTTP/2 framing, headers and metadata. The library’s maintainer has said it has had “a lot less work to optimize it” than gRPC for Java, in grpc-node#1539.
The connection count could be tested: gRPC sends every call over one HTTP/2 connection, while the REST client had 50 sockets. With 8 gRPC connections, set up with grpc.use_local_subchannel_pool, Node’s throughput on the 500-item list went from 1.1k–1.2k to 1.6k–1.9k requests per second, still below REST at 2.8k–3.0k. For the session check it didn’t change.
Large messages: Go’s gRPC won everywhere, Node’s only on slow links
The asset list, median of one call:
| Network | Items | Node gRPC | Node REST | Go gRPC | Go REST |
|---|---|---|---|---|---|
| Docker network | 500 | 0.80–0.88 ms | 0.56–0.69 ms | 0.52–0.55 ms | 1.08–1.22 ms |
| Docker network | 5,000 | 6.7–10.0 ms | 4.0–4.5 ms | 1.9–2.2 ms | 6.8–7.6 ms |
| Docker network | 20,000 | 41–51 ms | 19–23 ms | 9–12 ms | 28–34 ms |
| 1 Gbit/s, 0.5 ms | 500 | 1.65–1.69 ms | 1.68–1.69 ms | 1.34–1.42 ms | 2.07–2.34 ms |
| 1 Gbit/s, 0.5 ms | 5,000 | 14.6–19.5 ms | 10.7–13.9 ms | 5.6–5.8 ms | 12.1–15.4 ms |
| 1 Gbit/s, 0.5 ms | 20,000 | 76–84 ms | 45–46 ms | 20–23 ms | 47–56 ms |
| 100 Mbit/s, 1 ms | 500 | 5.4–5.6 ms | 7.9–8.3 ms | 5.2–5.3 ms | 8.2–8.5 ms |
| 100 Mbit/s, 1 ms | 5,000 | 47–51 ms | 68–69 ms | 39 ms | 70–71 ms |
| 100 Mbit/s, 1 ms | 20,000 | 196–205 ms | 274–275 ms | 153–154 ms | 282–287 ms |
| 20 Mbit/s, 20 ms | 500 | 38–39 ms | 51.7–52.0 ms | 38 ms | 51.7–51.8 ms |
| 20 Mbit/s, 20 ms | 5,000 | 283–286 ms | 339 ms | 199 ms | 340–341 ms |
| 20 Mbit/s, 20 ms | 20,000 | 1,127–1,136 ms | 1,318–1,321 ms | 751 ms | 1,324–1,327 ms |
Node’s gRPC lost on fast networks, tied at 500 items on 1 Gbit/s, and won once the link got slow. Go’s gRPC won every large-message case.
Why Node.js lost on large messages
A call costs two things: producing and reading the message, and sending its bytes. On a slow link sending decides. At 100 Mbit/s the 748 KB JSON list needs about 60 ms on the wire and the 422 KB protobuf list about 34 ms, so the smaller format wins no matter the language.
On a fast network sending is nearly free and CPU work decides. Encoding and decoding the 20,000-item list, timed separately in three runs:
| Step | Time |
|---|---|
JSON.stringify |
9.0–10.5 ms |
JSON.parse |
8.5–10.2 ms |
protobuf encode through @grpc/proto-loader |
34.6–41.0 ms |
| protobuf encode with ts-proto | 5.9–9.9 ms |
| protobuf decode with ts-proto | 7.9–13.1 ms |
@grpc/proto-loader runs every response through protobufjs fromObject before encoding, and that step is what costs the most. The encoding itself is as fast as JSON. To check, I rebuilt the Node server on the ts-proto service definitions instead of proto-loader. On the Docker network the 20,000-item list then took 25–31 ms over gRPC against 22–31 ms over REST, and 5,000 items 5.9–6.3 ms against 6.0–6.4 ms: a tie instead of losing by half. Small messages didn’t change, the per-call cost stayed.
In my thesis auth-service loads the .proto with proto-loader. For its small session messages that doesn’t matter much, but for any service sending large lists I’d now generate the server code too.
What the test doesn’t show
Everything ran on one machine, so client and server competed for the same CPU. There was no TLS, one message shape, one Node process per side, and the slow links were simulated with tc netem, not real networks. Go’s numbers come from the same machine and the same Docker setup, which makes them a fair comparison with Node here and nothing more.
What gRPC gave me anyway
- One contract. The
.protofile is the source of truth and both sides are generated from it. A renamed field breaks the build, not production. - Generated types. ts-proto produces every request and response interface. With REST they’re typed by hand on both sides, or you set up OpenAPI generation.
- Standard errors and metadata. Status codes and metadata for the API key, no custom error envelope.
- Smaller messages. 44–47% less in every test, which pays off on slow links.
- Deadlines built in. A client says how long it will wait, and the call fails with
DEADLINE_EXCEEDEDafter that.
When to pick gRPC and when REST
| Pick gRPC when | Pick REST when |
|---|---|
| services you own call each other and you want one contract | browsers or third parties call the API |
| the services are written in Go, Java or another language with a mature gRPC library | the services are Node.js, messages are small and they share a fast network |
| messages are large or the link is slow | you want to test it with curl and read the response |
| you need streaming in both directions | HTTP caching by URL matters |
Browsers can’t call gRPC directly. They need gRPC-Web and a proxy in between. That’s why the React app in my thesis uses REST and only the hop between services is gRPC.
What I’d keep
I’d keep the split: REST at the edge, gRPC between services. My reason would change. I picked gRPC for speed, and in Node.js on one fast network my test didn’t show any for the session check. In Go it would have. Today I’d pick gRPC in Node.js for the contract, generate the server code with ts-proto instead of loading the .proto at runtime, and count on speed only where the link is slow or the services aren’t written in Node.