Slide 1

Slide 1 text

Introduction and Insights of the Hasura-based Architecture Meetup #21 Guest talk and lightning talks 2023.09.13

Slide 2

Slide 2 text

Kazuki Hayaseʢ@KazukiHayaseʣ ● Frontend Engineer at BuySell Technologies ● Currently working on the management system for listing items on e-commerce websites ● GraphQL / TypeScript / Golang

Slide 3

Slide 3 text

Introduction of the Hasura-based architecture and pros/cons Topic

Slide 4

Slide 4 text

Agenda What is Hasura? 01 Overall Architecture 02 Pros and Cons 03 Conclusion 04

Slide 5

Slide 5 text

01 What is Hasura?

Slide 6

Slide 6 text

● OSS that automatically generates a GraphQL schema from a database schema ● Once the tables are created, CRUD APIs get generated. So a GraphQL server can be built quickly ● Authentication, authorization and federation are also available What is Hasura?

Slide 7

Slide 7 text

What is Hasura? Table creation Auto-generated GraphQL schema

Slide 8

Slide 8 text

● Can be authenticated and authorized by integrating with many popular auth services ● Has a role-based authorization control at row and column level Authentication and Authorization

Slide 9

Slide 9 text

Hasura has the ability to integrate GraphQL and REST endpoints ● Remote Schemas ● Actions Federation

Slide 10

Slide 10 text

Federation Remote Schema is a feature that merges your remote GraphQL schemas and provides you with a single, unified GraphQL API

Slide 11

Slide 11 text

02 Overall Architecture

Slide 12

Slide 12 text

Overall Architecture

Slide 13

Slide 13 text

● Builds a GraphQL server using Golang ○ Merges this GraphQL server into Hasura as Remote Schema ● Using gqlgen for schema-first development ● Complex Queries and Mutations are implemented on this server Custom GraphQL Server

Slide 14

Slide 14 text

● Adopted Elasticsearch to meet the requirements for complex searching ● Implemented integration with Elasticsearch in Remote Schema ○ As of today (September 13th, 2023), Hasura does not support Elasticsearch Elasticsearch

Slide 15

Slide 15 text

● In Remote Schema, it returns only the 'id' ● In Hasura, fetching data from the database based on the 'id' Elasticsearch

Slide 16

Slide 16 text

03 Pros and Cons

Slide 17

Slide 17 text

Pros 01 The implementation effort has been reduced 02 Hasura takes on the role of the Federation Layer 03 Configurations can be managed through the GUI

Slide 18

Slide 18 text

Pros 01 The implementation effort has been reduced 02 Hasura takes on the role of the Federation Layer 03 Configurations can be managed through the GUI

Slide 19

Slide 19 text

● Simple Queries and Mutations can use auto-generated APIs ● There is no need to implement resolvers for those parts ● Overall, auto-generated APIs are used for 90% of Queries and 10% of Mutations ○ Due to the frequent external integration, the proportion of mutations is low The implementation effort has been reduced

Slide 20

Slide 20 text

Pros 01 The implementation effort has been reduced 02 Hasura takes on the role of the Federation Layer 03 Configurations can be managed through the GUI

Slide 21

Slide 21 text

● Hasura federates the REST and GraphQL endpoints ● Federation setting is easily managed through the GUI ● Authorization for the federated target can also be managed with Hasura Hasura takes on the role of the Federation Layer

Slide 22

Slide 22 text

Hasura takes on the role of the Federation Layer Federation setting Authorization setting

Slide 23

Slide 23 text

Pros 01 The implementation effort has been reduced 02 Hasura takes on the role of the Federation Layer 03 Configurations can be managed through the GUI

Slide 24

Slide 24 text

● Most settings can be managed through the GUI ● The settings are exported as YAML files ● Database migrations can also be managed through the GUI Configurations can be done through the GUI

Slide 25

Slide 25 text

Cons 01 Managing configuration files can be difficult 02 Knowledge of the tables is required to write queries 03 Tuning the database is difficult

Slide 26

Slide 26 text

Cons 01 Managing configuration files can be difficult 02 Knowledge of the tables is required to write queries 03 Tuning the database is difficult

Slide 27

Slide 27 text

● Reviewing the YAML configuration files alone is difficult ● In large-scale systems, managing configs through the GUI can actually be more difficult Managing configuration files can be difficult

Slide 28

Slide 28 text

● Making rules related to configuration ● Creating a custom YAML file validator based on the rules and running it in CI ● Additionally, creating a custom tool for modifying YAML files Solutions

Slide 29

Slide 29 text

Cons 01 Managing configuration files can be difficult 02 Knowledge of the tables is required to write queries 03 Tuning the database is difficult

Slide 30

Slide 30 text

Knowledge of the tables is required to write queries With Hasura, the step of defining the GraphQL schema is omitted Usually Using Hasura Table definition GraphQL schema definition Implementation Table definition Implementation

Slide 31

Slide 31 text

Knowledge of the tables is required to write queries Understanding both the GraphQL schema and 
 the table structure is necessary Writing Queries becomes dependent on individual skills

Slide 32

Slide 32 text

● Participating in backend development to get the knowledge of the table structure ○ The team's policy of developing in full-stack is the underlying principle ● Export only the required schema ○ Reducing the cost of schema selection Solutions

Slide 33

Slide 33 text

Cons 01 Managing configuration files can be difficult 02 Knowledge of the tables is required to write queries 03 Tuning the database is difficult

Slide 34

Slide 34 text

● Hasura builds responses using SQL queries, often resulting in complex SQL queries ● Understanding the complex SQL queries is nearly impossible ● It is not possible to modify the SQL query unless fixing the GraphQL Query Tuning the database is difficult

Slide 35

Slide 35 text

Tuning the database is difficult GraphQL Query Corresponding SQL query

Slide 36

Slide 36 text

● We can only monitor slow queries and add indexes ● If this doesn't solve the performance issue, the only option is to implement that Query in the Remote Schema Solutions

Slide 37

Slide 37 text

04 Conclusion

Slide 38

Slide 38 text

● Adopting Hasura has reduced development efforts and allowed us to focus on core logic implementation ○ It's highly recommended for Proof of Concept or creating prototypes ● While there are some cons, we have been able to handle them so far, so overall, we believe it was a good choice to adopt it Conclusion

Slide 39

Slide 39 text

THANK YOU