> ## Content Index
> Fetch the complete content index at: https://datajutsu.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# gRPC Compression Wraps the Message, Not the Frame (and a Small Message Gets Bigger)
- URL: https://datajutsu.com/grpc-compression-gets-bigger/
- Published: 2026-10-29T09:19:12.000Z
- Updated: 2026-10-29T09:19:12.000Z
- Author: Data Jutsu

The build post in this series names the compression flag byte, zero for plain and one for gzip, but it does not say what happens to the bytes once that flag is set, or when setting it actually helps. I wanted both, so I turned on compression in a real grpc-js call, caught the bytes on the wire, and measured the sizes. The result was not what I expected for the small messages.

I started with a seven byte message, the string field holding hello. Framed plain it is twelve bytes on the wire, the flag, a four byte length, seven payload bytes. I compressed the same message and framed it, and it came out twenty eight bytes. It got bigger, by sixteen. The gzip container has a fixed floor that has nothing to do with your data: the two byte magic, the flags byte, the OS byte, two bytes of time, and then at the very end a four byte checksum plus a four byte size trailer. That floor sits right around twenty bytes before a single byte of payload is in. So a message smaller than the floor pays the floor to shrink and ends up larger than it started. I swept the size and it crosses under the plain frame somewhere around thirty bytes, and only for repetitive content. An empty or tiny message, compressed, is pure overhead.

The byte order is where the real mistake hides, and it is easy to get wrong. The correct order is to gzip the message, and then put the frame header on the compressed bytes: flag one, the length of the compressed payload, the compressed bytes. The receiver gunzips the payload and gets the message back, which starts with the protobuf tag 0x0a. The mistake is to frame the message first, gzip the whole frame, and then frame that again. Now the payload gunzips to a whole inner frame, a flag byte, a length, then the message, so one extra five byte header is riding inside the compressed bytes. The receiver gunzips, sees a flag and a length where it expected the first protobuf tag, and it either misreads the message or throws. Compression is one layer around the message, and the frame is one layer around that. Not the frame inside the compression.

Two more things bite in the real library. The flag byte has to agree with the header: one only when grpc-encoding is set to gzip on the call, zero when it is not, and a one with no header, or gzip bytes under a zero, is a protocol violation the other side surfaces as a decode error. The second one is in grpc-js itself. The channel option that turns compression on is grpc.default\_compression\_algorithm, and it wants a number. Pass it the string gzip and it logs an invalid value line and your message sails out with flag zero, uncompressed, no error. Pass it two and the client sets the gzip header and writes flag one with a payload that gunzips back to the message. The algorithm map is numeric, zero identity, one deflate, two gzip. A plain client still reads a gzipped response without any option, it advertises that it accepts gzip and gunzips on the way in, so you only need the option when you are the one sending the compressed bytes.

Compression only pays on repetitive or structured bytes, which is why the sizes are the only honest signal. A two thousand byte message of random bytes compressed to two thousand and twenty eight, it grew by twenty three. A repeated field full of the same string, or a map with many similar keys, is where gzip actually bites. A field of random ids, or bytes that are already compressed somewhere upstream, is where it does not. The encode tab at [proto.datajutsu.com](https://proto.datajutsu.com/?ref=datajutsu.com) does the framing for you, uncompressed or gzip, and it prints the flag and both sizes above the output. Those two numbers, the plain length and the compressed length, are exactly the pair that tells you whether this particular call got bigger or smaller, and the answer changes with the content, not the flag.

So the flag byte is one bit and the decision it makes is whether the bytes after the length are the message or a gzipped copy of the message. Keep the wrap order right, the frame around the compression and not the other way, keep the flag and the header in agreement, and remember the floor. Below roughly thirty bytes you are paying to shrink. The [https://proto.datajutsu.com/?ref=datajutsu.com](decode tab) reads a flag one payload back to the message the same way, and the [https://datajutsu.com/build-grpc-request-body/?ref=datajutsu.com](request body post) is where the frame header itself is built. A compressed frame is not always a smaller one, and the sizes are the only thing that tells you which.