Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction and Insights of the Hasura-based Architecture

KazukiHayase
September 13, 2023

Introduction and Insights of the Hasura-based Architecture

KazukiHayase

September 13, 2023
Tweet

More Decks by KazukiHayase

Other Decks in Technology

Transcript

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

    View Slide

  2. Kazuki Hayaseʢ@KazukiHayaseʣ
    ● Frontend Engineer at BuySell Technologies


    ● Currently working on the management system for
    listing items on e-commerce websites


    ● GraphQL / TypeScript / Golang

    View Slide

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

    View Slide

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

    View Slide

  5. 01
    What is Hasura?

    View Slide

  6. ● 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?

    View Slide

  7. What is Hasura?
    Table creation Auto-generated GraphQL schema

    View Slide

  8. ● 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

    View Slide

  9. Hasura has the ability to integrate GraphQL and REST endpoints


    ● Remote Schemas


    ● Actions
    Federation

    View Slide

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

    View Slide

  11. 02
    Overall Architecture

    View Slide

  12. Overall Architecture

    View Slide

  13. ● 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

    View Slide

  14. ● 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

    View Slide

  15. ● In Remote Schema, it returns only the 'id'


    ● In Hasura, fetching data from the database based on the 'id'
    Elasticsearch

    View Slide

  16. 03
    Pros and Cons

    View Slide

  17. 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

    View Slide

  18. 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

    View Slide

  19. ● 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

    View Slide

  20. 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

    View Slide

  21. ● 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

    View Slide

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

    View Slide

  23. 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

    View Slide

  24. ● 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

    View Slide

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

    View Slide

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

    View Slide

  27. ● 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

    View Slide

  28. ● 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

    View Slide

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

    View Slide

  30. 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

    View Slide

  31. 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

    View Slide

  32. ● 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

    View Slide

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

    View Slide

  34. ● 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

    View Slide

  35. Tuning the database is difficult
    GraphQL Query Corresponding SQL query

    View Slide

  36. ● 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

    View Slide

  37. 04
    Conclusion

    View Slide

  38. ● 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

    View Slide

  39. THANK YOU

    View Slide