29 Oct 2026 · Hardening & Ops
Self-Hosting a Next.js 15 AI SaaS, Architecture and Cost
Serverless limits vs a 4.50 euro Hetzner VPS, unit costs at 1k to 50k MAU, and when a starter kit beats wiring Stripe and Caddy yourself.
Serverless is a good default until the product is an AI agent. Then duration caps, cold starts, and stream egress start to set the architecture, not your ORM.
The free containerized baseline for this architecture is open-source: Agentic-Packs/agenticpacks-oss. Keep it open while you read the cost table.
The serverless AI hangover
Vercel Pro and AWS Lambda are billed on execution time and outbound data. An agent that calls a model, tools, and a second model is not a 200ms handler.
| Constraint | Typical serverless cap | What an AI SaaS actually does |
|---|---|---|
| Duration | 10s to 60s on common plans, 300s on the expensive tier | LangGraph loops plus Tavily plus summarization often run 30s to 3 min |
| Streaming | Proxy and platform buffers, extra GB-out pricing | Token SSE for the whole generation |
| Cold start | Hundreds of ms to several seconds on Node | First chat after idle feels broken |
| Connections | Stateless functions vs a resident Postgres pool | Prisma plus pgvector wants a long-lived process |
| Webhooks | Need a reachable URL with fast ACK | Stripe and GitHub retries if you burn the budget on the first 10s |
You still pay the model vendor. Serverless adds a second meter on the glue: function GB-seconds, Fast Data Transfer, concurrent executions. At low traffic that meter is noise. At 10k MAU with streaming chat it is the line item you notice. For the reverse-proxy side of streaming egress, see Configuring Caddy for Next.js 15 SSE Streaming.
The alternative: about 4.50 euro per month
A Hetzner CX22 / CX23 (or CAX11 ARM) running Docker Compose:
- Next.js 15 standalone on port 3000, unpublished
- PostgreSQL 16 on 5432, unpublished
- Caddy on 80/443 with automatic TLS
That is the topology in the Docker + Caddy guide. AgenticPacks OSS is Compose plus Postgres locally. Pro adds Caddy, Terraform, and the Hetzner TLS path.
You trade autoscaling for a known monthly invoice and a process that can sit on a stream for minutes.
Cost at 1k, 10k, and 50k MAU
Figures are order-of-magnitude, USD per month, infra only (not OpenAI / Anthropic tokens). Serverless assumes Vercel Pro, a hosted Postgres (Neon or Supabase Pro), and streaming chat as the hot path. VPS assumes one CX23, Caddy, self-hosted Postgres, backups to object storage.
| MAU | Serverless (Vercel Pro + hosted Postgres) | Self-hosted (Hetzner CX23 + Docker + Postgres) |
|---|---|---|
| 1,000 | ~25 to 60 | ~5 to 12 (VPS + backups + domain) |
| 10,000 | ~80 to 250 (function time + egress on streams) | ~5 to 20 (still one node, add a second for DB if chat is heavy) |
| 50,000 | ~400 to 1,200+ | ~30 to 80 (app + dedicated Postgres box, or CX43) |
The VPS column stays flat until CPU or RAM is saturated. The serverless column tracks stream-minutes. If each active user does a few long generations, 10k MAU is not 10x of 1k. It can be 20x.
When you outgrow one node, you still understand the bill: another CX, managed Postgres, or object storage. You do not discover a 4-digit Fast Data Transfer invoice after a launch week of SSE.
Production architecture
browsers / Stripe / GitHub
|
Caddy :443 TLS
|
Docker bridge (unpublished)
+-----------------+------------------+
| |
Next.js 15 App Router PostgreSQL 16
Auth.js v5 (Node, not Edge-only) Prisma
Route Handlers: pgvector (Pro)
/api/chat SSE users, sessions
/api/webhooks/stripe messages, usage
/api/agent LangGraph (Pro) Stripe customer ids
background: cron / worker |
(report jobs, RAG ingest) |
| |
+-------- Stripe API ---------+
Auth.js v5 session strategy on a VPS is JWT or a database session in Postgres. Skip Edge middleware that assumes Vercel. Keep auth checks in Node Route Handlers and server layouts.
Stripe: checkout session or payment link from a server action, webhook on a dedicated route, raw body for signature verify, then write entitlements before you ACK. The webhook must be fast. Do agent work after the 200.
AgenticPacks OSS ships Auth.js, Prisma, Postgres, streaming chat, Compose, and Free + Pro $19 Stripe checkout with webhooks and a credit counter. Pro adds Caddy, 3-tier Stripe with proration and team credit pools, pgvector RAG, LangGraph, Terraform, Redis.
Build vs buy
Wiring this from a blank create-next-app is not a weekend:
| Piece | Honest hours |
|---|---|
| Standalone Dockerfile, Compose, .dockerignore, swap | 4 to 8 |
| Caddy TLS, Cloudflare Full Strict, SSE flush | 3 to 6 |
| Auth.js v5 + Postgres adapter + OAuth | 6 to 10 |
| Prisma schema, migrations, usage table | 4 to 8 |
| Stripe checkout, webhooks, credits or seats | 8 to 16 |
| Streaming AI route that does not buffer | 4 to 8 |
| Terraform, firewall, backups | 6 to 12 |
| Total | 35 to 70 |
That is before product UI. The 40+ hour number is the floor if you have done it before. First time through Caddy plus Stripe signatures, add a buffer.
Forty hours of Stripe, Caddy, and Terraform is not the product.
Clone the free baseline: Agentic-Packs/agenticpacks-oss.
Or skip the wiring with the Hetzner cost stack in Pro.
A starter is worth it when those hours are not the product. It is not worth it if you only need a marketing page.
Where to Go From Here
You do not have to assemble this from a blank create-next-app. Pick a path based on where the project is.
| Capability | OSS (MIT) | Pro ($149) |
|---|---|---|
| Next.js 15 + Docker | Yes | Yes |
| Auth.js v5 | Email + Google | Magic links + RBAC |
| Postgres + Prisma | Yes | Yes + pgvector RAG |
| Stripe | Single plan ($19/mo) checkout, webhooks & credit counter | 3-tier subscriptions, customer portal upgrades, proration & team pools |
| Agents | None | LangGraph + Tavily |
| Deploy | Compose | Hetzner Terraform + Caddy + Redis |
| Price | Free | 149 USD one-time |
Option A: Free open-source baseline (MIT)
- GitHub: github.com/Agentic-Packs/agenticpacks-oss
- What is included: standalone Dockerfile, Compose, PostgreSQL 16, Auth.js v5, single-plan ($19/mo) Stripe checkout with webhooks and a credit counter, streaming chat
- Cost: free, MIT. Star the repo if this guide saved you a debugging session.
Option B: Ship with AgenticPacks Pro ($149 one-time)
If you would rather not spend 40+ hours on Terraform, Caddy, Stripe webhooks, and agent loops:
- Automated Hetzner provisioning:
terraform applyfor the VPS, firewall, Caddy auto-SSL, and Compose. - Production multi-agent core: LangGraph, pgvector RAG, Redis.
- Usage & Unit Economics: Stripe subscriptions, webhooks, and real-time token-to-dollar cost ledger.
