/docs/vps/go-sidecar

Go Sidecar

What is the Go Sidecar?

The Go Sidecar is an optional high-performance reverse proxy written in Go that sits between Caddy and your Next.js process. It serves prerendered HTML pages directly from memory, handling repeated requests in under a millisecond without touching Node.js.

Request flow

Browser
  โ”‚
  โ–ผ  HTTPS
Caddy (:443)
  โ”‚
  โ”œโ”€ Static assets (/_next/static/*)  โ”€โ”€โ–บ served by Caddy directly
  โ”‚
  โ””โ”€ Page requests  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ Go Sidecar (:3001)
                                             โ”‚
                                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                    โ”‚  cache hit?       โ”‚
                                    โ”‚  < 0.5 ms        โ”‚
                                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                        no   โ”‚  yes
                                        โ”‚    โ””โ”€โ”€โ–บ return cached HTML
                                        โ–ผ
                                   Next.js (:3000)
                                        โ”‚
                                   renders page
                                        โ”‚
                                   sidecar caches
                                   response + returns

Capabilities

In-memory page cache

Radix-tree keyed cache stores full HTML responses. Invalidated on deploy.

Image optimisation

Resizes and converts images to WebP/AVIF on first request, caches the result.

Transparent fallback

Cache miss or sidecar crash: Caddy falls back to Next.js directly. Zero downtime.

Worker pool

Configurable goroutine pool prevents thundering-herd on cache population.

Configuration (nextdeploy.yml)

# nextdeploy.yml
name: my-app
region: nairobi-1

gosidecar:
  enabled: true
  port: 3001
  max_image_workers: 4
  cache:
    max_entries: 2000
    ttl: 3600            # seconds; 0 = cache until next deploy
    exclude:
      - /api/*
      - /dashboard/*     # never cache authenticated pages
  image_optimization:
    enabled: true
    formats: [webp, avif]
    quality: 85

Deploy commands

The sidecar binary is bundled with the NextDeploy CLI and uploaded during nextdeploy prepare. No separate installation needed.

# Validate config and upload the sidecar binary to your VPS
nextdeploy prepare

# Build your app, transfer the bundle, run health check, flip traffic
nextdeploy ship

# Verify sidecar is running and check cache stats
nextdeploy sidecar status

# Flush the page cache without redeploying
nextdeploy sidecar purge