Technical document

Designing the Migration of a Dysfunctional TypeScript Execution Platform to Go, Edge, and Single SPA

We will organize the design decisions and gradual steps for migrating from a situation where server-side TypeScript execution systems became difficult to maintain operationally, to Go, Cloudflare, and Single SPA.
Architecture / Migration Design~16 minPublication Date September 22, 2026Update date November 23, 2026
Illustration of an engineer organizing distributed execution systems into a Go, edge, and Single SPA configuration

Summary

Key points of this document

  • The starting point for the migration is the operational fact that 'TypeScript doesn't work'.
  • The server side will be consolidated into a single Go binary, and the frontend will retain TypeScript.
  • Tenant resolution is handled at the edge, while ultimate security is guaranteed by the backend and DB.

Overview

The reason for this migration is not that TypeScript as a language is bad. As the number of server-side TypeScript execution environments increased, and execution processes, service boundaries, artifacts, and deployment procedures became dispersed, it became difficult to keep modified code running under the same assumptions. By retaining browser-side TypeScript and reorganizing the execution infrastructure to be Go-centric, we will reduce the operating conditions and the boundaries of responsibility.

The starting point for the migration is the operational fact that 'TypeScript doesn't work'.

TypeScript offers the convenience of writing browser UI, server APIs, batches, development tools, and CI auxiliary processes all in the same language. On the other hand, as the number of server-side execution environments increases, each process requires individual alignment of dependent runtimes, artifacts, environment variables, startup methods, and health checks. Code passing type checks and stable operation at the deployment target are separate conditions.

This migration started from the premise that server-side execution environments written in TypeScript became difficult to maintain due to the combination of increased service boundaries and operational procedures. Instead of deciding 'not to use TypeScript,' we will redefine which runtime is responsible for which process. The UI running in the browser will continue to use TypeScript, while the core of APIs, data access, and resident processes will shift to Go.

If we start a complete rewrite without making this distinction, the goal will become merely replacing the language. First, we will differentiate whether the cause of the malfunction is a code bug, an inconsistency in the execution environment, or a misalignment in contracts between services. Then, the objective of the migration will be to reduce recurring execution boundaries.

  • Verify the success of type checking separately from the success of startup, connection, and termination in the production runtime.
  • Frame the problem by the number of execution processes and operational boundaries, not by language preference.
  • Decide on browser-side TypeScript and server-side runtime selection separately.

The server side will be consolidated into a single Go binary, and the frontend will retain TypeScript.

The goal for the server side is to consolidate multiple execution environments into a Go modular monolith. HTTP routing, authentication, tenant resolution, domain processing, and external integration will be separated by responsibility within a single process, reducing the number of build artifacts and startup conditions. It is important not to equate module separation with service separation.

The reason for choosing Go is that server code is easy to handle as a single static binary, and it's easier to standardize Cloud Run startup/shutdown, memory usage, and concurrency measurements. Instead of packing everything into one giant package, we fix the dependency direction apps → addons → packages and maintain internal boundaries at the domain level.

Meanwhile, the UI will retain TypeScript as a Single SPA using React and Vite. Since API contracts are generated from Protobuf, and the browser side receives types and React Query hooks, the static benefits of TypeScript can be maintained. We avoid the chain reaction of 'since the server is Go, the frontend should also be a different language,' and only shift boundaries related to the purpose of the change.

  • Reduce server-side execution conditions and leverage TypeScript's type safety on the UI side.
  • Separate module division from service division to avoid excessively increasing deployment units.
  • Focus the migration target on 'broken boundaries' and do not unconditionally replace working UIs.
// Conceptual diagram separating runtime responsibilities
browser:   React + Vite + TypeScript
           |  generated client from .proto
           v
edge:      Cloudflare Pages Functions
           |  tenant resolution / API proxy
           v
backend:   Go modular monolith on Cloud Run
           |  auth / domain / validation / SQLC
           v
database:  PostgreSQL on Cloud SQL

Tenant resolution is handled at the edge, while ultimate security is guaranteed by the backend and DB.

When providing the same application to multiple brands or organizations, it's essential to first determine which tenant a request belongs to. In the target configuration, Cloudflare Pages Functions read the Host, and retrieve a mapping of domains to tenant IDs from Cloudflare KV. Then, tenant information is added to the API request, and the entry points for static assets and APIs are separated at the edge.

However, simply trusting the headers added by the edge is insufficient. On the Cloud Run side, we verify if the information came from an authorized path and inject the tenant into the request context. Furthermore, the tenant ID is mandatorily passed as an argument to queries generated by SQLC, ensuring that all data retrieval includes isolation conditions. This design confirms the same boundary across three layers: edge, application, and DB.

Cloudflare KV is a projection for fast lookups and not the authoritative source of correct brand information. The DB is the master, and KV is updated via update events or synchronization processes. It's also necessary to decide during migration how to prevent unknown domains from being incorrectly routed to a default tenant if KV updates are delayed.

  • Do not assign the same role to KV, which is for speed, and the DB, which is the authoritative source for correctness.
  • Re-validate the edge's resolution result on the backend, and reject unknown values on the safe side.
  • Make the tenant ID a mandatory argument for DB queries, not relying solely on screen-side filtering.
// Tenant Boundary Verification Order
request
  -> edge: Host -> tenant_id (KV lookup)
  -> backend: verify edge metadata
  -> context: attach tenant_id
  -> query: WHERE tenant_id = $1
  -> response: never cross tenant boundary

We are moving to a Single SPA to ensure that an increase in screens does not directly lead to an increase in services.

While delivering frontends as multiple independent applications offers deployment flexibility, it increases the burden of aligning common shells, dependent libraries, authentication, brand settings, and release order. In a configuration where every new screen adds a service, container, remote entry, and monitoring target, it becomes difficult to keep everything in the same state, even before considering whether TypeScript will run.

Therefore, we integrate into a Single SPA using React Router, suppressing initial load with route-based lazy loading and Vite's Code Splitting. The design uses a single source and, in principle, a single build artifact, ensuring that code for unused domains is not sent to the browser from the start. By reducing runtime remote dependencies like Module Federation, we can minimize the number of version combinations required to display screens.

This approach is not suitable for teams that require independent deployments. If a complete release lifecycle is needed for each domain, maintaining multiple applications might be better. In this decision, we prioritized deployment consistency due to the high frequency of simultaneous updates to common authentication, brand injection, and API contracts.

  • Consolidate shared shells and contracts into a single build to reduce runtime dependency combinations.
  • Use React.lazy and manualChunks to suppress the increase in initial load due to integration.
  • Determine if independent deployment is truly necessary based on team operations and release frequency.

For APIs and DBs, reduce manual duplication and unify the generation path.

If API inputs and outputs are defined separately in Go and TypeScript, a runtime error will remain if only one is updated. After migration,.protowe will make Protobuf the canonical source for API contracts, and use buf generate to create Go server types, TypeScript client types, and React Query hooks. Manual coding will be limited to contract and domain implementation, reducing boundary transformation code.

For the DB, we will manage schemas with Atlas HCL and generate Go typed access code from SQL with SQLC. Instead of entrusting all queries to an ORM, we will keep SQL readable and review tenant isolation conditions, indexes, and transaction boundaries. Generation is convenient, but generated artifacts should not be the basis for correctness. Reviewing the input schemas, SQL, and Protobuf comes first.

In this configuration, the order of API and DB changes is also important. First, add new fields, create a period where the old version can be read, populate data, confirm usage, and then delete unnecessary items. Since application rollback and DB rollback are not the same operation, destructive changes will not be mixed into a single release.

  • Place API contracts in one location and generate Go and TypeScript types from the same input.
  • Do not hide SQL too much; make tenant conditions and transactions reviewable.
  • Separate additions, migrations, and deletions to allow for both application rollback and DB changes.
// Process for adding a new API
1. write API contract      -> proto/service.proto
2. generate clients         -> buf generate
3. write domain behavior    -> Go handler/service
4. write SQL                 -> queries/*.sql
5. generate DB access        -> sqlc generate
6. verify compatibility     -> proto breaking + sqlc verify

Operational design is as important as language replacement.

Even if you migrate to Go, if builds and deployments remain manual, operational problems will merely shift elsewhere. We will use Bazel to track Go and SPA dependencies and remote cache to reduce rebuilds. Dagger will be used to codify the generation, testing, image creation, and deployment flow, enabling the same verification procedures to be reproduced locally and in CI. Nix Flakes will be used to pin versions of Go, Node.js, Bazel, buf, etc.

Deployment destinations will be split: static files to Cloudflare Pages, edge processing to Pages Functions, APIs to Cloud Run, and data to Cloud SQL. Cloud Run allows selecting 0-scale in its initial settings, which reduces resident costs when usage is low. However, cold starts, DB connection counts, and external API timeouts will be measured in practice, and settings will only be changed when necessary.

Monitoring will not collect all information from the start. Go panics, handler errors, DB timeouts, React rendering errors, and payment/external integration validation failures will be sent to Sentry. Performance Monitoring and Session Replay will not be unconditionally enabled; we will start by linking error occurrences to releases.

  • Codify build, generation, test, and deployment procedures to reduce differences in execution environments.
  • 0-scale is a cost-based choice, not a reason to avoid measuring latency or DB connection counts.
  • Narrow down monitoring targets and first create evidence that links failures to releases.

Porting will proceed in small steps, in the order of execution infrastructure, contracts, features, and deployment.

If a full migration is done in a single cutover, TypeScript execution failures, authentication, data isolation, UI differences, and deployment settings will all fail simultaneously. First, set up the development environment and build reproducibility, then create the Go Core API skeleton, DB schema, and Protobuf contracts. After that, implement authentication and tenant boundaries, and port domain functions one by one.

The frontend creates the Single SPA entry point and brand injection, connecting from a single screen with the generated API client. Cloudflare and Cloud Run deployments do not bundle static assets, APIs, and DB changes into the same release; instead, they verify readiness, key smoke tests, and data isolation between tenants step by step.

During migration, we record how long the old version will remain, which data will be dual-written, and where to roll back in case of a switchover failure. It is also important not to delete old assets prematurely before the full Go migration is complete. The completion criteria for porting are not merely 'the new code compiles,' but rather the confirmation of functional equivalence, contract compatibility, monitoring, and recovery procedures.

  • Verify the reproducibility of the execution environment before porting functionality.
  • Treat authentication, tenant isolation, and processes involving money or data as independent validation axes.
  • Decide the deletion criteria for the old version first, and retain the possibility of rollback during migration.
// Phased Migration Order
phase 0  reproducible toolchain and build
phase 1  Go core / schema / proto contracts
phase 2  auth / tenant resolution / authorization
phase 3  domain behavior and Single SPA routes
phase 4  Cloudflare / Cloud Run / database rollout
phase 5  equivalence tests / observability / rollback proof
phase 6  retire old runtime only after evidence is complete

Separate problems that will be solved by migrating to Go from those that will not.

Go makes it easy to create single binaries, which helps standardize server execution conditions. However, issues like forgetting to add tenant IDs to SQL, handling authentication cookies, retrying external APIs, and the order of DB migrations do not become safer just by changing the language. Even after migration, contract tests, permission tests, data isolation tests, and recovery verification during failures are still necessary.

Furthermore, while Single SPA enhances release consistency, it also tends to consolidate frontend changes into the same artifact. Without proper ownership per domain, scope of impact, Code Splitting, and route-level testing, a single monolithic frontend can become the new bottleneck. We regularly review what should be aggregated and what should remain independent.

This design assumes a separation of responsibilities between the frontend, which continues to use TypeScript, and the server/control systems, which will be migrated to Go. Instead of replacing everything with another language because TypeScript stopped working, we only migrate the parts where execution conditions fluctuate significantly. This boundary is a decision that simultaneously reduces migration costs and future operational risks.

  • Independently verify runtime stability and the security of authentication, authorization, and data integrity.
  • Manage the aggregation effects of Single SPA and the risk of bloat through Code Splitting and ownership boundaries.
  • Define language migration completion criteria by evidence of equivalence, observability, and recovery, not just compilation.

The decision criterion for migration is not the language itself, but 'can it run under the same conditions?'

When TypeScript stops working, the first thing to consider is not abandoning TypeScript. It's identifying which execution boundary, which dependencies, and which deployment conditions are misaligned. In this design, we retain browser-side TypeScript, consolidate the server-side into a single Go binary, and organize boundaries with Cloudflare's edge, Single SPA, Protobuf, and SQLC.

The success of a migration is not determined solely by the completion of design documents or the successful build of a new language. We verify, one by one, that the changed code can be generated and validated with the same toolchain, that tenant boundaries are maintained at each layer, and that we can roll back to the old version if something fails. Rebuilding a working state means transferring operational conditions and verifiability, not just moving code.

Technical documents

We will continue to increase technical documentation.

We will continue to organize our thoughts on AI, cloud, business app development, requirements definition, and operational design into documents.

Go to technical documentation list