Skip to content

Add response compression and stream negotiation for API gateway #601

Description

@Smartdevs17

Context

API responses (invoice CSVs, analytics reports, export dumps) can exceed 10MB uncompressed, causing slow downloads and high egress costs.

Current Limitation/Problem

No response compression. Large invoice CSV exports take 30+ seconds to download on mobile connections.

Expected Outcome

Brotli/gzip compression negotiation via Accept-Encoding header, streaming responses for large payloads, and configurable compression level per endpoint.

Acceptance Criteria

  • Compression middleware: Brotli (preferred, level 4 default) and gzip (fallback, level 6) via Accept-Encoding
  • Compression level config: endpoint-level override via x-compression-level response header
  • Minimum size threshold: only compress responses >1KB (skip tiny responses)
  • Streaming: large CSV/JSON responses served with Transfer-Encoding: chunked
  • Skip list: certain endpoints skip compression (streaming video, already-compressed binary)
  • Performance: Brotli reduces JSON payload by 75%, CSV by 85% (measured with sample data)
  • Edge case: client sends unsupported encoding (respond uncompressed with identity Content-Encoding)

Technical Scope

  • backend/shared/middleware/compression.ts - compression negotiator middleware
  • backend/shared/middleware/streaming.ts - streaming response middleware
  • backend/config/ - endpoint-level compression configuration
  • backend/gateway/ - API gateway compression config (if separate)
  • backend/tests/ - compression integration and performance tests

Metadata

Metadata

Assignees

Labels

200-points200 point issueStellar WaveIssues in the Stellar wave programdrips-waveIssues in the Drips Wave programhighHigh complexity issue

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions