Global reach, local performance: Introducing Hasura's multi-region database routing

The speed of your API responses is as crucial as the accuracy of the data they provide. Across all industries, from e-commerce to fintech, users expect apps to be available and responsive, anytime and anywhere.

When user experience can make or break your application, delivering data from the edge has become a key requirement for backend teams developing modern applications. Hasura's Data Delivery Network (DDN), is built from the ground up with this in mind, providing out-of-the-box multi-region support across the globe.

As developers adopt a multi-regional approach to manage their digital products, the need for a system that can seamlessly operate across boundaries while minimizing latency is paramount. Hasura DDN is engineered precisely with this need in mind, offering instant GraphQL APIs on a variety of data sources that are not just local but distributed – positioned close to your users, wherever they might be.

We are excited to announce built-in support for multi-region routing, starting with PostgreSQL family databases.

How it works

The GraphQL API endpoint that Hasura DDN provides is backed by Hasura DDN's edge network. It has an Anycast IP address, where a single IP is allocated for serving the incoming request and the request is routed to the nearest Hasura DDN region. When the request reaches Hasura in one of the regions closest to the client, Hasura will figure out the nearest database location the user has configured through their metadata and routes the request to that database. Hasura will also look to see whether it was a read or a write request and route to the corresponding database replica. In the event of a region failure, Hasura DDN automatically recovers and starts routing to the closest available region.

Let's say you have two database instances, one in EU Frankfurt, which is the primary that can serve reads and writes and another one in US West, which can serve only reads.

We'll look at queries first. Let's say a user is executing a GraphQL query from somewhere in the US. Through Hasura DDN edge network, it reaches the nearest Hasura DDN region, say US West. Hasura DDN will now process the request, and it's already aware that the user has configured the primary in US West. Since it is the closest region, the request is sent to the PostgreSQL connector in the same region and the connector executes the request on the database.

Routing topology for reads

Similarly, if a user is executing a query from somewhere in Europe, it will be sent to the nearest Hasura DDN region, which is EU Frankfurt. And since there is a database configured in that region, the request is directly sent there.

But if a GraphQL query is executed from India, it will reach Hasura DDN region at Bangalore. A database replica has not been configured in the Bangalore region, but Hasura knows that the closest region to Bangalore where a database instance can be found is EU Frankfurt. Hasura will now direct that request to the PostgreSQL connector in EU Frankfurt over Hasura DDN's private network, ensuring a direct path to the connector. The connector will execute the query on the database and sends back a response.

Similarly for writes, since there is only one instance that can service writes, requests from all regions will be routed to that database instance.

Routing topology for writes

Supported databases

All PostgreSQL family databases are supported, including:

Getting started

If you don't have a project setup that lets you query PostgreSQL, please follow this guide. Once you have a working project, you can modify the ConnectorManifest configuration as shown in the example below to enable multi-region routing:

kind: ConnectorManifest
version: v1
    - base
  name: mypg
  type: cloud
    type: hub
    name: hasura/postgres:v0.6.0
    - context: .
      mode: ReadWrite
      region: gcp-us-west2
    - context: .
      mode: ReadOnly
      region: gcp-us-east4
    - context: .
      mode: ReadOnly
      region: gcp-europe-west1

Further details on the configuration can be found in our docs.

What's next

Hasura provides performance, scalability and reliability to developers without additional overheard through built-in support for multi-region routing. We're working on adding multi-region support to all other connectors so that our users can provide reduced latency for their API clients out of the box.

Ready to take Hasura DDN in beta for a spin? Simply click here to start your journey toward a more streamline, modern approach to data architecture and access!

29 Apr, 2024
Subscribe to stay up-to-date on all things Hasura. One newsletter, once a month.
Accelerate development and data access with radically reduced complexity.