gRPC vs REST vs GraphQL benchmarks: bytes, round trips and CPU per call

NetworkingArchitecture

The usual comparison of gRPC, REST and GraphQL is about contracts, tooling and taste. This one is about cost: what one call puts on the wire, how long it takes on a fast and a slow network, how many calls a server core can answer, and what changes when the data is nested and a client needs only part of it.

All three APIs run in one Go process, over the same TLS 1.3 settings, and call the same functions over the same in-memory store. The only thing that differs between them is the API layer: its encoding, its HTTP framing and, for GraphQL, its query execution. Every response was decoded, reduced to the same canonical form and hashed, and the hash compared with one computed from the store: 38,562,745 calls and 1,120,000 streamed records, 0 mismatches; the same call also produced the same hash on every API.

SetupDetails
ServerOne Go 1.26.10 process on 2 cores (GOMAXPROCS=2) · gRPC: grpc-go 1.85.0, protobuf-go 1.36.12, its own HTTP/2 transport · REST/JSON: net/http + encoding/json, HTTP/2 and HTTP/1.1 on one port by ALPN · GraphQL: gqlgen 0.17.98 on the same net/http server, POST with a JSON body, parsed-query cache on · no compression anywhere
Data1,000 users (id, name, email, a 160-character bio, date, 3 tags, follower count, flag), 10 posts per user, 5 comments per post with their author · small: one user · medium: a page of 100 users · nested: one user’s page, the user’s name, every post’s title and every comment’s text and author name
Nested, per APIgRPC: one RPC returning the whole graph, or (feed fields only) the same RPC filling only the page’s fields · GraphQL: one query selecting exactly the page’s fields · REST ?expand=: one request returning the whole graph · REST N+1: GET /users/{id}, GET /users/{id}/posts, then GET /posts/{id}/comments for each of the 10 posts, either one after another or in two parallel waves
ClientsGo 1.26.10, same versions; HTTP/2 through golang.org/x/net/http2 on a connection the client opened itself, so “one connection” is exactly one · gRPC, REST and GraphQL over HTTP/2, REST also over HTTP/1.1
TLS1.3 everywhere, ECDSA P-256 certificate, X25519MLKEM768 key exchange (Go’s default); connections are opened and warmed before anything is measured
NetworkOne network namespace, IPv4 loopback at a 1,500-byte MTU with segmentation offloads off · links emulated with tc netem: LAN (nothing added), 50 ms round trip, 200 ms round trip with 1 % random loss in each direction
CPUAMD Ryzen AI Max+ 395, cores 0–7 reserved for the benchmark · server on cores 2–3, clients on cores 4–7
MethodEvery cell is a fresh client process, run 10 times · value: median of the 10 runs (mean of the two middle ones), min–max in the tables · latency p99: all calls of all runs pooled · bytes from the interface counters (every IP packet, both directions) before and after · server CPU from the kernel’s per-thread run time

The scoreboard

Scoreboard, median per API. Bytes per call, one user: gRPC 699 B, REST 667 B, GraphQL 929 B. Bytes per call, 100 users: gRPC 27,215 B, REST 36,317 B, GraphQL 36,600 B. Bytes per call, nested page: gRPC 12,993 B, REST 17,241 B, GraphQL 9,230 B. Latency, one user, LAN: gRPC 25 µs, REST 34 µs, GraphQL 49 µs. Nested page, 50 ms link: gRPC 50.6 ms, REST 50.9 ms, GraphQL 51.3 ms. Calls/s, one user, 16 callers: gRPC 132,075/s, REST 63,165/s, GraphQL 40,777/s. Server CPU per 1,000 small calls: gRPC 9 ms, REST 18 ms, GraphQL 32 ms. Server CPU per 1,000 nested pages: gRPC 32 ms, REST 59 ms, GraphQL 400 ms. Best in every run, out of 8 measures: gRPC on 6 · REST on 1 · GraphQL on 1 Eight measures from the sections below · each API as a multiple of the best gRPC REST GraphQL 1× = the best median; grey line: lowest to highest run 1× (best) 2× 3× 5× 10× Bytes per call, one user 699 B 667 B 929 B Bytes per call, 100 users 27,215 B 36,317 B 36,600 B Bytes per call, nested page 12,993 B 17,241 B 9,230 B Latency, one user, LAN 25 µs 34 µs 49 µs Nested page, 50 ms link 50.6 ms 50.9 ms 51.3 ms Calls/s, one user, 16 callers 132,075/s 63,165/s 40,777/s Server CPU per 1,000 small calls 9 ms 18 ms 32 ms Server CPU per 1,000 nested pages 32 ms 59 ms 400 ms Each bar is that API's median as a multiple of the best median for the measure, log scale: 1× is the best, a bar twice as long is twice as costly. Grey line: lowest to highest of the 10 process runs; the median is printed after each bar.
Eight headline measures from the sections below, each API's median as a multiple of the best median for that measure (1×; log scale, a longer bar is worse), labelled with the measured value. Median of 10 process runs; grey line: lowest to highest run. REST is REST/JSON over HTTP/2, and for the nested page one ?expand= request; the N+1 variants are in the latency section. Throughput and CPU: 16 callers on one connection, LAN.
Scoreboard, median per API. Bytes per call, one user: gRPC 699 B, REST 667 B, GraphQL 929 B. Bytes per call, 100 users: gRPC 27,215 B, REST 36,317 B, GraphQL 36,600 B. Bytes per call, nested page: gRPC 12,993 B, REST 17,241 B, GraphQL 9,230 B. Latency, one user, LAN: gRPC 25 µs, REST 34 µs, GraphQL 49 µs. Nested page, 50 ms link: gRPC 50.6 ms, REST 50.9 ms, GraphQL 51.3 ms. Calls/s, one user, 16 callers: gRPC 132,075/s, REST 63,165/s, GraphQL 40,777/s. Server CPU per 1,000 small calls: gRPC 9 ms, REST 18 ms, GraphQL 32 ms. Server CPU per 1,000 nested pages: gRPC 32 ms, REST 59 ms, GraphQL 400 ms. Best in every run, out of 8 measures: gRPC on 6 · REST on 1 · GraphQL on 1 Eight measures from the sections below · each API as a multiple of the best gRPC REST GraphQL 1× = the best median; grey line: lowest to highest run 1× (best) 2× 3× 5× 10× Bytes per call, one user gRPC 699 B REST 667 B GraphQL 929 B Bytes per call, 100 users gRPC 27,215 B REST 36,317 B GraphQL 36,600 B Bytes, nested page gRPC 12,993 B REST 17,241 B GraphQL 9,230 B Latency, one user, LAN gRPC 25 µs REST 34 µs GraphQL 49 µs Nested page, 50 ms link gRPC 50.6 ms REST 50.9 ms GraphQL 51.3 ms Calls/s, 16 callers gRPC 132,075/s REST 63,165/s GraphQL 40,777/s CPU per 1,000 small calls gRPC 9 ms REST 18 ms GraphQL 32 ms CPU per 1,000 nested pages gRPC 32 ms REST 59 ms GraphQL 400 ms Each bar is that API's median as a multiple of the best median for the measure, log scale: 1× is the best, a bar twice as long is twice as costly. Grey line: lowest to highest of the 10 process runs; the median is printed after each bar.
Eight headline measures from the sections below, each API's median as a multiple of the best median for that measure (1×; log scale, a longer bar is worse), labelled with the measured value. Median of 10 process runs; grey line: lowest to highest run. REST is REST/JSON over HTTP/2, and for the nested page one ?expand= request; the N+1 variants are in the latency section. Throughput and CPU: 16 callers on one connection, LAN.
MeasuregRPCRESTGraphQLgRPC vs RESTGraphQL vs REST
Bytes per call, one user699 B
677–726 B
667 B
667 B
929 B
929 B
0.95×0.72×
Bytes per call, 100 users27,215 B
27,190–27,300 B
36,317 B
36,278–36,327 B
36,600 B
36,569–36,607 B
1.3×0.99×
Bytes per call, nested page12,993 B
12,905–13,015 B
17,241 B
17,227–17,256 B
9,230 B
9,223–9,242 B
1.3×1.9×
Latency, one user, LAN25 µs
24–27 µs
34 µs
32–38 µs
49 µs
46–52 µs
1.4×0.70×
Nested page, 50 ms link50.6 ms
50.3–50.7 ms
50.9 ms
50.5–51.1 ms
51.3 ms
50.8–51.6 ms
same0.99×
Calls/s, one user, 16 callers132,075/s
130,076/s–133,773/s
63,165/s
61,647/s–65,268/s
40,777/s
39,989/s–41,137/s
2.1×0.65×
Server CPU per 1,000 small calls9 ms
9 ms
18 ms
17–19 ms
32 ms
32–33 ms
1.9×0.56×
Server CPU per 1,000 nested pages32 ms
31–35 ms
59 ms
58–67 ms
400 ms
397–427 ms
1.9×0.15×

Median of 10 process runs, lowest to highest run beneath; bold: best in every run; the vs columns: above 1× better than REST, below 1× worse, same: rounds to 1×.

Counting a measure only where every run agrees, against REST: gRPC is better on 6 (up to 2.1× on calls/s, one user, 16 callers), worse on 1 (down to 0.95× on bytes per call, one user) and ties on 1; GraphQL is better on 1 (up to 1.9× on bytes per call, nested page), worse on 7 (down to 0.15× on server CPU per 1,000 nested pages). The sections below take each measure in turn, with REST over HTTP/1.1, the N+1 variants, the slow links and the runs behind every median.

Factor against REST per measure, above 1 is better than REST. Bytes per call, one user: gRPC 0.95×, GraphQL 0.72×. Bytes per call, 100 users: gRPC 1.3×, GraphQL 0.99×. Bytes per call, nested page: gRPC 1.3×, GraphQL 1.9×. Latency, one user, LAN: gRPC 1.4×, GraphQL 0.70×. Nested page, 50 ms link: gRPC 1.0×, GraphQL 0.99×. Calls/s, one user, 16 callers: gRPC 2.1×, GraphQL 0.65×. Server CPU per 1,000 small calls: gRPC 1.9×, GraphQL 0.56×. Server CPU per 1,000 nested pages: gRPC 1.9×, GraphQL 0.15×. Against REST, 8 measures: gRPC better on 6 · GraphQL on 1 Medians of 10 process runs · log scale · above 1× is better than REST gRPC GraphQL 0.2× 0.5× 1× (parity) 2× Bytes per call, one user gRPC 0.95× · GraphQL 0.72× Bytes per call, 100 users gRPC 1.3× · GraphQL 0.99× Bytes per call, nested page gRPC 1.3× · GraphQL 1.9× Latency, one user, LAN gRPC 1.4× · GraphQL 0.70× Nested page, 50 ms link gRPC same · GraphQL 0.99× Calls/s, one user, 16 callers gRPC 2.1× · GraphQL 0.65× Server CPU per 1,000 small calls gRPC 1.9× · GraphQL 0.56× Server CPU per 1,000 nested pages gRPC 1.9× · GraphQL 0.15× ← REST better gRPC or GraphQL better →
Each API's median against REST's on the same measure, log scale; above 1× it is better than REST (fewer bytes, faster, more calls per second or less CPU). Filled dot: gRPC; hollow: GraphQL. Median of 10 process runs.
Factor against REST per measure, above 1 is better than REST. Bytes per call, one user: gRPC 0.95×, GraphQL 0.72×. Bytes per call, 100 users: gRPC 1.3×, GraphQL 0.99×. Bytes per call, nested page: gRPC 1.3×, GraphQL 1.9×. Latency, one user, LAN: gRPC 1.4×, GraphQL 0.70×. Nested page, 50 ms link: gRPC 1.0×, GraphQL 0.99×. Calls/s, one user, 16 callers: gRPC 2.1×, GraphQL 0.65×. Server CPU per 1,000 small calls: gRPC 1.9×, GraphQL 0.56×. Server CPU per 1,000 nested pages: gRPC 1.9×, GraphQL 0.15×. Against REST, 8 measures: gRPC better on 6 · GraphQL on 1 Medians of 10 process runs · log scale · above 1× is better than REST gRPC GraphQL 0.2× 0.5× 1× (parity) 2× Bytes per call, one user gRPC 0.95× · GraphQL 0.72× Bytes per call, 100 users gRPC 1.3× · GraphQL 0.99× Bytes, nested page gRPC 1.3× · GraphQL 1.9× Latency, one user, LAN gRPC 1.4× · GraphQL 0.70× Nested page, 50 ms link gRPC same · GraphQL 0.99× Calls/s, 16 callers gRPC 2.1× · GraphQL 0.65× CPU per 1,000 small calls gRPC 1.9× · GraphQL 0.56× CPU per 1,000 nested pages gRPC 1.9× · GraphQL 0.15× ← REST better gRPC or GraphQL better →
Each API's median against REST's on the same measure, log scale; above 1× it is better than REST (fewer bytes, faster, more calls per second or less CPU). Filled dot: gRPC; hollow: GraphQL. Median of 10 process runs.

Bytes on the wire per call

On an open connection, what does one call cost on the network, request and response together?

Bytes on the wire per API call, both directions, all IP, TCP, TLS and HTTP/2 headers included, connection already open. Small: one user record: gRPC 699 B, REST, HTTP/2 667 B, REST, HTTP/1.1 698 B, GraphQL 929 B. Medium: a page of 100 users: gRPC 27,215 B, REST, HTTP/2 36,317 B, REST, HTTP/1.1 35,609 B, GraphQL 36,600 B. Nested: a user page (user, 10 posts, 50 comments with authors): gRPC 12,993 B, gRPC, feed fields only 7,433 B, GraphQL 9,230 B, REST, ?expand= 17,241 B, REST, N+1 one by one 20,379 B, REST, N+1 in 2 waves 19,663 B, REST, N+1, HTTP/1.1 20,318 B. A small record costs about the same on every API (667–929 B); for the nested page GraphQL sends 54 % of REST's bytes Bytes per call, both directions, every header included · connection already open gRPC REST/JSON GraphQL lighter: HTTP/1.1, or gRPC with only the page's fields Small: one user record gRPC 699 B · body 251 B REST, HTTP/2 667 B · body 336 B REST, HTTP/1.1 698 B · body 336 B GraphQL 929 B · body 354 B Medium: a page of 100 users gRPC 27,215 B · body 25,424 B REST, HTTP/2 36,317 B · body 33,739 B REST, HTTP/1.1 35,609 B · body 33,739 B GraphQL 36,600 B · body 33,758 B Nested: a user page (user, 10 posts, 50 comments with authors) gRPC 12,993 B · body 11,862 B gRPC, feed fields only 7,433 B · body 6,551 B GraphQL 9,230 B · body 8,048 B REST, ?expand= 17,241 B · body 15,738 B REST, N+1 one by one 20,379 B · body 15,609 B · 12 requests REST, N+1 in 2 waves 19,663 B · body 15,609 B · 12 requests REST, N+1, HTTP/1.1 20,318 B · body 15,609 B · 12 requests Protobuf's body is 25 % smaller than JSON for the same 100 users; selecting fields matters more: GraphQL's page is 9,230 B, REST's one big response 17,241 B, and gRPC carrying only the same fields 7,433 B.
Median of 10 process runs, each making 200 calls (100 for the nested page) on one open connection and reading the network interface counters before and after. After each bar: the response body alone (protobuf or JSON) and, where it is not one, the number of HTTP requests. Each payload has its own scale.
Bytes on the wire per API call, both directions, all IP, TCP, TLS and HTTP/2 headers included, connection already open. Small: one user record: gRPC 699 B, REST, HTTP/2 667 B, REST, HTTP/1.1 698 B, GraphQL 929 B. Medium: a page of 100 users: gRPC 27,215 B, REST, HTTP/2 36,317 B, REST, HTTP/1.1 35,609 B, GraphQL 36,600 B. Nested: a user page (user, 10 posts, 50 comments with authors): gRPC 12,993 B, gRPC, feed fields only 7,433 B, GraphQL 9,230 B, REST, ?expand= 17,241 B, REST, N+1 one by one 20,379 B, REST, N+1 in 2 waves 19,663 B, REST, N+1, HTTP/1.1 20,318 B. A small record costs about the same on every API (667–929 B); for the nested page GraphQL sends 54 % of REST's bytes Bytes per call, both directions, every header included · connection already open gRPC REST/JSON GraphQL lighter: HTTP/1.1, or gRPC with only the page's fields Small: one user record gRPC 699 B · body 251 B REST, HTTP/2 667 B · body 336 B REST, HTTP/1.1 698 B · body 336 B GraphQL 929 B · body 354 B Medium: a page of 100 users gRPC 27,215 B · body 25,424 B REST, HTTP/2 36,317 B · body 33,739 B REST, HTTP/1.1 35,609 B · body 33,739 B GraphQL 36,600 B · body 33,758 B Nested: a user page gRPC 12,993 B · body 11,862 B gRPC, feed fields only 7,433 B · body 6,551 B GraphQL 9,230 B · body 8,048 B REST, ?expand= 17,241 B · body 15,738 B REST, N+1 one by one 20,379 B · body 15,609 B · 12 req. REST, N+1 in 2 waves 19,663 B · body 15,609 B · 12 req. REST, N+1, HTTP/1.1 20,318 B · body 15,609 B · 12 req. Protobuf's body is 25 % smaller than JSON for the same 100 users; selecting fields matters more: GraphQL's page is 9,230 B, REST's one big response 17,241 B, and gRPC carrying only the same fields 7,433 B.
Median of 10 process runs, each making 200 calls (100 for the nested page) on one open connection and reading the network interface counters before and after. After each bar: the response body alone (protobuf or JSON) and, where it is not one, the number of HTTP requests. Each payload has its own scale.

For one small record, the API makes little difference: 699 B for gRPC, 667 B for REST over HTTP/2, 929 B for GraphQL. The response bodies differ more (251 B of protobuf against 336 B of JSON), but the request and some 400 bytes of TCP, IP, TLS and HTTP framing are much the same for everyone. GraphQL pays most because its request carries the query text, 262 B more than a REST GET.

At 100 records the encoding takes over. Protobuf sends numbers as variable-length integers and field names as one-byte tags, so the same 100 users are 25,424 B against 33,739 B of JSON, and the call 27,215 B against 36,317 B. Most of the user record is text (names, bio, email), which neither format compresses; with numeric data the gap would be wider.

The nested page shows what selecting fields is worth. The page needs 8,048 B of GraphQL response; REST’s ?expand= returns every field of every object, 15,738 B, and the whole call costs 17,241 B against GraphQL’s 9,230 B. The N+1 version (one request for the user, one for the posts, then one per post for its comments) moves about the same body in 12 requests and pays HTTP framing 12 times: 20,379 B in 61 packets. gRPC returning the whole graph sits between (12,993 B); filling only the page’s fields, which a purpose-built RPC would do, it is the smallest of all, 7,433 B. Selection, not the protocol, decides the bytes here; GraphQL just makes it the client’s choice instead of the server’s.

Latency per call

On the LAN a call costs whatever the software costs:

Latency of one API call on an open connection over the LAN, median: Small: one user record: gRPC 25 µs, REST, HTTP/2 34 µs, REST, HTTP/1.1 22 µs, GraphQL 49 µs. Medium: a page of 100 users: gRPC 126 µs, REST, HTTP/2 322 µs, REST, HTTP/1.1 294 µs, GraphQL 773 µs. Nested: a user page (user, 10 posts, 50 comments with authors): gRPC 72 µs, GraphQL 332 µs, REST, ?expand= 174 µs, REST, N+1 in 2 waves 277 µs, REST, N+1 one by one 518 µs. On a fast network the API's own software is the latency: a small record in 25 µs over gRPC, 34 µs over REST, 49 µs over GraphQL LAN, one call at a time on an open connection · median; the slowest 1 % are in the table below gRPC REST/JSON GraphQL lighter: HTTP/1.1 Small: one user record gRPC 25 µs REST, HTTP/2 34 µs REST, HTTP/1.1 22 µs GraphQL 49 µs Medium: a page of 100 users gRPC 126 µs REST, HTTP/2 322 µs REST, HTTP/1.1 294 µs GraphQL 773 µs Nested: a user page (user, 10 posts, 50 comments with authors) gRPC 72 µs GraphQL 332 µs REST, ?expand= 174 µs REST, N+1 in 2 waves 277 µs REST, N+1 one by one 518 µs The nested page done as N+1 REST requests takes 518 µs against 332 µs for one GraphQL query even here, where a round trip costs almost nothing.
One call at a time on an open connection, LAN, from the call until the response is decoded and checked. Median of 10 process runs × 200 calls. Each payload has its own scale.
Latency of one API call on an open connection over the LAN, median: Small: one user record: gRPC 25 µs, REST, HTTP/2 34 µs, REST, HTTP/1.1 22 µs, GraphQL 49 µs. Medium: a page of 100 users: gRPC 126 µs, REST, HTTP/2 322 µs, REST, HTTP/1.1 294 µs, GraphQL 773 µs. Nested: a user page (user, 10 posts, 50 comments with authors): gRPC 72 µs, GraphQL 332 µs, REST, ?expand= 174 µs, REST, N+1 in 2 waves 277 µs, REST, N+1 one by one 518 µs. On a fast network the API's own software is the latency: a small record in 25 µs over gRPC, 34 µs over REST, 49 µs over GraphQL LAN, one call at a time on an open connection · median; the slowest 1 % are in the table below gRPC REST/JSON GraphQL lighter: HTTP/1.1 Small: one user record gRPC 25 µs REST, HTTP/2 34 µs REST, HTTP/1.1 22 µs GraphQL 49 µs Medium: a page of 100 users gRPC 126 µs REST, HTTP/2 322 µs REST, HTTP/1.1 294 µs GraphQL 773 µs Nested: a user page gRPC 72 µs GraphQL 332 µs REST, ?expand= 174 µs REST, N+1 in 2 waves 277 µs REST, N+1 one by one 518 µs The nested page done as N+1 REST requests takes 518 µs against 332 µs for one GraphQL query even here, where a round trip costs almost nothing.
One call at a time on an open connection, LAN, from the call until the response is decoded and checked. Median of 10 process runs × 200 calls. Each payload has its own scale.

gRPC answers a small record in 25 µs, REST over HTTP/2 in 34 µs, GraphQL in 49 µs. For the page of 100 users the gap widens to 126 µs, 322 µs and 773 µs: JSON encoding and decoding on both ends against protobuf’s, and for GraphQL its executor walking every field of every user. These are fractions of a millisecond; on any real network the round trip is bigger.

On a slow link, the count of round trips decides:

Latency of loading the nested user page on the slow links, median and 99th percentile. 50 ms round trip: gRPC 50.6 ms (p99 51.1 ms), GraphQL 51.3 ms (p99 52.1 ms), REST, ?expand= 50.9 ms (p99 51.3 ms), REST, N+1 in 2 waves 102 ms (p99 102 ms), REST, N+1 one by one 607 ms (p99 611 ms). 200 ms round trip, 1 % loss: gRPC 201 ms (p99 852 ms), GraphQL 202 ms (p99 807 ms), REST, ?expand= 201 ms (p99 1,005 ms), REST, N+1 in 2 waves 601 ms (p99 1,212 ms), REST, N+1 one by one 2,607 ms (p99 3,707 ms). Loading the nested page on a 50 ms link: one request 51.3 ms, N+1 REST requests one by one 607 ms User, 10 posts, 50 comments with their authors · open connection · median, tick = slowest 1 % gRPC REST/JSON GraphQL 50 ms round trip gRPC 50.6 ms · p99 51.1 ms GraphQL 51.3 ms · p99 52.1 ms REST, ?expand= 50.9 ms · p99 51.3 ms REST, N+1 in 2 waves (12 requests) 102 ms · p99 102 ms REST, N+1 one by one (12 requests) 607 ms · p99 611 ms Round trips: GraphQL 1.0 · N+1 in 2 waves 2.0 · N+1 one by one 12.1 200 ms round trip, 1 % loss gRPC 201 ms · p99 852 ms GraphQL 202 ms · p99 807 ms REST, ?expand= 201 ms · p99 1,005 ms REST, N+1 in 2 waves (12 requests) 601 ms · p99 1,212 ms REST, N+1 one by one (12 requests) 2,607 ms · p99 3,707 ms Round trips: GraphQL 1.0 · N+1 in 2 waves 3.0 · N+1 one by one 13.0 On a slow link the count of sequential round trips is the latency. One request (gRPC, GraphQL or a REST ?expand=) costs one; the same N+1 requests cost two when sent in parallel waves and twelve one after another (more of each with loss).
One page at a time on an open connection. Median of 10 process runs × 50 pages (on the 200 ms link 30 pages in two waves and 20 one by one); the tick is the 99th percentile of every page loaded. RTT = round trips at that link's delay. Each link has its own scale.
Latency of loading the nested user page on the slow links, median and 99th percentile. 50 ms round trip: gRPC 50.6 ms (p99 51.1 ms), GraphQL 51.3 ms (p99 52.1 ms), REST, ?expand= 50.9 ms (p99 51.3 ms), REST, N+1 in 2 waves 102 ms (p99 102 ms), REST, N+1 one by one 607 ms (p99 611 ms). 200 ms round trip, 1 % loss: gRPC 201 ms (p99 852 ms), GraphQL 202 ms (p99 807 ms), REST, ?expand= 201 ms (p99 1,005 ms), REST, N+1 in 2 waves 601 ms (p99 1,212 ms), REST, N+1 one by one 2,607 ms (p99 3,707 ms). Loading the nested page on a 50 ms link: one request 51.3 ms, N+1 REST requests one by one 607 ms User, 10 posts, 50 comments with their authors · open connection · median, tick = slowest 1 % gRPC REST/JSON GraphQL 50 ms round trip gRPC 50.6 ms · p99 51.1 ms GraphQL 51.3 ms · p99 52.1 ms REST, ?expand= 50.9 ms · p99 51.3 ms REST, N+1 in 2 waves (12 requests) 102 ms · p99 102 ms REST, N+1 one by one (12 requests) 607 ms · p99 611 ms Round trips: GraphQL 1.0 · N+1 in 2 waves 2.0 · N+1 one by one 12.1 200 ms round trip, 1 % loss gRPC 201 ms · p99 852 ms GraphQL 202 ms · p99 807 ms REST, ?expand= 201 ms · p99 1,005 ms REST, N+1 in 2 waves (12 requests) 601 ms · p99 1,212 ms REST, N+1 one by one (12 requests) 2,607 ms · p99 3,707 ms Round trips: GraphQL 1.0 · N+1 in 2 waves 3.0 · N+1 one by one 13.0 On a slow link the count of sequential round trips is the latency. One request (gRPC, GraphQL or a REST ?expand=) costs one; the same N+1 requests cost two when sent in parallel waves and twelve one after another (more of each with loss).
One page at a time on an open connection. Median of 10 process runs × 50 pages (on the 200 ms link 30 pages in two waves and 20 one by one); the tick is the 99th percentile of every page loaded. RTT = round trips at that link's delay. Each link has its own scale.

With 50 ms between client and server, every API that loads the page in one request takes one round trip: 50.6 ms for gRPC, 51.3 ms for GraphQL, 50.9 ms for REST with ?expand=. The N+1 REST client needs the posts before it can ask for their comments: sent in two parallel waves, 102 ms; one request after another, as a naive client does, 607 ms. On the lossy 200 ms link the same page costs 2,607 ms one by one.

Loss shows in the tail for everyone. On the 200 ms link with 1 % loss, the slowest 1 % of small calls took 807 ms over gRPC and 668 ms over REST: a lost TCP segment waits for a retransmission timeout of at least 200 ms plus the round trip. All three ride the same TCP, and none of them helps with that. Response size starts to matter too: when losses keep TCP’s congestion window small, the page of 100 users (27–37 KB per call) needs a second round trip at the median on every API (401 ms for gRPC, 401 ms for REST), while the nested page in one request (9–17 KB) still takes one (201 ms with ?expand=).

All latencies, median and p99:

Median · p99LAN50 ms200 ms
1 % loss
small · gRPC25 µs
91 µs
50.6 ms
51.0 ms
201 ms
807 ms
small · REST
HTTP/2
34 µs
105 µs
50.5 ms
51.2 ms
200 ms
668 ms
small · REST
HTTP/1.1
22 µs
115 µs
50.3 ms
51.1 ms
201 ms
604 ms
small · GraphQL49 µs
149 µs
50.7 ms
51.2 ms
201 ms
855 ms
medium · gRPC126 µs
279 µs
50.7 ms
51.2 ms
401 ms
1,009 ms
medium · REST
HTTP/2
322 µs
886 µs
51.4 ms
51.8 ms
401 ms
1,054 ms
medium · REST
HTTP/1.1
294 µs
878 µs
51.3 ms
52.0 ms
401 ms
1,201 ms
medium · GraphQL773 µs
2.72 ms
52.2 ms
53.2 ms
402 ms
1,060 ms
nested · gRPC72 µs
185 µs
50.6 ms
51.1 ms
201 ms
852 ms
nested · GraphQL332 µs
1.32 ms
51.3 ms
52.1 ms
202 ms
807 ms
nested · REST
?expand=
174 µs
492 µs
50.9 ms
51.3 ms
201 ms
1,005 ms
nested · REST
N+1 in 2 waves
277 µs
662 µs
102 ms
102 ms
601 ms
1,212 ms
nested · REST
N+1 one by one
518 µs
900 µs
607 ms
611 ms
2,607 ms
3,707 ms

Throughput: concurrency and connections

How many calls per second can a client get from a 2-core server? Callers call as fast as they can; either all of them share one connection, or each has its own.

Small-record calls per second on the LAN, by number of concurrent callers and connections. gRPC: 1 caller 38,048, 16 callers, 1 connection 132,075, 16 callers, 16 connections 101,071, 128 callers, 1 connection 194,946, 128 callers, 128 connections 109,591. REST, HTTP/2: 1 caller 27,981, 16 callers, 1 connection 63,165, 16 callers, 16 connections 82,794, 128 callers, 1 connection 83,311, 128 callers, 128 connections 92,536. GraphQL: 1 caller 19,658, 16 callers, 1 connection 40,777, 16 callers, 16 connections 50,404, 128 callers, 1 connection 45,436, 128 callers, 128 connections 51,220. REST, HTTP/1.1: 1 caller 45,478, 16 callers, 1 connection 49,217, 16 callers, 16 connections 143,982, 128 callers, 1 connection 48,934, 128 callers, 128 connections 163,563. Calls per second on 2 server cores: gRPC peaks at 195k, REST over HTTP/1.1 at 164k, REST over HTTP/2 at 93k, GraphQL at 51k Small record, LAN · calls completed and checked per second · median gRPC REST/JSON GraphQL lighter: REST over HTTP/1.1 gRPC 1 caller 38,048/s 16 callers, 1 connection 132,075/s 16 callers, 16 connections 101,071/s 128 callers, 1 connection 194,946/s 128 callers, 128 connections 109,591/s REST, HTTP/2 1 caller 27,981/s 16 callers, 1 connection 63,165/s 16 callers, 16 connections 82,794/s 128 callers, 1 connection 83,311/s 128 callers, 128 connections 92,536/s GraphQL 1 caller 19,658/s 16 callers, 1 connection 40,777/s 16 callers, 16 connections 50,404/s 128 callers, 1 connection 45,436/s 128 callers, 128 connections 51,220/s REST, HTTP/1.1 1 caller 45,478/s 16 callers, 1 connection 49,217/s 16 callers, 16 connections 143,982/s 128 callers, 1 connection 48,934/s 128 callers, 128 connections 163,563/s On one connection gRPC keeps scaling to 128 callers; a connection per caller costs it 44 %. HTTP/1.1 needs a connection per caller, and given them it is the fastest REST here.
Callers call as fast as they can for 2 s; calls completed and checked per second, median of 10 process runs. Server: one process on 2 cores; clients on 4 other cores. One connection is one TCP + TLS connection carrying every caller (HTTP/1.1 can only carry one request at a time on it); with as many connections as callers, each caller has its own.
Small-record calls per second on the LAN, by number of concurrent callers and connections. gRPC: 1 caller 38,048, 16 callers, 1 connection 132,075, 16 callers, 16 connections 101,071, 128 callers, 1 connection 194,946, 128 callers, 128 connections 109,591. REST, HTTP/2: 1 caller 27,981, 16 callers, 1 connection 63,165, 16 callers, 16 connections 82,794, 128 callers, 1 connection 83,311, 128 callers, 128 connections 92,536. GraphQL: 1 caller 19,658, 16 callers, 1 connection 40,777, 16 callers, 16 connections 50,404, 128 callers, 1 connection 45,436, 128 callers, 128 connections 51,220. REST, HTTP/1.1: 1 caller 45,478, 16 callers, 1 connection 49,217, 16 callers, 16 connections 143,982, 128 callers, 1 connection 48,934, 128 callers, 128 connections 163,563. Calls per second on 2 server cores: gRPC peaks at 195k, REST over HTTP/1.1 at 164k, REST over HTTP/2 at 93k, GraphQL at 51k Small record, LAN · calls completed and checked per second · median gRPC REST/JSON GraphQL lighter: REST over HTTP/1.1 gRPC 1 caller 38,048/s 16 callers, 1 connection 132,075/s 16 callers, 16 connections 101,071/s 128 callers, 1 connection 194,946/s 128 callers, 128 connections 109,591/s REST, HTTP/2 1 caller 27,981/s 16 callers, 1 connection 63,165/s 16 callers, 16 connections 82,794/s 128 callers, 1 connection 83,311/s 128 callers, 128 connections 92,536/s GraphQL 1 caller 19,658/s 16 callers, 1 connection 40,777/s 16 callers, 16 connections 50,404/s 128 callers, 1 connection 45,436/s 128 callers, 128 connections 51,220/s REST, HTTP/1.1 1 caller 45,478/s 16 callers, 1 connection 49,217/s 16 callers, 16 connections 143,982/s 128 callers, 1 connection 48,934/s 128 callers, 128 connections 163,563/s On one connection gRPC keeps scaling to 128 callers; a connection per caller costs it 44 %. HTTP/1.1 needs a connection per caller, and given them it is the fastest REST here.
Callers call as fast as they can for 2 s; calls completed and checked per second, median of 10 process runs. Server: one process on 2 cores; clients on 4 other cores. One connection is one TCP + TLS connection carrying every caller (HTTP/1.1 can only carry one request at a time on it); with as many connections as callers, each caller has its own.
Calls/sgRPCREST
HTTP/2
GraphQLREST
HTTP/1.1
small · LAN
1 caller
38k
38k–38k
28k
28k–28k
20k
19k–20k
45k
45k–46k
small · LAN
16 callers, 1 connection
132k
130k–134k
63k
62k–65k
41k
40k–41k
49k
49k–49k
small · LAN
16 callers, 16 connections
101k
99k–102k
83k
81k–86k
50k
50k–51k
144k
143k–145k
small · LAN
128 callers, 1 connection
195k
187k–197k
83k
80k–85k
45k
45k–46k
49k
48k–49k
small · LAN
128 callers, 128 connections
110k
104k–112k
93k
84k–98k
51k
49k–52k
164k
158k–168k
medium · LAN
1 caller
7.7k
7.6k–7.8k
3.0k
2.9k–3.0k
1.2k
1.1k–1.2k
3.2k
3.2k–3.3k
medium · LAN
16 callers, 1 connection
26k
25k–26k
10k
10.0k–11k
2.5k
2.5k–2.6k
10k
9.7k–10k
medium · LAN
16 callers, 16 connections
26k
26k–27k
11k
11k–11k
2.6k
2.5k–2.6k
12k
11k–12k
medium · LAN
128 callers, 1 connection
28k
28k–29k
9.6k
9.3k–9.7k
2.6k
2.5k–2.7k
10k
10.0k–10k
medium · LAN
128 callers, 128 connections
24k
23k–24k
11k
11k–11k
2.3k
2.3k–2.3k
12k
12k–12k
small · 50 ms
1 caller
20
20–20
20
20–20
20
20–20
20
20–20
small · 50 ms
16 callers, 1 connection
318
315–319
315
313–317
314
312–316
20
20–20
small · 50 ms
16 callers, 16 connections
318
314–319
318
315–319
318
314–319
318
315–319
small · 50 ms
128 callers, 1 connection
2.5k
2.5k–2.5k
2.5k
2.4k–2.5k
2.5k
2.4k–2.5k
20
20–20
small · 50 ms
128 callers, 128 connections
2.5k
2.5k–2.5k
2.5k
2.5k–2.5k
2.5k
2.5k–2.5k
2.5k
2.5k–2.6k

Server CPU per 1,000 calls

The same throughput runs, measured from the server’s side: how much CPU it spent per 1,000 calls answered, with 16 callers.

Server CPU time per 1,000 calls, 16 concurrent callers on the LAN. Small: one user record: gRPC 9 ms, REST, HTTP/2 18 ms, REST, HTTP/1.1 9 ms, GraphQL 32 ms. Medium: a page of 100 users: gRPC 51 ms, REST, HTTP/2 106 ms, REST, HTTP/1.1 81 ms, GraphQL 758 ms. Nested: a user page (user, 10 posts, 50 comments with authors): gRPC 32 ms, REST, ?expand= 59 ms, GraphQL 400 ms, REST, N+1 (12 requests) 234 ms. Server CPU per 1,000 small calls: 9 ms for gRPC, 18 ms for REST over HTTP/2, 32 ms for GraphQL 16 concurrent callers, LAN · CPU of every server thread · median gRPC REST/JSON GraphQL lighter: HTTP/1.1 Small: one user record gRPC 9 ms REST, HTTP/2 18 ms REST, HTTP/1.1 9 ms GraphQL 32 ms Medium: a page of 100 users gRPC 51 ms REST, HTTP/2 106 ms REST, HTTP/1.1 81 ms GraphQL 758 ms Nested: a user page (user, 10 posts, 50 comments with authors) gRPC 32 ms REST, ?expand= 59 ms GraphQL 400 ms REST, N+1 (12 requests) 234 ms For one record the HTTP and TLS work dominates; for a page of 100 users encoding dominates, and protobuf costs 48 % of JSON. Resolving the nested page field by field costs GraphQL 6.8× REST's one prebuilt response.
CPU time of every server thread (from the kernel's per-thread run-time counters) during the 2-second throughput window, divided by the calls completed; 16 callers on one connection (HTTP/1.1: 16 connections, it cannot share one). Median of 10 process runs. Each payload has its own scale.
Server CPU time per 1,000 calls, 16 concurrent callers on the LAN. Small: one user record: gRPC 9 ms, REST, HTTP/2 18 ms, REST, HTTP/1.1 9 ms, GraphQL 32 ms. Medium: a page of 100 users: gRPC 51 ms, REST, HTTP/2 106 ms, REST, HTTP/1.1 81 ms, GraphQL 758 ms. Nested: a user page (user, 10 posts, 50 comments with authors): gRPC 32 ms, REST, ?expand= 59 ms, GraphQL 400 ms, REST, N+1 (12 requests) 234 ms. Server CPU per 1,000 small calls: 9 ms for gRPC, 18 ms for REST over HTTP/2, 32 ms for GraphQL 16 concurrent callers, LAN · CPU of every server thread · median gRPC REST/JSON GraphQL lighter: HTTP/1.1 Small: one user record gRPC 9 ms REST, HTTP/2 18 ms REST, HTTP/1.1 9 ms GraphQL 32 ms Medium: a page of 100 users gRPC 51 ms REST, HTTP/2 106 ms REST, HTTP/1.1 81 ms GraphQL 758 ms Nested: a user page gRPC 32 ms REST, ?expand= 59 ms GraphQL 400 ms REST, N+1 (12 requests) 234 ms For one record the HTTP and TLS work dominates; for a page of 100 users encoding dominates, and protobuf costs 48 % of JSON. Resolving the nested page field by field costs GraphQL 6.8× REST's one prebuilt response.
CPU time of every server thread (from the kernel's per-thread run-time counters) during the 2-second throughput window, divided by the calls completed; 16 callers on one connection (HTTP/1.1: 16 connections, it cannot share one). Median of 10 process runs. Each payload has its own scale.

For a small record most of the server’s work is HTTP and TLS. gRPC’s own HTTP/2 transport needs 9.4 ms per 1,000 calls, net/http over HTTP/1.1 about the same, 8.7 ms, and net/http over HTTP/2 twice that, 18.1 ms: in Go, REST’s HTTP/2 costs more than its JSON. For 100 users it is encoding: 51 ms for gRPC, 106 ms for REST.

GraphQL is the outlier: 758 ms per 1,000 pages of 100 users, 7.2× REST’s for the same data. gqlgen resolves and writes the response field by field, checking each against the query, where REST hands a struct to encoding/json in one call. For the nested page, GraphQL costs 400 ms per 1,000 against 59 ms for REST’s ?expand= and 234 ms for the 12 N+1 requests. GraphQL moves fewer bytes and saves the client round trips; the server pays for it in CPU.

Serialisation: protobuf vs JSON

The encoding alone, outside any server: the same Go structs encoded and decoded with protobuf and with encoding/json.

Time to encode and decode one payload, Go protobuf against Go encoding/json. One user: protobuf encode 139 ns, JSON encode 319 ns, protobuf decode 287 ns, JSON decode 1.9 µs. 100 users: protobuf encode 12.4 µs, JSON encode 29.9 µs, protobuf decode 28.3 µs, JSON decode 185 µs. User page with every field: protobuf encode 5.8 µs, JSON encode 13.5 µs, protobuf decode 11.8 µs, JSON decode 83.4 µs. Decoding 100 users: protobuf 28.3 µs, JSON 185 µs (6.5×); encoding is closer Go protobuf vs encoding/json · time per payload · median protobuf JSON One user · protobuf 248 B, JSON 333 B protobuf encode 139 ns · 1 allocation JSON encode 319 ns · 1 allocation protobuf decode 287 ns · 11 allocations JSON decode 1.9 µs · 16 allocations 100 users · protobuf 25,224 B, JSON 33,552 B protobuf encode 12.4 µs · 1 allocation JSON encode 29.9 µs · 1 allocation protobuf decode 28.3 µs · 1,109 allocations JSON decode 185 µs · 1,015 allocations User page with every field · protobuf 11,808 B, JSON 15,635 B protobuf encode 5.8 µs · 1 allocation JSON encode 13.5 µs · 1 allocation protobuf decode 11.8 µs · 346 allocations JSON decode 83.4 µs · 245 allocations Per record the difference is microseconds: decoding one user costs 287 ns against 1.9 µs. It adds up on the server for large responses, not on a single call.
Go's testing.Benchmark, about one second per value, in 10 fresh processes on the client cores; median. Each payload is encoded from, and decoded into, the same structs the servers use; every decode is checked against the original first. Size: the encoded bytes. Each payload has its own scale.
Time to encode and decode one payload, Go protobuf against Go encoding/json. One user: protobuf encode 139 ns, JSON encode 319 ns, protobuf decode 287 ns, JSON decode 1.9 µs. 100 users: protobuf encode 12.4 µs, JSON encode 29.9 µs, protobuf decode 28.3 µs, JSON decode 185 µs. User page with every field: protobuf encode 5.8 µs, JSON encode 13.5 µs, protobuf decode 11.8 µs, JSON decode 83.4 µs. Decoding 100 users: protobuf 28.3 µs, JSON 185 µs (6.5×); encoding is closer Go protobuf vs encoding/json · time per payload · median protobuf JSON One user · protobuf 248 B, JSON 333 B protobuf encode 139 ns · 1 allocation JSON encode 319 ns · 1 allocation protobuf decode 287 ns · 11 allocations JSON decode 1.9 µs · 16 allocations 100 users · protobuf 25,224 B, JSON 33,552 B protobuf encode 12.4 µs · 1 allocation JSON encode 29.9 µs · 1 allocation protobuf decode 28.3 µs · 1,109 allocations JSON decode 185 µs · 1,015 allocations User page with every field · protobuf 11,808 B, JSON 15,635 B protobuf encode 5.8 µs · 1 allocation JSON encode 13.5 µs · 1 allocation protobuf decode 11.8 µs · 346 allocations JSON decode 83.4 µs · 245 allocations Per record the difference is microseconds: decoding one user costs 287 ns against 1.9 µs. It adds up on the server for large responses, not on a single call.
Go's testing.Benchmark, about one second per value, in 10 fresh processes on the client cores; median. Each payload is encoded from, and decoded into, the same structs the servers use; every decode is checked against the original first. Size: the encoded bytes. Each payload has its own scale.

Encoding 100 users takes 12.4 µs in protobuf and 29.9 µs in JSON, 2.4×. Decoding is where JSON is slow in Go: 185 µs against 28.3 µs, 6.5×, because encoding/json matches field names as text and uses reflection for each field. For one user both are a few microseconds or less, small next to a network round trip, which is why the LAN latencies above differ by tens of microseconds, not milliseconds.

Streaming: gRPC server streaming vs NDJSON

One request, 2,000 user records back, processed as they arrive. gRPC sends a stream of messages on one HTTP/2 stream; the REST endpoint writes newline-delimited JSON (NDJSON), one object per line, over HTTP/2 or HTTP/1.1 chunked encoding. For comparison: the same 2,000 users as one ordinary JSON array.

Streaming 2,000 user records: time to the first record and to the last, per link. LAN, no added delay: gRPC server stream first 137 µs, all 2.14 ms, REST NDJSON, HTTP/2 first 151 µs, all 5.87 ms, REST NDJSON, HTTP/1.1 first 552 µs, all 6.06 ms, REST, one JSON array first 5.92 ms, all 6.60 ms. 50 ms round trip: gRPC server stream first 50.4 ms, all 104 ms, REST NDJSON, HTTP/2 first 50.7 ms, all 103 ms, REST NDJSON, HTTP/1.1 first 50.9 ms, all 104 ms, REST, one JSON array first 106 ms, all 107 ms. 200 ms round trip, 1 % loss: gRPC server stream first 201 ms, all 1,905 ms, REST NDJSON, HTTP/2 first 201 ms, all 1,803 ms, REST NDJSON, HTTP/1.1 first 401 ms, all 1,604 ms, REST, one JSON array first 2,907 ms, all 2,908 ms. Streaming 2,000 records: the first one arrives after one round trip over gRPC and NDJSON alike (50.4 ms and 50.7 ms on the 50 ms link); a plain JSON array makes the client wait for all of them (106 ms) Server streaming vs newline-delimited JSON · first record (thin) and last record (thick) · median gRPC REST/JSON thin grey: until the first record lighter: HTTP/1.1 LAN, no added delay gRPC server stream first 137 µs · all 2.14 ms REST NDJSON, HTTP/2 first 151 µs · all 5.87 ms REST NDJSON, HTTP/1.1 first 552 µs · all 6.06 ms REST, one JSON array first 5.92 ms · all 6.60 ms 50 ms round trip gRPC server stream first 50.4 ms · all 104 ms REST NDJSON, HTTP/2 first 50.7 ms · all 103 ms REST NDJSON, HTTP/1.1 first 50.9 ms · all 104 ms REST, one JSON array first 106 ms · all 107 ms 200 ms round trip, 1 % loss gRPC server stream first 201 ms · all 1,905 ms REST NDJSON, HTTP/2 first 201 ms · all 1,803 ms REST NDJSON, HTTP/1.1 first 401 ms · all 1,604 ms REST, one JSON array first 2,907 ms · all 2,908 ms On the wire a streamed record costs 280 B over gRPC and 358 B as NDJSON. On the lossy link the total is TCP's, not the API's: runs ranged 1.4–3.8 s for gRPC and 0.7–6.4 s for NDJSON, and gRPC finished first in 4 of 10 runs; the order between them is noise.
One request answered with 2,000 user records (about 0.5 MB of protobuf, 0.7 MB of JSON), read and checked record by record. Median of 10 process runs × 5 streams (3 on the slow links). Thin grey bar: until the first record arrives; thick bar: until the last. A plain JSON array can only be decoded once it has fully arrived. Each link has its own scale.
Streaming 2,000 user records: time to the first record and to the last, per link. LAN, no added delay: gRPC server stream first 137 µs, all 2.14 ms, REST NDJSON, HTTP/2 first 151 µs, all 5.87 ms, REST NDJSON, HTTP/1.1 first 552 µs, all 6.06 ms, REST, one JSON array first 5.92 ms, all 6.60 ms. 50 ms round trip: gRPC server stream first 50.4 ms, all 104 ms, REST NDJSON, HTTP/2 first 50.7 ms, all 103 ms, REST NDJSON, HTTP/1.1 first 50.9 ms, all 104 ms, REST, one JSON array first 106 ms, all 107 ms. 200 ms round trip, 1 % loss: gRPC server stream first 201 ms, all 1,905 ms, REST NDJSON, HTTP/2 first 201 ms, all 1,803 ms, REST NDJSON, HTTP/1.1 first 401 ms, all 1,604 ms, REST, one JSON array first 2,907 ms, all 2,908 ms. Streaming 2,000 records: the first one arrives after one round trip over gRPC and NDJSON alike (50.4 ms and 50.7 ms on the 50 ms link); a plain JSON array makes the client wait for all of them (106 ms) Server streaming vs newline-delimited JSON · first record (thin) and last record (thick) · median gRPC REST/JSON thin grey: until the first record lighter: HTTP/1.1 LAN, no added delay gRPC server stream first 137 µs · all 2.14 ms REST NDJSON, HTTP/2 first 151 µs · all 5.87 ms REST NDJSON, HTTP/1.1 first 552 µs · all 6.06 ms REST, one JSON array first 5.92 ms · all 6.60 ms 50 ms round trip gRPC server stream first 50.4 ms · all 104 ms REST NDJSON, HTTP/2 first 50.7 ms · all 103 ms REST NDJSON, HTTP/1.1 first 50.9 ms · all 104 ms REST, one JSON array first 106 ms · all 107 ms 200 ms round trip, 1 % loss gRPC server stream first 201 ms · all 1,905 ms REST NDJSON, HTTP/2 first 201 ms · all 1,803 ms REST NDJSON, HTTP/1.1 first 401 ms · all 1,604 ms REST, one JSON array first 2,907 ms · all 2,908 ms On the wire a streamed record costs 280 B over gRPC and 358 B as NDJSON. On the lossy link the total is TCP's, not the API's: runs ranged 1.4–3.8 s for gRPC and 0.7–6.4 s for NDJSON, and gRPC finished first in 4 of 10 runs; the order between them is noise.
One request answered with 2,000 user records (about 0.5 MB of protobuf, 0.7 MB of JSON), read and checked record by record. Median of 10 process runs × 5 streams (3 on the slow links). Thin grey bar: until the first record arrives; thick bar: until the last. A plain JSON array can only be decoded once it has fully arrived. Each link has its own scale.

Both streams deliver the first record about one round trip after the request (50.4 ms for gRPC, 50.7 ms for NDJSON on the 50 ms link); the JSON array arrives in about the same total time but can be used only at the end, 106 ms. On the wire a record costs 280 B over gRPC and 358 B as NDJSON, the same protobuf-against-JSON ratio as above. On the lossy link the total is TCP’s: 0.5–0.7 MB over a 200 ms path with 1 % loss, where each loss cuts TCP’s sending rate, took 1,905 ms for gRPC (runs ranged 1,403 ms–3,806 ms) and 1,803 ms for NDJSON over HTTP/2 (705 ms–6,408 ms); gRPC finished first in 4 of 10 runs, so the order between the two is noise, the spread is the finding. NDJSON needs nothing but HTTP; what gRPC streaming adds is a typed message per record, flow control per stream, and streams in both directions, which NDJSON cannot do.

What this does not show

What the numbers say

Reproduce it

The harness is one Go program: the server with all three APIs over one store, and a client that runs one measurement and prints JSON lines. A driver script runs every cell 10 times on each link:

./certs.sh                     # throwaway CA and ECDSA P-256 certificate for localhost
docker build -t rpcb .         # Go 1.26 build, runs the self-test (store, hashes, protobuf mapping)
./up.sh 4-7 2-3                # client cores, server cores
docker exec rb-net tc qdisc replace dev lo root netem delay 25ms limit 100000   # the 50 ms link
docker exec rb-net rb run -test lat -kind restn -payload nested -n 50 -settle 300ms

Each run prints the latency samples, bytes and packets counted, calls verified against the store, and the content hash of the last response.

Questions? Let's Chat :)

protocols