cd /news/ai-infrastructure/why-your-streaming-llm-ai-webhooks-b… · home › topics › ai-infrastructure › article
[ARTICLE · art-179353] src=dev.to ↗ pub= topic=ai-infrastructure verified=true sentiment=↑ positive

Why Your Streaming LLM & AI Webhooks Buffer Behind Docker Reverse Proxies (And the 25-Line Caddy v2 Fix)

A developer published a 25-line Caddy v2 configuration for running streaming LLM and AI agent webhook backends behind Docker reverse proxies, addressing SSE token buffering and 504 Gateway Timeout failures. The setup uses flush_interval -1, stream_timeout 30m, and a 300s response_header_timeout on a dedicated handle block for streaming routes, while keeping gzip/zstd compression off those paths. It also recommends persistent /data and /config Docker volumes to avoid re-requesting Let's Encrypt certificates on every restart.

recommendation

Put streaming LLM and webhook routes in their own Caddy handle block with flush_interval -1 and long timeouts, and keep encode gzip/zstd off those paths so tokens flush immediately.

more in playbook: Inference and self-hosting
by read4 min views1 publishedDec 1, 2026

flush_interval -1, response_header_timeout 300s, and stream_timeout 30m on your streaming/webhook handle block, and keep encode gzip outside that route. Your streaming AI chat or multi-step agent webhook works smoothly on http://localhost:8000. Then you put Docker and a reverse proxy in front of it for HTTPS—and suddenly token-by-token SSE streaming stalls, or long reasoning chains crash with 504 Gateway Timeout.

Below is the exact 25-line Caddy v2 production configuration we deploy in 2026 for streaming LLMs, FastAPI AI workers, and n8n webhooks—plus zero-downtime reloads.

Reverse Proxy / Edge Option Auto Let's Encrypt TLS SSE Streaming Config Effort Zero-Downtime Reload Monthly Infra Cost
**Caddy v2 in Docker on Hostinger VPS ** Built-in automatic 3 directives ( flush_interval -1 + timeouts) caddy reload (instant) ~$6.49–$8.79/mo flat VPS
Nginx + Certbot on VPS Manual Certbot cron Requires proxy_buffering off ,X-Accel-Buffering , chunked headers nginx -s reload ~$6.49–$8.79/mo flat VPS
**Managed Edge on Railway ** Built-in automatic Zero config (managed proxy) Managed rolling deploys ~$15–$45+/mo (24/7 metered)

text/event-stream (SSE) LLM outputs, that destroys perceived latency.504 errors.encode gzip zstd on an SSE route causes the compressor to wait for enough bytes to build a compression dictionary, stalling individual tokens.Caddyfile (Copy-Paste Ready) Split your streaming/webhook paths into a dedicated handle block so normal static/JSON routes still benefit from fast defaults while AI routes stream immediately:

{
    email ops@yourdomain.com
}

ai.yourdomain.com {
    handle /v1/chat/completions* {
        reverse_proxy http://ai-backend:8000 {
            flush_interval -1
            stream_timeout 30m
            transport http {
                response_header_timeout 300s
                keepalive 3m
            }
            header_up X-Forwarded-For {remote_host}
            header_up X-Forwarded-Proto {scheme}
        }
    }

    handle {
        encode zstd gzip
        reverse_proxy http://ai-backend:8000 {
            transport http {
                response_header_timeout 60s
            }
        }
    }
}

Always persist /data and /config in named Docker volumes. If you rebuild Caddy without a persistent /data volume, every container restart requests a brand-new Let's Encrypt certificate—hitting Let's Encrypt's weekly rate limit within an hour.

services:
  caddy:
    image: caddy:2-alpine
    restart: unless-stopped
    mem_limit: 256m
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
      - caddy_config:/config
    networks:
      - ai-net

volumes:
  caddy_data:
  caddy_config:

networks:
  ai-net:
    driver: bridge

Note that inside Docker, Caddy connects to your upstream service via the Docker Compose service name (http://ai-backend:8000 or http://n8n-main:5678), never http://localhost:8000.

When you update routes or timeouts in Caddyfile, reload Caddy in-place without dropping active AI streams or TLS sockets:

docker compose exec caddy caddy validate --config /etc/caddy/Caddyfile
docker compose exec caddy caddy reload --config /etc/caddy/Caddyfile

Verify unbuffered streaming immediately using curl -N (--no-buffer):

curl -N -H "Accept: text/event-stream" https://ai.yourdomain.com/v1/chat/completions

If tokens print line-by-line immediately instead of waiting until the stream closes, your proxy is production-ready.

Run Caddy + Docker on Hostinger VPS for your AI APIs, RAG backends, and n8n webhooks—and avoid self-hosting marketing landing pages or email funnels on the same box. Off lead capture, checkout funnels, and automated email sequences to Systeme.io ($0 Free / $27/mo Startup) keeps your VPS footprint minimal and isolates customer-facing marketing uptime from backend deployments.

Reverse proxies buffer responses by default to optimize packet framing. Setting flush_interval -1 inside Caddy's reverse_proxy block disables response buffering so every SSE token chunk streams to the client immediately.

Set response_header_timeout 300s inside transport http to allow up to 5 minutes for initial LLM prefill or multi-step agent execution, and set stream_timeout 30m for lengthy streaming generations.

It can delay token delivery if compression buffers chunks before flushing. Isolating your SSE/streaming endpoint into its own handle block without encode gzip ensures instant token-by-token delivery.

Run docker compose exec caddy caddy validate --config /etc/caddy/Caddyfile followed by docker compose exec caddy caddy reload --config /etc/caddy/Caddyfile. Caddy applies the new config gracefully with zero downtime.

Open-Source Starter Repo: Grab the ready-to-deploy Docker Compose + Caddy + PostgreSQL + Redis stack on GitHub: https://github.com/Soph1yzzz/n8n-ai-agent-docker-stack

Question for builders: What is your current monthly bill (or biggest production bottleneck) running AI agents or webhooks—and are you self-hosting or staying on managed cloud? Drop your stack in the comments.

Full benchmarks, cost tables, and updated 2026 blueprints on AgentStack.

── more in #ai-infrastructure 4 stories · sorted by recency
── more on @caddy 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/why-your-streaming-l…] indexed:0 read:4min 2026-12-01 · —