When I built version 3 of Headcode CMS, I followed the architecture almost every SaaS engineer reaches for by default: one multi-tenant Rust backend sitting in front of a shared Postgres database, every route scoped with /p/<project>/mcp, every query filtered by a project ID. It worked. It also carried weight I kept questioning.
For version 4, I stripped the stack down to the simplest thing that could possibly scale — and extracted the foundation into mstack, an open-source Rust MCP kit. One binary, one embedded Turso database file, roughly 8 MB of RAM, and a ~14 ms boot time. Here is why single-tenant beats shared clusters for agent backends.
The hidden tax of multi-tenant MCP servers
A shared Postgres cluster sounds neat on paper until you operate real internal services for companies and agencies:
- Blast radius in every query. Forget one
WHERE project_id = ?clause and tenant A reads tenant B's data. When AI agents generate queries and call tools all day, structural isolation beats discipline. - Network hops and cold starts. Even a fast Rust function waits on database handshakes and region latency. In our v3 tests, putting functions in one region and Postgres in another pushed a single MCP call to around a second.
- Heavy orchestration overhead. Kubernetes or full PaaS stacks easily burn 1–2 GB of RAM before your first service answers a single request.
Most internal MCP services — a CMS, a supplier lookup tool, an invoicing bridge, a reporting service — do not have 100 tables or 100 million rows. Treating every one of them like a hyperscale multi-tenant cluster is classic over-engineering.
What single-tenant on mstack looks like
In mstack, every service or website gets its own tiny container and its own embedded turso 0.9 database file — the Rust rewrite of SQLite with MVCC (BEGIN CONCURRENT) and online VACUUM INTO snapshots. There is no tenant_id, no project_id, and no external database cluster to wire up. Routes are simply /mcp and /health.
What that delivers in production:
- ~14 ms startup, including running schema migrations.
- ~7–8 MiB of RAM per running service.
- ~70 MiB total overhead for Uncloud (Caddy HTTPS + WireGuard mesh) on the host.
- 100+ isolated internal MCP services comfortably fitting on a single €4 ARM64 server.
Backups stop being cluster surgery: run an online VACUUM INTO snapshot and push the encrypted file with restic to S3. Need to move a busy service to a bigger server? Move one container and one .db file across the Uncloud WireGuard mesh with zero DNS propagation wait.
Copy, own, adapt — the shadcn/ui model for backends
I do not want mstack to become a black-box framework crate that traps you behind clever traits and macros. I prefer the philosophy popularized by shadcn/ui: plain, readable code you own directly in your repository.
mstack ships small Rust modules in a registry (mcp.rs, auth.rs, db.rs, events.rs, members.rs, skills.rs, storage.rs). When your coding agent scaffolds a new service, it copies those files straight into src/kit/ and records their versions in mstack.json.
- Plain functions and structs — add a trait only when a second implementation exists.
- No repository abstraction layer; SQL sits right next to the handler that uses it.
- No
unwrap()orexpect()on request paths. - Built on
rmcp 3.11, the official Rust SDK for MCP, including built-in MCP Skills (skills-fs) with SHA-256 verification.
Because coding agents can read every line of src/kit/ without digging into hidden crates, they debug faster and over-engineer far less.
Zero-PII auth and a clean workflow boundary
Authentication stays out of the individual services. One shared Better Auth instance (services/auth) handles magic links, OAuth 2.1, dynamic client registration, and SSO when needed. Every mstack service verifies short-lived RFC 9068 JWTs via multi-issuer JWKS and stores only the opaque sub ID — never email addresses or user profiles.
We also drew a hard boundary for background work: deterministic, service-local jobs (bulk imports, exports, backups, re-indexing) belong inside the MCP service as MCP Tasks backed by its own Turso database. Cross-service or LLM-driven workflows belong outside, in the calling agent or orchestrator, triggered via HMAC-signed webhooks from the service's transactional outbox table.
Always pick the simplest architecture that scales. One binary and one database file per service eliminate whole categories of operational and security failure.
The honest trade-offs
Single-tenant embedded databases are not magic. They make two explicit trade-offs:
- 1–2 seconds of container swap on deploys. A single-writer embedded DB uses stop-first restarts (
SIGTERM+ ~14 ms boot). For cached frontends like Next.js, visitors never notice; for hard zero-millisecond write streams, you would pick a different database. - Not for massive single-service datasets. If one service genuinely needs 100+ tables, 100 million rows, or Postgres-specific extensions, use Postgres. For the other 90% of internal MCP backends, an embedded file wins on speed, isolation, and cost.
Headcode CMS is the first full production app built on mstack. Explore the mstack repository on GitHub or follow Install Headcode in five minutes.