An edge-first reference architecture for a small SaaS
How far can you get with a TypeScript monorepo, serverless functions at the edge, and a managed database? Further than you'd think. Here's the layout we're using, and where it bends.
When you’re building a SaaS product as a small team, the expensive resource isn’t compute. It’s attention. Every server you patch and every queue you babysit is time not spent on the product.
The shape
thequantaspace.com → static marketing site + blog (this site)
app.thequantaspace.com → web app (SPA or SSR), served from the edge
api.thequantaspace.com → typed HTTP API on edge functions
├─ Postgres (managed, with connection pooling)
├─ object storage for uploads
└─ queues for background jobs
Three deployables, one repository, one language.
Why split marketing from the app?
The marketing site and blog change for content reasons; the app changes for product reasons. Keeping them separate means a broken migration can never take the blog down, and the blog can stay a fast, static, fully cacheable site.
The API layer
A small, typed router on edge functions with a shared schema package covers most of what an early SaaS needs:
app.post('/v1/projects', auth(), validate(CreateProject), async (c) => {
const input = c.req.valid('json');
const project = await db.projects.create({ ...input, ownerId: c.var.user.id });
return c.json(project, 201);
});
The same CreateProject schema validates requests on the server and generates types for the client SDK.
Where it bends
- Long-running work (exports, model calls over a minute) belongs on queues and workers, not request handlers.
- Database latency from the edge is real. Keep the database in one region close to most users, and cache reads aggressively.
- Heavy compute (video, large ML models) may eventually need dedicated machines. That’s a good problem to have.
- #saas
- #cloudflare
- #architecture
- #typescript