Slide 1

Slide 1 text

Matt Valley Twitter: @mattvalleycodes E-Mail: [email protected] Presented at: SydJS Meetup, Jan 2020 GraphQL at :Different A case study

Slide 2

Slide 2 text

Full service property management for just $100/month :Different With our fixed monthly fee & responsive dashboard, landlords enjoy full transparency whilst saving time & money. different.com.au

Slide 3

Slide 3 text

Technical Debts

Slide 4

Slide 4 text

MySQL DB 01

Slide 5

Slide 5 text

Database as the representation of UI Our data is structured and stored based on some UI screens that either don’t exist or changed.

Slide 6

Slide 6 text

The Billion Dollar Mistake Almost EVERYTHING in our database in nullable!

Slide 7

Slide 7 text

Normalised Database The database is highly normalised, you need a handful of JOINs to get the data you need.

Slide 8

Slide 8 text

Complicated Data Models Complicated data models. difficult to understand even by engineers

Slide 9

Slide 9 text

DB <> Code Bridge 02

Slide 10

Slide 10 text

Lack of abstraction Not much of abstractions between backend code and the DB, makes it hard to start refactoring our DB.

Slide 11

Slide 11 text

Duplicate Data-fetching logic repeated data fetching logic across the codebase, you should always remember to not fetch DELETED (soft) records

Slide 12

Slide 12 text

RESTish API 03

Slide 13

Slide 13 text

Way too many endpoints Way too many endpoints with heaps of overlaps

Slide 14

Slide 14 text

Lack of Reusability Lack of reusability, endpoints serve often a single UI screen

Slide 15

Slide 15 text

For the next API! Goals

Slide 16

Slide 16 text

Front-end Agnostic & Reusable As startup, we have plenty of technical challenges to address with minimum amount of engineering resources. Many of the tools we build at Different might change in future and some had changed completely in the past so having a back-end that is not coupled with front-end as well as being reusable is a must. We wanted an API that does not require constant work to cover new use cases.

Slide 17

Slide 17 text

Act as “Data Access Layer” Not only an API, we need a Data Access Layer for our platform. A bridge between database(s) and applications (internal, external — backend or front-end). We were looking for a way to stop devs from connecting to db directly but simply ask the data access layer for the data they need. Make the underlying databases invisible to the apps.

Slide 18

Slide 18 text

Months with GraphQL 12

Slide 19

Slide 19 text

Migration to GraphQL GraphQL fits well to our approach of multi-phase migration One mobile app is fully built on top of GraphQL Backend services started using GraphQL Front-end apps are using GraphQL Engineers using GraphQL instead of DB

Slide 20

Slide 20 text

Suggestions

Slide 21

Slide 21 text

Develop framework-agnostic Be prepared for switching from one framework to another framework. GraphQL is a young community and as it becomes more mature, you will have better options. Be prepared for migration to other frameworks.

Slide 22

Slide 22 text

Start small with GraphQL types Don’t forget that you can always introduce new fields as you need them so start with what you need and introduce new fields and types later.

Slide 23

Slide 23 text

Don’t over-use GraphQL types We used to introduce a type for a single argument that our mutation fields accept whereas we could simply accept multiple arguments! Simply over-using types

Slide 24

Slide 24 text

Train Consumers Our mobile team needed help to understand the concept and how to use GraphQL. They used to over-fetch data.

Slide 25

Slide 25 text

Over-fetching Have a plan for consumers that over fetch the data. Think about query complexity and how that can impact performance of your GraphQL API.

Slide 26

Slide 26 text

Think about mutation APIs are not all about fetching data but also about mutations and that’s something that you need to also think about it.

Slide 27

Slide 27 text

Perf Optimization and Caching Think early about your data fetching logic as well as your strategy on caching

Slide 28

Slide 28 text

Micro GraphQL Services? That sounds like a good topic for a talk but think about this one as well!

Slide 29

Slide 29 text

Спасибо! Twitter: @mattvalleycodes Email: [email protected] LinkedIn: https://www.linkedin.com/in/matthew-valley/