Share
Embed
Transcript
39 slides
-
Introduction and Insights of the Hasura-based Architecture Meetup #21 Guest
talk and lightning talks 2023.09.13 -
Kazuki Hayaseʢ@KazukiHayaseʣ • Frontend Engineer at BuySell Technologies • Currently
working on the management system for listing items on e-commerce websites • GraphQL / TypeScript / Golang -
Agenda What is Hasura? 01 Overall Architecture 02 Pros and
Cons 03 Conclusion 04 -
• 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? -
• 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 -
Hasura has the ability to integrate GraphQL and REST endpoints
• Remote Schemas • Actions Federation -
Federation Remote Schema is a feature that merges your remote
GraphQL schemas and provides you with a single, unified GraphQL API -
• 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 -
• 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 -
• In Remote Schema, it returns only the 'id' •
In Hasura, fetching data from the database based on the 'id' Elasticsearch -
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 -
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 -
• 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 -
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 -
• 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 -
Hasura takes on the role of the Federation Layer Federation
setting Authorization setting -
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 -
• 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 -
Cons 01 Managing configuration files can be difficult 02 Knowledge
of the tables is required to write queries 03 Tuning the database is difficult -
Cons 01 Managing configuration files can be difficult 02 Knowledge
of the tables is required to write queries 03 Tuning the database is difficult -
• 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 -
• 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 -
Cons 01 Managing configuration files can be difficult 02 Knowledge
of the tables is required to write queries 03 Tuning the database is difficult -
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 -
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 -
• 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 -
Cons 01 Managing configuration files can be difficult 02 Knowledge
of the tables is required to write queries 03 Tuning the database is difficult -
• 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 -
• 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 -
• 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