Skip to content

gRPC vs REST Performance: How to Benchmark Them Fairly

gRPC vs REST performance depends on payload, connection reuse and server work. Design a fair benchmark and read the percentiles before you migrate.

Side-by-side request anatomy: JSON over several HTTP/1.1 connections on the left, protobuf frames multiplexed on one HTTP/2 connection on the right, with a same-payload same-server-work checklist

gRPC is often faster than REST on serialization and connection handling, but the size of the gap depends on your payload, your connection reuse and how much work the server does per call. A fair benchmark holds all of those constant and changes only the protocol. This post shows how to design that benchmark so you measure your own system instead of quoting someone else’s numbers.

Numbers from blog posts and conference slides come from systems that are not yours. They used a particular payload, a particular server and often an unequal setup, such as gRPC on warm HTTP/2 connections against REST opening a new connection per call. Treat them as a reason to run your own test, not as a result.

Prerequisites

You need three things before you start:

  • A service that exposes the same operation over REST and gRPC, or a plan to build both on one handler.
  • A load generator that speaks both protocols, such as k6, on a machine that does not saturate.
  • Access to CPU and request-count metrics for the service and its load balancer.

Where the differences come from

Four mechanisms account for most real differences between a gRPC service and a JSON REST service.

Encoding. Protocol Buffers write fields as compact binary with numeric tags. JSON writes field names as text on every message and the receiver parses text into objects. For a payload with many numeric fields or repeated records, protobuf messages are usually smaller and cheaper to encode and decode. For a payload that is mostly one long string, there is little to save.

Transport. gRPC requires HTTP/2. HTTP/2 multiplexes many concurrent calls on one connection, compresses headers, and avoids opening a connection per request. REST over HTTP/1.1 needs one connection per in-flight request, so a client holds a pool and requests queue when it is exhausted. REST also runs on HTTP/2, which removes part of this gap. See HTTP/2 and HTTP/3 load testing for what changes when the transport changes.

Streaming. gRPC has server, client and bidirectional streaming built in. If your workload is a long-lived feed of small messages, a stream avoids a request and response cycle per message. A REST design needs polling, server-sent events or a WebSocket to do the same job, and each has its own cost profile. The gRPC load testing guide covers how to test streams.

Connection reuse. A warm connection skips TCP and TLS setup. Whichever protocol you test, whether the client reuses connections often moves latency more than the encoding does.

Where the difference does not matter

A request that spends 40 ms in a database query and 0.3 ms in JSON parsing does not get faster by changing protocol. If the database, a downstream call or business logic dominates the service time, a protocol comparison shows noise around a fixed cost. Profile a representative request first. If serialization and framing are a small share of the time and CPU, spend your effort elsewhere.

The protocol matters more when requests are small and frequent, when payloads are large and structured, when many calls share a connection, when CPU on the service is the constraint, or when you pay for bandwidth between services. Internal service-to-service traffic often fits this description. A public API consumed by browsers and third parties usually has other constraints, such as tooling, caching and browser support, that decide the question before performance does.

Design a fair benchmark

A comparison is fair when the only variable is the protocol. Check each of these before you trust a result.

  • Same payload content. Both protocols carry the same logical data, with the same field values and sizes. Generate the JSON and the protobuf message from one source object. Test a small, a typical and a large payload, because the gap changes with size.
  • Same server work. The handler runs the same business logic and the same database or cache calls. Share the implementation behind both interfaces, or stub the backend identically. Otherwise you compare two codebases.
  • Same connection behavior. Both clients reuse connections the same way. If production clients open a connection per call, test that as a separate scenario and label it.
  • HTTP/2 for both where possible. If your production REST traffic is HTTP/1.1, benchmark that, and also run REST on HTTP/2 to separate the encoding effect from the transport effect.
  • Warm-up. Exclude the first seconds. JIT compilation, connection establishment and cache fill distort early samples.
  • Open arrival rate. Drive both with a fixed number of requests per second rather than a fixed number of virtual users. A closed model slows down when the server slows down and hides queueing, as described in open vs closed workload models. An arrival rate keeps pressure the same for both protocols.
  • Enough samples. Tail percentiles need volume. A p99 from a few thousand requests is noisy. Run long enough that p99 stops moving between repetitions, and repeat the run to see the spread.
  • Client and server CPU. Record both. Two protocols show equal latency while one uses less CPU per request, and that is capacity you gain at higher load. A saturated load generator also makes everything look slow, so check it is not the bottleneck.
  • Percentiles and throughput at a fixed latency target. Report p50, p95 and p99, plus the highest throughput each protocol sustains while p95 stays under your target. Averages hide the tail, and the tail is what users feel.

Load balancing breaks the comparison

gRPC clients keep a small number of long-lived HTTP/2 connections and multiplex calls on them. A Layer 4 load balancer picks a backend once per connection, so all calls from a client land on one backend for the life of the connection. REST over HTTP/1.1 with a connection pool and short-lived connections spreads more evenly by accident.

If you put both services behind the same L4 balancer and compare them, the gRPC side shows uneven load and worse tail latency that comes from distribution, not from the protocol. Use a Layer 7 balancer or proxy that balances per request, or client-side balancing, and confirm in your metrics that backends receive similar request counts. Load balancer uneven distribution explains how to spot this.

A benchmark plan

  1. Profile one real request. Find how much of the service time and CPU goes to encoding, parsing and framing. If it is a few percent, stop here and fix the dominant cost.
  2. Pick the call shapes. Choose one or two unary methods that carry real traffic. Add a streaming scenario only if production uses streaming.
  3. Build equivalent endpoints. Put both interfaces over the same handler. Confirm responses carry identical data.
  4. Define payload sizes. Prepare small, typical and large messages from one source.
  5. Fix the connection policy. Decide on connection reuse, TLS and HTTP version for each run, and write it down.
  6. Choose the load shape. Use a constant arrival rate, a warm-up period and a hold long enough for stable p99.
  7. Check the balancer. Verify that backends receive even traffic for both protocols.
  8. Run each protocol several times. Alternate the order of runs so a warm cache or a noisy neighbour does not favour one side.
  9. Record latency, throughput and CPU. Capture client and server CPU, status codes and backend request counts.
  10. Step the rate up. Find the throughput each protocol reaches before p95 crosses your latency target.
  11. Decide with a threshold. Agree beforehand what difference justifies the migration cost, for example a fixed percentage in CPU per request or in sustainable throughput.

Worked example with hypothetical numbers

The numbers below are an illustration of how to read results. They are not measurements.

A team compares a product lookup in three configurations at a constant 2,000 requests per second with a typical payload of about 1 KB. The backend and handler are shared.

Configurationp50p95p99Service CPU
REST, JSON, HTTP/1.114 ms31 ms58 ms62%
REST, JSON, HTTP/213 ms27 ms49 ms58%
gRPC, protobuf, HTTP/212 ms22 ms36 ms47%

Reading the table: moving REST to HTTP/2 shows the transport effect. Moving from REST on HTTP/2 to gRPC shows the encoding and framing effect on top of it. Comparing only the first and third rows would credit gRPC with the whole gap. The service spends most of its 12 to 14 ms in a database call, so the median barely moves, while the tail and CPU change more.

The team then steps the arrival rate up and records the rate at which p95 reaches 40 ms. In this hypothetical, REST on HTTP/1.1 reaches it at 3,100 requests per second and gRPC at 3,900. The decision depends on what a 25 percent capacity gain is worth against the work of changing clients, tooling and debugging habits. A different payload or a slower database would produce a different table, which is why the team runs the test on its own system.

Tools for the benchmark

  • k6 drives HTTP with k6/http and gRPC with k6/net/grpc, so one tool and one load model cover both sides. Use an arrival-rate executor for a fixed request rate and thresholds on latency percentiles.
  • ghz is a command-line gRPC benchmark for a single method. It is quick for a first look, but it does not share a load model with your HTTP tool, so numbers from different tools are harder to compare.
  • Use the same tool for both protocols where possible. Different tools have different client overhead, connection handling and percentile calculation.

Troubleshooting

  • gRPC looks slower than REST. Check connection reuse first. A client that reconnects per call pays TLS setup on every request.
  • One backend runs hot. An L4 balancer pins long-lived HTTP/2 connections. Balance per request.
  • p99 changes between repeats. The run is too short or the load generator is saturated. Lengthen the hold and check generator CPU.
  • Results differ from a published benchmark. Compare payload, server work and connection policy with the benchmark’s setup. Expect differences.

Run both in MaxoPerf

MaxoPerf runs k6 scripts, and the gRPC load testing guide in the academy shows how to upload .proto files as test assets and call unary methods with k6/net/grpc. For the comparison, create two tests from the same k6 project: one script calls the REST endpoint with k6/http, the other calls the gRPC method. Keep the load profile, duration and runner location identical, and set a failure criterion on p95 latency for both.

Run each test several times, then use the run comparison view to line up percentiles and error rates, as described in comparing runs and baselines. The RPS-controlled throughput cookbook shows how to hold a fixed request rate. If the service is only reachable inside your network, run the load from a private datacenter location so both protocols take the same network path. CPU on the service comes from your own monitoring, so keep it open next to the run.

Questions this article answers

Is gRPC faster than REST?

Often, for the part of the request the protocol controls: serialization, framing and connection handling. Protocol Buffers are smaller and cheaper to parse than JSON, and HTTP/2 multiplexes calls on one connection. If a database query or business logic dominates the request, the two protocols look the same end to end.

Why do published gRPC vs REST benchmarks disagree?

They usually compare different things. One side reuses connections while the other opens a new one per call, payloads differ, servers do different work, or REST runs on HTTP/1.1 while gRPC runs on HTTP/2. Until those variables match, the difference is not attributable to the protocol.

Should I run REST over HTTP/2 for a fair comparison?

Yes, and you should when your production REST traffic uses it. Comparing gRPC on HTTP/2 against REST on HTTP/1.1 measures two changes at once. Run REST on both HTTP/1.1 and HTTP/2 if you want to separate the transport effect from the encoding effect.

Which metrics should a gRPC vs REST benchmark report?

Latency at p50, p95 and p99, throughput at a fixed latency target, error and status-code counts, and client and server CPU. CPU per request shows the cost of encoding and parsing even when latency looks equal.