API performance Level 1 This level · 1 of 10
Easy java backend

Compress with gzip or brotli

The 30 second answer

For larger text responses like JSON, I enable gzip or brotli compression on the server or the load balancer. Text compresses very well, so transfer time drops a lot, especially on slow networks. I set a minimum size so tiny responses are not compressed, because the CPU cost is not worth it, and I skip already compressed content such as images.

Could you say this in an interview?

Content-Encoding compresses the response body. Brotli (RFC 7932) usually compresses text better than gzip. In Spring Boot, set server.compression.enabled=true; it applies only above min-response-size (default 2KB). Spring Boot's embedded servers support gzip. Editor's note: brotli is usually handled at a proxy or CDN.

Sources (3)
  1. RFC 9110 §8.4 Content-Encodingrfc-editor.org
  2. RFC 7932: Brotlirfc-editor.org
  3. Spring Boot: Enable HTTP response compressiondocs.spring.io
Previous
Next