Streaming & Performance

Streaming, coalescing, compression, and performance optimizations

Overview

SBproxy is built for high-performance request processing with advanced transport features that optimize throughput and reduce latency across all traffic types.

Capabilities

  • HTTP/2 - Multiplexed connections with header compression
  • Request coalescing - Deduplicate identical concurrent requests, reducing origin load by 30-60%
  • Request hedging - Send parallel requests to multiple backends, use the first response
  • Chunk streaming - Serve cached response prefixes while streaming the rest from origin (100-500ms TTFB improvement)
  • Connection pooling - Reusable connections with configurable pool size and keep-alive
  • DNS caching - Built-in DNS cache with configurable TTL
  • Compression - Per-origin response compression with zstd, brotli, and gzip support

Compression

SBproxy compresses responses per origin using the algorithm the client prefers, based on the Accept-Encoding request header. Supported algorithms are zstd, br (brotli), and gzip. List them in preference order and SBproxy selects the first one the client accepts. Responses smaller than min_size bytes are passed through uncompressed.

proxy:
  http_bind_port: 8080

origins:
  "api.example.com":
    action:
      type: proxy
      url: https://test.sbproxy.dev
    compression:
      enabled: true
      algorithms: [zstd, br, gzip]
      min_size: 1024

Test it:

curl -H "Host: api.example.com" -H "Accept-Encoding: zstd, br, gzip" http://localhost:8080/

PROXY Protocol

When SBproxy runs behind a Layer 4 load balancer such as AWS NLB or HAProxy, the load balancer wraps each TCP connection with a PROXY protocol header that carries the original client IP and port. Enable PROXY protocol on the proxy listener so SBproxy can read those headers and populate the real client IP in logs, rate limiting, and IP filtering policies.

Restrict PROXY protocol to trusted load balancer CIDR ranges. Connections from addresses outside trusted_cidrs are rejected to prevent IP spoofing.

proxy:
  http_bind_port: 8080
  proxy_protocol:
    enabled: true
    trusted_cidrs:
      - 10.0.0.0/8

Both PROXY protocol v1 (text) and v2 (binary) are accepted automatically. No additional configuration is needed to distinguish between them.

Test it by sending a PROXY protocol v1 header in front of a plain HTTP request:

printf "PROXY TCP4 1.2.3.4 10.0.0.1 12345 8080\r\nGET / HTTP/1.1\r\nHost: api.example.com\r\n\r\n" | nc localhost 8080