tags

Using Azure Cosmos DB for PostgreSQL & Hasura GraphQL

12 October, 2022 | 3 min read

Today Microsoft announced General Availability for Azure Cosmos DB for PostgreSQL. This brings significant features to PostgreSQL on Azure by leveraging the power of Azure Cosmos DB. Because Azure Cosmos DB for Postgres is True PostgreSQL, this means you can now connect Hasura to Cosmos DB and get instant GraphQL APIs!

This blog post will provide a high-level overview of how to integrate Hasura with the new Azure Cosmos DB for Postgres.

Note: This post explores connecting Hasura with Azure Cosmos DB for PostgreSQL and hasn't been tested for full support / compatibility yet. Azure Cosmos DB eco-system supports various flavours like NoSQL/MongoDB/Cassandra etc and we are currently only exploring the PostgreSQL support with Hasura.

How to get started:

It is easy to get started with both Hasura and Azure Cosmos DB for Postgres.

  1. Sign up for a Hasura Cloud account
  2. Create a project in the Hasura Cloud Account
  3. Sign up for the Azure Cosmos DB free trial and select Azure Cosmos DB for PostgreSQL
  4. Once you have completed the sign up for the trial on Azure, this will bring you to the Azure portal

After you have created your trial account on Azure, you will need to reset the password to initialize the trial. You can do this by clicking the Important message in the Azure portal.

Connecting Azure Cosmos DB to Hasura


Now let's connect this new database to our Hasura project.

  1. In the menu on the left in the Azure Portal, select Connection Strings
  2. Copy the PostgreSQL connection URL, we will use this to place in our Hasura Project.
  3. In your Hasura cloud account, edit your project settings and select Env vars.
  4. Add a new Env var called DATABASE_URL and paste your connection URL into the value.
  5. Replace the {your_password} with the password you created when resetting the database.
  6. Save your env variable.
  7. Now we can launch our Hasura Console by clicking Launch Console in the top right.
  8. Go to the Data tab in the Hasura Console.
  9. Click Connect Database
  10. Give the database a name and select Data Source Driver of Citus.
  11. Select Environment Variable for the Connect Database Via setting.
  12. Enter the Environment Variable of DATABASE_URL

Building your Database

Now that you have a Hasura Cloud instance and a database using Azure Cosmos DB for Postgres, you may begin by adding tables or following any of our other getting started guides just as you would with any PostgreSQL DB.

Why Azure Cosmos DB for PostgreSQL?

There are some great benefits to using Azure Cosmos DB for PostgreSQL, including the following:

  1. True PostgreSQL - Microsoft maintains this product with the latest version of PostgreSQL within two weeks of each release.
  2. Managed Cloud Database - Being built on Azure's managed services, you can take the worry out of managing databases. Microsoft Azure provides high availability configurations across availability zones.
  3. Powered by Citus - You can simply start with a small Free Trial and grow it into a highly scalable database with distributed tables. This will handle building a relational database at scale with distributed transactions, deadlocks, foreign keys, and more.
  4. Global Availability - Because Azure Cosmos DB for PostgreSQL is powered by Cosmos DB, you can choose to distribute your database globally with just a few clicks of a button.

Conclusion

Thanks to the outstanding work Microsoft has provided a product that lets you leverage Hasura on a massive global scale. The power of Cosmos DB meets PostgreSQL is an exciting combination that will allow applications scale from a few users to millions of users and adding Hasura, you now have a complete solution for any application you develop.



Subscribe IlluSubscribe Illu

Monthly product updates in your inbox. No spam.

Loading...