GraphQL as a high-performance�cross-database query language
Predrag Gruevski �
Outline
Outline
GraphQL as most commonly used
Product backend
SQL �query
GraphQL
Browser
Relational database
N+1 queries problem
for data_id in get_ids_from_database():
get_data_from_database(data_id)
N + 1 = 1 query to look up N identifiers� + N queries to look up their data
N+1 queries solution: compile your GraphQL
for data_id in get_ids_from_database():
get_data_from_database(data_id)
N + 1 = 1 query to look up N identifiers� + N queries to look up their data
Avoiding the N+1 problem
Product backend
SQL �query
GraphQL
Browser
Relational database
GraphQL data access layer
GraphQL
Avoiding the N+1 problem
https://bit.ly/2kaaOQe
Operations on “createdAt”
Operations on “updatedAt”
Operations on “deletedAt”
Operations on “firstName”
Outline
If your company’s architecture looks like this
Product backend
SQL �query
GraphQL
Browser
Relational database
then you have truly found paradise, enjoy it!
Paradise Lost: before long, it’ll turn into this
Product backends
Product backends
Graph databases
Timeseries databases
Document stores
Relational databases
ML model training
Analytics
Product backends
various graph �query languages
SQL
various timeseries �query languages
document store APIs
Paradise Regained: can we have this instead?
Product backends
Product backends
???
Graph databases
Timeseries databases
Document stores
Relational databases
ML model training
Analytics
Product backends
various graph �query languages
SQL
various timeseries �query languages
document store APIs
Paradise Regained: can we have this instead?
Product backends
Product backends
???
Graph databases
Timeseries databases
Document stores
Relational databases
ML model training
Analytics
Product backends
various graph �query languages
SQL
various timeseries �query languages
document store APIs
common �query interface
Paradise Regained: can we have this instead?
Product backends
Product backends
???
Graph databases
Timeseries databases
Document stores
Relational databases
ML model training
Analytics
Product backends
various graph �query languages
SQL
various timeseries �query languages
document store APIs
millions of lines of stitched schema
Paradise Regained: can we have this instead?
Product backends
Product backends
???
Graph databases
Timeseries databases
Document stores
Relational databases
ML model training
Analytics
Product backends
various graph �query languages
SQL
various timeseries �query languages
document store APIs
Product�domain
Infrastructure�domain
Paradise Regained: everyone is happy
Paradise Regained: everyone is happy
Paradise Regained: everyone is happy
Paradise Regained: GraphQL compiler
Product backends
Product backends
GraphQL compiler
Graph databases
Timeseries databases
Document stores
Relational databases
ML model training
Analytics
Product backends
various graph �query languages
SQL
various timeseries �query languages
document store APIs
GraphQL syntax, with more powerful semantics
millions of lines of auto-generated cross-db schema
Rules we have to break
Rules we have to break
Outline
interface GeographicArea {
name: String
uuid: ID
in_GeographicArea_SubArea: [GeographicArea]
out_GeographicArea_SubArea: [GeographicArea]
}
type Country implements GeographicArea {
alpha2: String
alpha3: String
name: String
uuid: ID
in_GeographicArea_SubArea: [GeographicArea]
out_GeographicArea_SubArea: [GeographicArea]
in_Airport_BasedIn: [Airport]
in_Airline_RegisteredIn: [Airline]
}
type Region implements GeographicArea {
name: String
uuid: ID
in_GeographicArea_SubArea: [GeographicArea]
out_GeographicArea_SubArea: [GeographicArea]
}
interface GeographicArea {
name: String
uuid: ID
in_GeographicArea_SubArea: [GeographicArea]
out_GeographicArea_SubArea: [GeographicArea]
}
type Country implements GeographicArea {
alpha2: String
alpha3: String
name: String
uuid: ID
in_GeographicArea_SubArea: [GeographicArea]
out_GeographicArea_SubArea: [GeographicArea]
in_Airport_BasedIn: [Airport]
in_Airline_RegisteredIn: [Airline]
}
type Region implements GeographicArea {
name: String
uuid: ID
in_GeographicArea_SubArea: [GeographicArea]
out_GeographicArea_SubArea: [GeographicArea]
}
type Airline {
alpha2_country: String
callsign: String
iata_code: String
icao_code: String
id: Int
name: String
in_FlightRoute_OperatingAirline: [FlightRoute]
out_Airline_RegisteredIn: [Country]
}
type Airport {
alpha2_country: String
city_served: String
elevation_ft: Int
iata_code: String
icao_code: String
id: Int
name: String
in_FlightRoute_FromAirport: [FlightRoute]
in_FlightRoute_ToAirport: [FlightRoute]
out_Airport_BasedIn: [Country]
}
type FlightRoute {
id: Int
stops: Int
out_FlightRoute_FromAirport: [Airport]
out_FlightRoute_OperatingAirline: [Airline]
out_FlightRoute_ToAirport: [Airport]
}