QA
Senior LevelREST APIs & Web Services

How do you tune Brotli compression quality settings to balance CPU vs network payload bandwidth?

❓ Interview Prompt: Explain Brotli compression quality levels (1 to 11), CPU execution overhead vs compression ratio trade-offs, static asset pre-compression vs dynamic API compression.

Brotli ('br') provides 15%-25% higher compression ratios than Gzip, but higher quality levels demand exponentially more CPU compute time:

Quality Level Tuning Strategy:

•
Quality 1 to 4 (Dynamic APIs): Low CPU overhead (~1-2 ms latency). Ideal for dynamic JSON API responses generated on the fly.
•
Quality 11 (Static Assets / Pre-Compressed Specs): Maximum compression ratio, but takes hundreds of milliseconds of CPU compute time. Ideal for pre-compressing static OpenAPI JSON specs or client SDK bundles during build time!

Code Implementation Example

typescript
import zlib from 'zlib';

// Dynamic JSON API Brotli compression setting (Quality Level 4 for optimal CPU/ratio balance)
const brotliOptions = {
  params: {
    [zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_TEXT,
    [zlib.constants.BROTLI_PARAM_QUALITY]: 4 // Level 4 for dynamic APIs!
  }
};
💡Configuring Brotli compression quality settings for dynamic API responses in Node.js.
🎯 Interview Key Takeaway

Tune Brotli compression to Quality Level 4 for dynamic API responses to balance CPU latency against bandwidth reduction.

#Brotli#Compression#Performance#Senior
Back to all REST APIs & Web Services Questions→

More REST APIs & Web Services Interview Questions

Beginner LevelREST APIs & Web Services

What is HTTP Method Idempotency and how do you implement Idempotency Keys for REST APIs?

Beginner LevelREST APIs & Web Services

What are standard HTTP Status Codes (200, 201, 204, 400, 401, 403, 404, 409, 429, 500, 503)?

Beginner LevelREST APIs & Web Services

What are HTTP Verbs (GET, POST, PUT, PATCH, DELETE) and when to use PUT vs PATCH?