Scaling GraphQL backend with Hasura and YugabyteDB

Web / Mobile / VR / AR / IoT / AI

Software architect, consultant, author

What is GraphQL

GraphQL

A query language for your API

What about Architecture

Microservices architecture 

3factor.app Architecture

How do you start with backend?

  • Code your own
  • Use Hasura 
  • Use AWS AppSync

What is Hasura

open source and free engine that gives you auto-generates real-time GraphQL API on top of new or existing PostgreSQL database

Features

  • Can be deployed to any cloud or run locally
  • Compatible with all Authentication solutions
  • Can run on top of new or existing Postgres database
  • Supports Postgres addons (PostGIS, TimescaleDB)
  • Auto-generates GraphQL api
  • GraphQL queries are compiled to performant SQL statements using native Postgres features

Features

  • Comes with hasura-cli which has awesome tools like migrations and more
  • Can work with custom SQL statements
  • Has configurable access controls for data
  • Can be connected to your own GraphQL server (does schema stitching)
  • Has eventing system which enables to trigger serverless functions

Let's see it in action

Download docker-compose.yaml

wget https://raw.githubusercontent.com/hasura/graphql-engine/stable/install-manifests/docker-compose/docker-compose.yaml
docker-compose up

Hasura Console overview

  • GraphiQL - run your queries in in-browser IDE
  • Data - manage your data, access control, relations, permissions
  • Remote Schemas - stitch GraphQL schema of your custom GraphQL server
  • Event Triggers - connect your serverless functions

GraphiQL tab - use for development

  • Set endpoint headers
  • Execute queries and mutations
  • Analyse queries

Data tab - data management interface

  • View and insert data into db
  • create and modify tables
  • Create relationships
  • set permissions and access control
  • execute custom sql statements

Remote Schemas tab

stitch your custom GraphQL server schema

Event triggers

  • connect custom webhooks to database events to execute serverless functions
  • set retry logic
  • forward custom headers to webhook

 

Authentication

Run hasura locally on top of existing postgres

GraphQL meets Distributed SQL

Create local YugabyteDB cluster

yb-ctl create --rf 3 

Connect to ysqlsh

./bin/ysqlsh --echo-queries

Load sample data

Run Hasura on top of newly created Db

docker run -d -p 8080:8080 -e \ 
HASURA_GRAPHQL_DATABASE_URL=postgres://postgres:@host.docker.internal:5433/yb_demo \
-e HASURA_GRAPHQL_ENABLE_CONSOLE=true hasura/graphql-engine:latest

Let's see it in action

Thank You

  @VladimirNovick