In the early days of High on Therapy AI, a single Node.js express monolith was sufficient to handle routing, API endpoints, static assets, and even websocket connections. But as the system evolved—adding Zero-IDE, AI-driven wellness engines, and heavy webGL assets—the strain on the monolith became undeniable.
The breaking point
A monolith works well until latency becomes the primary bottleneck. When you're serving developers across the globe, every millisecond counts. We started seeing high TTFB (Time to First Byte) in regions far from our primary datacenter. The UI would load, but the API calls required to render dynamic user configurations would hang for just a little too long, shattering the illusion of an instant, local-feeling OS.
Moving to the Edge
The solution was clear: distribute the logic to where the users are. By leveraging Vercel Edge Functions and Appwrite's globally distributed database, we can execute authentication, rate limiting, and core data fetches closer to the client.
// Example Edge Middleware Snippet
export const config = {
runtime: 'edge',
};
export default async function middleware(req) {
const { geo } = req;
const start = Date.now();
// Authenticate at the edge
const token = req.headers.get('Authorization');
if (!isValid(token)) return new Response('Unauthorized', { status: 401 });
return new Response(JSON.stringify({
status: 'SYS.ACTIVE',
latency: Date.now() - start,
node: geo.city || 'UNKNOWN_NODE'
}), {
headers: { 'content-type': 'application/json' },
});
}
The transition isn't entirely smooth. State management across edge nodes, especially for rate limiting (which historically relied on our in-memory token buckets in Node), requires distributed solutions like Redis (Upstash) or intelligent caching strategies.
But the results? Sub-50ms API responses globally. The OS feels alive again.