Getting Started with Hasura GraphQL Remote JOINs on Multi-Cloud Distributed SQL

Getting Started with Hasura GraphQL Remote JOINs on Multi-Cloud Distributed SQL

In this tutorial we show you how to issue Hasura GraphQL queries that join data from 2 different databases, hosted in 2 different clouds, into a single result set.

Remote Joins in Hasura GraphQL extend the concept of joining data across tables, to being able to join data across tables and remote data sources. In this blog post we are going to demonstrate this capability by configuring the following set up.

  • A 3 node YugabyteDB cluster running on GKE with a Hasura GraphQL Engine attached
  • A 3 node YugabyteDB cluster running on AKS with a Hasura GraphQL Engine attached
  • A Remote Schema and Remote Relationship configured
  • The ability to issue GraphQL queries that join data from two different databases, hosted in two different clouds, into a single result set

how to get started with hasura graphql remote joins on multicloud distributed sql with yugabytedb

First things first, for those of you who might be new to either distributed SQL or YugabyteDB…

What Is Distributed SQL?

Distributed SQL databases are becoming popular with organizations interested in moving data infrastructure to the cloud or to cloud native environments. This is often motivated by the desire to reduce TCO or move away from the scaling limitations of monolithic RDBMS like Oracle, MySQL, and SQL Server. The basic characteristics of Distributed SQL are:

  • SQL API for querying and modeling data, with support for traditional RDBMS features like primary keys, foreign keys, indexes, stored procedures, and triggers.
  • Automatic distributed query execution so that no single node becomes a bottleneck.
  • A distributed SQL database should support automatically distributed data storage. This includes indexes which should be automatically distributed (aka sharded) across multiple nodes of the cluster so that no single node becomes a bottleneck for ensuring high performance and high availability.
  • Distributed SQL systems should also provide for strongly consistent replication and distributed ACID transactions.

For a deeper discussion about what Distributed SQL is, check out, “What is Distributed SQL?”

What Is YugabyteDB?

YugabyteDB is an open source, high-performance distributed SQL database built on a scalable and fault-tolerant design inspired by Google Spanner. YugabyteDB is PostgreSQL wire compatible and supports GraphQL along with advanced RDBMS features like stored procedures, triggers, and UDFs.

Got questions? Make sure to ask them in our YugabyteDB Slack channel. Ok, let’s dive in…

Step 1: Install YugabyteDB on GKE

Here are the complete steps to install a 3 node YugabyteDB cluster on Google Kubernetes Engine. Once you have a YugabyteDB cluster running on GKE, check the status of the cluster by executing the command below:

$ kubectl get services --namespace yb-demo

NAME                    EXTERNAL-IP        PORT(S)
yb-tserver-service       35.224.XX.XX        5433:3067/TCP

Note the external IP for yb-tserver-service which we are going to use to establish a connection between YugabyteDB and Hasura GraphQL Engine. From the output above we can see that the IP is 35.224.XX.XX and the YSQL port is 5433.

Step 2: Create the Northwind Sample Database

In our documentation, you can find a variety of sample databases that are compatible with YugabyteDB. For the purposes of this tutorial we are going to use the Northwind sample database. The Northwind database contains the sales data for a fictitious company called “Northwind Traders,” which imports and exports specialty foods from around the world. The Northwind database is an excellent tutorial schema for a small-business ERP, with customers, orders, inventory, purchasing, suppliers, shipping, employees, and single-entry accounting.

Connect to the yb-tserver-pod by running the following command:

$ kubectl exec -n yb-demo -it yb-tserver-0 /bin/bash

To download the schema and data files, run the following commands:

$ wget https://raw.githubusercontent.com/yugabyte/yugabyte-db/master/sample/northwind_ddl.sql
$ wget https://raw.githubusercontent.com/yugabyte/yugabyte-db/master/sample/northwind_data.sql

Note: If the Google Cloud Shell tells you that the wget command does not exist, you can execute:

$ yum install wget -y

To connect to the YSQL service, exit out of the pod shell and run the following command:

$ exit 

$ kubectl exec -n yb-demo -it yb-tserver-0 -- ysqlsh -h yb-tserver-0.yb-tservers.yb-demo

Create a database and connect to it using the following commands:

yugabyte=## CREATE DATABASE northwind;
northwind=## \c northwind;

We can now create the database objects and load them with data using the files we downloaded to yb-tserver-pod using the following commands:

northwind=## \i 'northwind_ddl.sql';
northwind=## \i 'northwind_data.sql';

By default, a YugabyteDB installation doesn’t have a password setup for the default yugabyte user. Specifying one is done the same way you’d do it in PostgreSQL.

northwind=## ALTER ROLE yugabyte WITH PASSWORD 'password';

Step 3: Set Up Hasura on GKE to Use YugabyteDB

We are now ready to install the Hasura GraphQL Engine on GKE. Exit the YSQL shell and get the Hasura Kubernetes deployment and service files by executing the commands below.

$ wget https://raw.githubusercontent.com/hasura/graphql-engine/master/install-manifests/kubernetes/deployment.yaml
$ wget https://raw.githubusercontent.com/hasura/graphql-engine/master/install-manifests/kubernetes/svc.yaml

Modify the database URL in deployment.yaml file to include the IP of YugabyteDB. For the purposes of this tutorial, the modification should look like this:

value: postgres://yugabyte:[email protected]:5433/northwind

Note: If you’d like everything to run in the yb-demo namespace, make sure to modify the namespace value in both the deployment.yaml and svc.yaml files. This is the setup I have chosen for this demo.

After saving the file, use kubectl to create a Hasura deployment using the commands below:

$ kubectl create -f deployment.yaml

deployment.apps/hasura created
$ kubectl create -f svc.yaml

service/hasura created

To find the external IP and open the Hasura console execute the command below:

$ kubectl get services --namespace yb-demo 

NAME       EXTERNAL-IP     PORT(S)                                    hasura     35.192.XX.XX    80:30546/TCP

Now use http:///console to access the Hasura console. In this case it is 35.192.XX.XX. You should now see the Hasura console.

access the hasura console distributed sql multicloud tutorial blog post yugabytedb

databases distributed sql google cloud platform graphql how to kubernetes microsoft azure postgresql hasura multicloud

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

50+ Useful Kubernetes Tools for 2020 - Part 2

Our original Kubernetes tool list was so popular that we've curated another great list of tools to help you improve your functionality with the platform.

Introduction to Structured Query Language SQL pdf

SQL stands for Structured Query Language. SQL is a scripting language expected to store, control, and inquiry information put away in social databases. The main manifestation of SQL showed up in 1974, when a gathering in IBM built up the principal model of a social database. The primary business social database was discharged by Relational Software later turning out to be Oracle.

Getting Started With SQLPad and Distributed SQL on Google Kubernetes Engine

See how to install a 3 node YugabyteDB cluster on Google Kubernetes Engine, build the sample Northwind database, build and configure SQLPad, and more! In this blog post we’ll show you how to: Install a 3 node YugabyteDB cluster on Google Kubernetes Engine, Build the sample Northwind database, Build and configure SQLPad, Start the required SQLPad processes, Launch the SQLPad UI and issue a test query to validate the deployment.

Migrating SQL workloads to Microsoft Azure: Databases Trip to Azure SQL Database

In this article, we will discuss how to migrate an on-premises SQL Server database to Microsoft Azure SQL Database.

Microsoft Innovates Its Azure Multi-Cloud, Multi-Edge Hybrid Capabilities

During the recent Ignite virtual conference, Microsoft announced several updates for their Azure multi-cloud and edge hybrid offerings. These updates span from security innovations to new edge capabilities.