Compression Interview Questions and Answers (15 Must-Know Questions)

Master API Compression with 15 interview questions and answers. Learn GZIP, Brotli, HTTP compression, Content-Encoding, Accept-Encoding, Spring Boot compression, payload optimization, and enterprise best practices.

Introduction

As modern applications exchange increasingly large amounts of JSON, XML, HTML, CSS, JavaScript, and other data, network bandwidth often becomes a major performance bottleneck. Even if an API executes quickly, transferring large payloads over the network can significantly increase response times.

Compression reduces the size of request and response payloads before transmission. Smaller payloads consume less bandwidth, improve response time, reduce cloud networking costs, and provide a better user experience, especially on mobile and slow network connections.

Modern web applications commonly use GZIP and Brotli compression. Web servers, API gateways, CDNs, and Spring Boot applications automatically negotiate compression through HTTP headers such as Accept-Encoding and Content-Encoding.

Compression is one of the most frequently asked interview topics for Java Backend, Spring Boot, Microservices, Cloud, DevOps, API Gateway, and Solution Architect interviews.


What You'll Learn

  • Compression Fundamentals
  • HTTP Compression
  • GZIP
  • Brotli
  • Accept-Encoding
  • Content-Encoding
  • Spring Boot Compression
  • Compression Trade-offs
  • Enterprise Best Practices
  • Interview Tips

Enterprise Compression Architecture

            Mobile App / Browser
                     │
                     │ Accept-Encoding: gzip, br
                     ▼
               CDN / API Gateway
                     │
                     ▼
             Spring Boot Service
                     │
              JSON Response
                     │
                     ▼
          Compress (GZIP/Brotli)
                     │
                     ▼
          Smaller Response Payload
                     │
                     ▼
                 Client Browser

Compression Flow

Client Request

↓

Accept-Encoding: gzip

↓

Spring Boot API

↓

Generate JSON

↓

Compress Response

↓

Content-Encoding: gzip

↓

Return Response

1. What is Compression?

Answer

Compression is the process of reducing the size of data before transmitting or storing it.

Benefits include:

  • Faster API responses
  • Reduced bandwidth usage
  • Lower cloud costs
  • Better mobile performance
  • Improved scalability

Compression is especially beneficial for large payloads.


2. Why is Compression Important?

Answer

Compression improves API performance by reducing the amount of data transferred across the network.

Benefits:

  • Faster downloads
  • Faster uploads
  • Lower latency
  • Reduced network congestion
  • Better customer experience
  • Lower CDN costs

Compression is a standard optimization for modern APIs.


3. What is HTTP Compression?

Answer

HTTP Compression compresses HTTP request and response bodies before they are transmitted.

Workflow

Client

↓

Accept-Encoding

↓

Server

↓

Compressed Response

↓

Client Decompresses

HTTP compression is transparent to the application.


4. What is GZIP?

Answer

GZIP is the most widely used HTTP compression algorithm.

Advantages:

  • Excellent compatibility
  • Good compression ratio
  • Supported by nearly all browsers
  • Supported by API Gateways
  • Supported by Spring Boot

GZIP is the default compression algorithm for many enterprise applications.


5. What is Brotli?

Answer

Brotli is a modern compression algorithm developed by Google.

Advantages:

  • Better compression ratio
  • Smaller payload sizes
  • Optimized for web applications
  • Excellent browser support

Comparison

GZIP Brotli
Faster compression Better compression ratio
Excellent compatibility Smaller payloads
Common API usage Common CDN/Web usage

6. What is the Accept-Encoding Header?

Answer

The client uses the Accept-Encoding header to tell the server which compression algorithms it supports.

Example

Accept-Encoding: gzip, br

The server selects the best supported algorithm before sending the response.


7. What is the Content-Encoding Header?

Answer

The server uses Content-Encoding to indicate which compression algorithm was applied.

Example

Content-Encoding: gzip

The client automatically decompresses the response.


8. How Does Spring Boot Support Compression?

Answer

Spring Boot provides built-in response compression.

Example

server.compression.enabled=true
server.compression.mime-types=application/json,text/html,text/plain
server.compression.min-response-size=1024

Compression is applied automatically for eligible responses.


9. Which Content Types Should be Compressed?

Answer

Common compressible content:

  • JSON
  • XML
  • HTML
  • CSS
  • JavaScript
  • CSV
  • Plain text

Generally, these should not be compressed again:

  • JPEG
  • PNG
  • MP4
  • ZIP
  • PDF (already compressed in many cases)

Compressing already compressed files provides little benefit.


10. What are the Trade-offs of Compression?

Answer

Compression offers many benefits but also introduces CPU overhead.

Benefit Trade-off
Smaller payloads Additional CPU usage
Faster network transfer Compression time
Lower bandwidth cost Higher server utilization

Compression should be enabled where network savings outweigh CPU costs.


11. What are Common Compression Mistakes?

Answer

Common mistakes include:

  • Compressing tiny payloads
  • Compressing images
  • Double compression
  • Ignoring CPU utilization
  • Compressing encrypted archives
  • Wrong MIME type configuration
  • Missing browser compatibility testing
  • Compressing streaming data unnecessarily
  • Ignoring gateway configuration
  • Not monitoring compression ratios

These issues can reduce performance rather than improve it.


12. What are Enterprise Compression Best Practices?

Answer

Recommended practices:

  • Enable GZIP by default
  • Support Brotli where available
  • Compress only suitable content types
  • Configure minimum response size
  • Monitor CPU utilization
  • Use CDN compression
  • Enable API Gateway compression
  • Test compression ratios
  • Avoid double compression
  • Monitor network savings

These practices optimize both performance and infrastructure costs.


13. How Does Compression Improve API Performance?

Answer

Compression helps engineering teams:

  • Reduce payload size
  • Improve response time
  • Lower bandwidth consumption
  • Reduce cloud networking costs
  • Improve mobile performance
  • Increase throughput
  • Improve customer experience

Compression is one of the simplest network optimization techniques.


14. How is Compression Used in Microservices?

Answer

Example

Client

↓

API Gateway

↓

Spring Boot Service

↓

Compressed JSON

↓

Client

Compression may be handled by:

  • Spring Boot
  • NGINX
  • API Gateway
  • CDN
  • Service Mesh

Many organizations enable compression at multiple infrastructure layers.


15. What Does an Enterprise Compression Architecture Look Like?

Answer

           Mobile • Web • Partner APIs
                    │
                    │ Accept-Encoding
                    ▼
               CDN / WAF
                    │
                    ▼
              API Gateway
                    │
                    ▼
            Spring Boot APIs
                    │
             JSON / XML Data
                    │
                    ▼
           GZIP / Brotli Engine
                    │
                    ▼
      Compressed HTTP Response
                    │
                    ▼
              Client Browser

Enterprise Components

  • Browser
  • Mobile App
  • CDN
  • API Gateway
  • Spring Boot
  • GZIP
  • Brotli
  • NGINX
  • Load Balancer
  • Prometheus
  • Grafana

Compression Summary

Component Purpose
Compression Reduce payload size
GZIP Standard HTTP compression
Brotli High-ratio compression
Accept-Encoding Client-supported algorithms
Content-Encoding Compression used
Spring Boot Automatic compression
API Gateway Network optimization
CDN Edge compression
MIME Types Compression eligibility
Minimum Response Size Prevent unnecessary compression

Interview Tips

  1. Explain compression as reducing payload size to improve network performance.
  2. Clearly differentiate GZIP and Brotli, including compatibility and compression efficiency.
  3. Explain the role of Accept-Encoding and Content-Encoding headers in HTTP content negotiation.
  4. Describe how Spring Boot enables automatic response compression using server configuration.
  5. Discuss which MIME types should and should not be compressed.
  6. Explain the CPU versus bandwidth trade-off when enabling compression.
  7. Mention enabling compression at the API Gateway or CDN layer for centralized optimization.
  8. Discuss avoiding double compression and compressing already compressed files.
  9. Highlight monitoring compression ratios, bandwidth savings, and CPU utilization.
  10. Use enterprise examples from banking, e-commerce, media streaming, and cloud-native APIs to demonstrate compression strategies.

Key Takeaways

  • Compression reduces payload size, resulting in faster API responses and lower bandwidth usage.
  • HTTP compression commonly uses GZIP and Brotli algorithms.
  • Accept-Encoding allows clients to advertise supported compression algorithms.
  • Content-Encoding tells clients which compression algorithm was applied.
  • Spring Boot provides built-in support for automatic response compression.
  • JSON, XML, HTML, CSS, and JavaScript are ideal candidates for compression.
  • Images, videos, ZIP archives, and many PDFs should generally not be compressed again.
  • Compression introduces CPU overhead, so configuration should balance compute and network efficiency.
  • API Gateways, CDNs, and web servers often handle compression in enterprise environments.