The Challenge: Latency on Expansion
A SaaS company primarily serving Australian customers faced a critical challenge: expanding to the United States. Their existing infrastructure, a Kubernetes cluster running Go microservices and federated GraphQL/gRPC in Google Cloud Platform (GCP) in Australia, introduced 200-300ms of latency for new US-based users. This delay is unacceptable for a smooth user experience, particularly for their Tutoring and Schools products. The tight launch timeline of less than two months demanded a rapid solution for multi-region routing without necessarily resorting to complex data sharding.
Defining the Requirements for Global Reach
The core requirement was simple: users in the US should be served from a US-centric infrastructure, and Australian users from Australia. This meant routing traffic based on geographic location to minimize latency. While unified data management across regions was considered, the immediate priority was a performant user experience. The solution needed to be implementable within the aggressive two-month window, suggesting a need for a managed, scalable service that could abstract away much of the underlying infrastructure complexity.
Choosing Cloudflare Workers as the Routing Layer
Cloudflare Workers presented an ideal solution. Workers are serverless compute functions that run on Cloudflare's global network of edge locations. This allows developers to execute code close to their users, drastically reducing latency. Instead of users hitting a central Kubernetes cluster in Australia, their requests could be intercepted by Cloudflare's edge infrastructure and routed intelligently. The decision hinged on Workers' ability to act as a global traffic manager, capable of inspecting incoming requests and making routing decisions in milliseconds. This approach avoids the need for immediate, complex data sharding and focuses on optimizing the user-facing delivery path.
The architecture envisioned involved using Cloudflare Workers as the primary entry point for all user traffic. When a request arrives at Cloudflare's network, the Worker script would analyze the request. Based on the detected geographic origin of the request (e.g., IP address lookup), the Worker would then perform a DNS lookup or an HTTP redirect to the appropriate regional backend. For US users, this would point to a new Kubernetes cluster provisioned in the US Central region. For Australian users, traffic would continue to be directed to the existing Australian cluster.

Implementing the Multi-Region Routing Logic
The implementation within Cloudflare Workers involves leveraging built-in features and custom logic. The Worker script would typically start by inspecting the incoming request's properties. Cloudflare provides access to request headers, including information that can infer geographic origin, or developers can utilize IP geolocation services. A common pattern is to use the request.url object to determine the requested path or host, and then use Cloudflare's fetch API to proxy the request to the correct backend.
For example, a Worker script could be configured to serve api.example.com. Upon receiving a request, it would check the originating IP address. If the IP maps to a US location, the Worker would forward the request to the US API endpoint (e.g., us-api.example.com) using fetch. If the IP maps to Australia, it would forward to the Australian endpoint (e.g., au-api.example.com). This proxying happens at the edge, meaning the latency is minimal.
Crucially, this setup requires managing DNS records that point to Cloudflare, and then configuring Cloudflare's DNS to resolve to the appropriate backend origin servers based on the Worker's routing logic. The Worker itself is deployed to Cloudflare's network and becomes the active handler for the domain. This abstracts the complexity of global load balancing and geo-routing away from the application's core microservices.
Handling Unified Data and Future Scalability
While the immediate focus was on routing, the long-term consideration of data management is important. For applications requiring a single source of truth, strategies like multi-region databases with replication, or using specialized global data stores, would be necessary. However, for many SaaS applications, regional data sharding or keeping data separate per region can be a viable strategy, especially if compliance or performance dictates. In this case, the company did not require immediate data unification, simplifying the initial rollout. The ability to deploy Workers globally also means that as the company expands to new continents, the routing logic can be easily updated to include new regional backends without significant architectural changes.
The Impact: Reduced Latency and Global Presence
By implementing a multi-region routing system with Cloudflare Workers, the company effectively addressed the latency issue introduced by its US expansion. Users in the United States now experience significantly lower latency, comparable to what they would expect from a US-based service. This improves user satisfaction and retention. The use of Workers provides a scalable, edge-based solution that is cost-effective and quick to deploy. This architecture also lays the groundwork for future global expansion, allowing the company to add new regions and backends with relative ease. The critical two-month deadline was met by leveraging a managed edge computing platform that handles the complexities of global traffic distribution.
The surprising detail here is not the choice of Cloudflare Workers, which are well-suited for this task, but the speed at which such a critical infrastructure shift can be accomplished when leveraging edge computing. What nobody has addressed yet is the long-term cost implications of maintaining distinct Kubernetes clusters in multiple regions versus a single, highly optimized central cluster with more advanced global traffic management solutions, particularly as traffic scales exponentially.
