SlideShare a Scribd company logo
CASE STUDY
GraphQL for
Native Apps


The MyAXA App
MARCH 22ND, 2019
We will discuss thebest practices, 

architecture patterns and
lessons learned in adopting the
GraphQLAPI query language
in the context of 

theMyAXAnative app.
INTRO
Principal Software Architect @ frog
Emanuele Di Saverio
CS Engineering graduate ’06 from
Rome, started writing embedded
software when Symbian S40 was a
thing. Software Architect for Mobile and
Web, specialising in UX - in the frog pond
since 2011. Former Agile enthusiast, now
just agile, wrote a book about Android.
INTRO
Software Architect
Team Lead iOS @ AXA Italy
Andrea Baldon
Software engineer and architect with
many years spent on coding mobile
apps, deploy backend and frontend sites
plus a bunch of things on IOT and voice
control apps. Actually working on
Disruption technology for AXA
Insurance company.
@hazam
/emanueledisaverio
@ultranano
/baldonandrea
Howmanyofyou

haveaproductleveraging
GraphQLinProduction?
What’sMyAXA
GRAPHQL FOR NATIVE APPS
What’sMyAXA
INTRO
<SECTION>
It’s a completely new way

to explore insurance!

MyAXA is the official app available on
iOS and Android dedicated to customers
who have signed insurance policies with
the AXA Italy Group.
WHAT'S MYAXA
SolutionOverview
GRAPHQL FOR NATIVE APPS
A (very) Conceptual
Architecture
SOLUTION OVERVIEW
AXA Core IT
An App is never just an App
The MyAXA app needs to be joined by a
dedicated middleware layer, cloud-native and
flexible enough to serve mobile-optimized
content.
<SOAP/>
MessageQueues
ETLs
Batch
REST
Proxies
A (very) Conceptual
Architecture
SOLUTION OVERVIEW
AXA Core IT
An App is never just an App
Middleware
The MyAXA app needs to be joined by a
dedicated middleware layer, cloud-native and
flexible enough to serve mobile-optimized
content.
ETLs
Batch
Proxies <SOAP/>
MessageQueues
REST
(Anti-corruption layer, Facade)
Taking the fast track
GraphQL soundness and schema-centricity
enables complex tooling to be developed,
resulting in
• tremendous speedup of FE development
• DRY and modular BE development
This is what we were looking for, and we found it.
An “agile” tool
The most surprising outcome that we didn’t expect
was the flexibility of the tool, and how it affects the
team dynamics, communication and workflow.
The discoverability, flexibility and tooling had direct
impact over team members interactions and
communications.
SOLUTION OVERVIEW
<tl;dr>

GraphQL is custom API Gateway
for all clients,
with one codebase.
Introto

GraphQL
GRAPHQL FOR NATIVE APPS
INTRO TO GRAPHQL
Open from the start
Facebook took care in open-sourcing the whole
spec in 2015, of this new tech they were using
internally, including Relay, they client side library.
There are many implementations of the spec, for
every language.
If you really want to, you would build one yourself.
INTRO TO GRAPHQL
GraphQL is a Specification
https://facebook.github.io/graphql
Relevant Players
The companies really fueling the GraphQL
community are Meteor, Facebook, GraphCool,
Gatsby.
Case studies grow every day!
We’re going to reference the apollo
ecosystem as one of the most widespread and
well documented.
https://www.apollographql.com/
INTRO TO GRAPHQL
The Schema
Types and Operations
GraphQL implementation revolves around
the full specification of
• the data types involved
• the queries
• the data manipulations (Mutations)
Everything is strongly typed - allowing you
be loose everywhere else.
Remote Procedure Call
e.g. gRPC, SOAP, Thrift, Corba
INTRO TO GRAPHQL
GraphQL implements an

API paradigm
Resource-Based Query Language
e.g. REST + HATEOAS, FTP, ODATA e.g. Cipher, SparQL, LINQ, SQL, GraphQL
We scratch our heads to
decompose data to serve UX
FE developers scavenge
the right data
P. Sturgeon - https://philsturgeon.uk/2018/05/21/picking-an-api-paradigm-implementation/
We try decouple tangled
systems
INTRO TO GRAPHQL
Life with
REST
INTRO TO GRAPHQL
GraphQL

equivalent
INTRO TO GRAPHQL
GraphQL is designed to work as
an Evolving Gateway towards
multiple clients
5MonthsLater
GRAPHQL FOR NATIVE APPS
Promises
Kept&Broken
The curse of the multi-model
While at the business level, the model is one, at the
technical level you usually have 3 (or more)
implementations on your app:
• the on-the wire one, between client and server
• the persisted one, to save data on SQLite for example
• the runtime one, used to manipulate data in app
And you have to manage them all!
PROMISES
One Schema to
Rule them All
JSON

Model
Model.swift
SQL
Schema
GraphQL SchemaGraphQL Schema
The GraphQL schema is flexible, opt-in, standard and
strongly typed.
• flexible it has been designed with change in mind as
key feature, so you don’t risk to be locked in
• opt-in clients needs to explicitly write query and ask for
a given field on some type - no way to * !
• strongly typed and standardization allow for powerful
tooling to automate the 3 models
PROMISES
One Schema to
Rule them All
JSON

Model
Model.swift
SQL
Schema
Caveats
• GraphQL schema dictates how you write your code,
it’s not just data spec
• May not translate in a smooth way to all languages -
optionals and fragments
We group here considerations regarding how well the
GraphQL technology and his related implementation
libraries Apollo works with the target technology.
As a powerful abstraction, we expected some impedance
mismatch when analyzing the details and low level
implementation.
And we found some.
PROMISES
Mechanical Sympathy
Minimize Payloads
Query language allows the client to be in control of the
payload, so it can, at any time request only the minimum
amount of data needed on a given Fragment /
ViewController.
No more overfetching!
PROMISES
Mechanical Sympathy:

Network Efficiency 

just what you need
PROMISES
The Big Cookie
R. Meier - Google I/O 2012 - Making Good Apps Great
Mobile is Different
When working over 3G or 4G connections, the
Round Trip Time dominates over bandwidth.
GZIP works better with long payloads, and radio has
“warmup cycles” to exploit.
It’s much better to have “big data sync” requests.
Network queries tend to be more like “get all the
data”
Mechanical Sympathy:

Network Efficiency 

just what you need
Protocol Agnostic
GraphQL is not designed with a specific transport
protocol, but most of the implementations rely on HTTP.
All queries are exposed through a single endpoint
(typically /graph) and through POST with the query
content in the body.
The whole set of HTTP semantic is bypassed.
Caching is a casualty
GraphQL requests are opaque - so they can;’t be cached by
any proxy along the connection.
This means that client apps have to use a client side cache.
PROMISES
Mechanical Sympathy: 

HTTP Caching
PROMISES
Mechanical Sympathy: 

HTTP Caching
A Step Behind in Internet - friendliness
1990s
CORBA
Treat remote objects
as if they were local
2000s
SOAP
Standardize Remote
Method Innovation
2010s
REST
Going back to true
WWW sematics
2015
GraphQL
…we actually don’t
care about HTTP.
Another Casualty
For similar reasons, the HTTP Status-Code based
information is not available - all application-level errors
are 200s, and details are always in the payload.
The actual format is rich and articulated, including
support for partial errors (i.e. errors on only some
branch of the query tree), but overall, doesn’t play well
with what used to be key tenets of HTTP - let alone other
libraries and infrastructure.
PROMISES
Mechanical Sympathy: 

Error Handling
More than just queries
PROMISES
You can use GraphQL for 

all kinds of services
The standard includes support for Mutations:
specific requests that can CRUD data.
Most of the tooling also support Subscriptions:
pub/sub for data changes (i.e. over WebSockets).
Now we can use it for everything, right?
More than just queries A Query Language is for Querying
While we could implement everything, there is no advantage
in implementing “business-rocess” style services over
GraphQL. Examples:
• Logins, Registrations
• Payments, Enrollments
• Wizards
Moreover, support for binary payloads (file down/upload,
streaming) not supported *.
PROMISES
You can use GraphQL for 

all kinds of services
The standard includes support for Mutations:
specific requests that can CRUD data.
Most of the tooling also support Subscriptions:
pub/sub for data changes (i.e. over WebSockets).
Now we can use it for everything, right?
PROMISES
The service 

evolves smoothly and
indefinitely
Grow your Schema
The strategy that is suggested for evolving GraphQL
schema is to:
• Always add fields, never change or delete
• Mark obsolete fields with @Deprecated and keep
supporting them
• monitor service usage, and remove only when usage of
old field is ~0%
As we started our journey, we added the REST-style version
prefix /v1 to our /graph, as an added “safety net” for
backward compat.
So far has not been used.
Caveats
• Cost of mistakes during domain modeling is relevant -
actually stays in the schema forever.
• Need for “graphql aware” logging and report (example:
Apollo Engine Optics)
PROMISES
The service

evolves smoothly and
indefinitely
Definitely Works
Schema as Communication tool
Having the schema as a pivotal artifact affects greatly
the team workflow.
The back-end team can spend less time documenting
and tailoring the services to serve the UX (BFF-style).
This frees us from waterfall-ish contraints, as the back-
end is built on business objects and not on querying
constraints.
This also assumes a thick-client approach, with App
developers expert in the problem domain.
PROMISES
Team Workflow skyrockets
UI
DESIGN
REST
ENDPTS
APP DEVCONCEPT
with REST
UI
DESIGN
SCHEMA
DEV
APP DEVCONCEPT
with GraphQL
Schema is a Tooling Platform
The apollo-ios and apollo-android libraries implement the
GraphQL standard and a series of convenience features:
• Model Code generation in Java / Swift
• Local Cache, which is a full fledged instance of
Repository +ORM
• Watcher query, custom Scalars and Datatypes
They a bit lagging in respect to server counterpart (i.e
binary support)
Definitely Works
Proper tooling saved many weeks of “monkey” coding,
Caveats
• The apollo native libraries are developed by a much looser
community (forget project governance structures).
• There is the possibility to roll-your-own component - but this
way you miss most of the value
• Code generated is not perfect (as always)
PROMISES
Development Time To Market
skyrockets
Whatabout

yournextapp?
GRAPHQL FOR NATIVE APPS
Do you need to expose a
heterogenous setof services and
data sources,
to clients of all sorts?
Are you serving mostly
textualand 

authenticateddata?
How about 

“transactional” services?
Do you hate HTTP?
Can you live 

without server-definedcaching, 

without networkcaching, 

without HTTPsemantics?
Are you developing a digital product in a
context where 

fast turnaroundis key, and being 

flexible and robustto accomodate
new features?
GRAPHQL FOR NATIVE APPS


BeyondGraphQL
The native app is the User eXperience touch-point of a
wide array of technologies:
MyAXA
Technologies
GRAPHQL FOR NATIVE APPS
➡ ChatBots, Telemedicine
➡ Video/Image Recognition
➡ Microservices (Kubernetes + AWS)
➡ IoT for Car and Home
https://group.axa.com/en/careers
Thank you!
https://www.frogdesign.com/careers

More Related Content

What's hot

2015-05-19-resume
2015-05-19-resume2015-05-19-resume
2015-05-19-resume
Lee Norris
 
External - IT Specialist
External - IT SpecialistExternal - IT Specialist
External - IT Specialist
Jacob Wardon
 

What's hot (20)

The 7 Deadly Sins of API Design
The 7 Deadly Sins of API DesignThe 7 Deadly Sins of API Design
The 7 Deadly Sins of API Design
 
Simplifying AI integration on Apache Spark
Simplifying AI integration on Apache SparkSimplifying AI integration on Apache Spark
Simplifying AI integration on Apache Spark
 
2015-05-19-resume
2015-05-19-resume2015-05-19-resume
2015-05-19-resume
 
Richard ward2016
Richard ward2016Richard ward2016
Richard ward2016
 
SamSegalResume
SamSegalResumeSamSegalResume
SamSegalResume
 
How Facebook's Technologies can define the future of VistA and Health IT
How Facebook's Technologies can define the future of VistA and Health ITHow Facebook's Technologies can define the future of VistA and Health IT
How Facebook's Technologies can define the future of VistA and Health IT
 
apidays LIVE Australia 2020 - Leveraging DevOps to visualize your digital eco...
apidays LIVE Australia 2020 - Leveraging DevOps to visualize your digital eco...apidays LIVE Australia 2020 - Leveraging DevOps to visualize your digital eco...
apidays LIVE Australia 2020 - Leveraging DevOps to visualize your digital eco...
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
 
REST API Doc Best Practices
REST API Doc Best PracticesREST API Doc Best Practices
REST API Doc Best Practices
 
GraphQL Introduction
GraphQL IntroductionGraphQL Introduction
GraphQL Introduction
 
Magdalena Stenius: MLOPS Will Change Machine Learning
Magdalena Stenius: MLOPS Will Change Machine LearningMagdalena Stenius: MLOPS Will Change Machine Learning
Magdalena Stenius: MLOPS Will Change Machine Learning
 
Seamless MLOps with Seldon and MLflow
Seamless MLOps with Seldon and MLflowSeamless MLOps with Seldon and MLflow
Seamless MLOps with Seldon and MLflow
 
apidays LIVE Australia 2020 - Productising your Microservices as API Products...
apidays LIVE Australia 2020 - Productising your Microservices as API Products...apidays LIVE Australia 2020 - Productising your Microservices as API Products...
apidays LIVE Australia 2020 - Productising your Microservices as API Products...
 
Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...
Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...
Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...
 
apidays LIVE Helsinki & North - 20 minutes to build a serverless COVID-19 RES...
apidays LIVE Helsinki & North - 20 minutes to build a serverless COVID-19 RES...apidays LIVE Helsinki & North - 20 minutes to build a serverless COVID-19 RES...
apidays LIVE Helsinki & North - 20 minutes to build a serverless COVID-19 RES...
 
API Description Languages
API Description LanguagesAPI Description Languages
API Description Languages
 
External - IT Specialist
External - IT SpecialistExternal - IT Specialist
External - IT Specialist
 
BigdataConference Europe - BigQuery ML
BigdataConference Europe - BigQuery MLBigdataConference Europe - BigQuery ML
BigdataConference Europe - BigQuery ML
 
DevOps for DataScience
DevOps for DataScienceDevOps for DataScience
DevOps for DataScience
 
MLOps - Build pipelines with Tensor Flow Extended & Kubeflow
MLOps - Build pipelines with Tensor Flow Extended & KubeflowMLOps - Build pipelines with Tensor Flow Extended & Kubeflow
MLOps - Build pipelines with Tensor Flow Extended & Kubeflow
 

Similar to GraphQL for Native Apps

The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL Stack
Sashko Stubailo
 

Similar to GraphQL for Native Apps (20)

Andrea Baldon, Emanuele Di Saverio - GraphQL for Native Apps: the MyAXA case ...
Andrea Baldon, Emanuele Di Saverio - GraphQL for Native Apps: the MyAXA case ...Andrea Baldon, Emanuele Di Saverio - GraphQL for Native Apps: the MyAXA case ...
Andrea Baldon, Emanuele Di Saverio - GraphQL for Native Apps: the MyAXA case ...
 
GraphQL research summary
GraphQL research summaryGraphQL research summary
GraphQL research summary
 
apidays LIVE Paris - GraphQL meshes by Jens Neuse
apidays LIVE Paris - GraphQL meshes by Jens Neuseapidays LIVE Paris - GraphQL meshes by Jens Neuse
apidays LIVE Paris - GraphQL meshes by Jens Neuse
 
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything togetherSashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
Sashko Stubailo - The GraphQL and Apollo Stack: connecting everything together
 
The Apollo and GraphQL Stack
The Apollo and GraphQL StackThe Apollo and GraphQL Stack
The Apollo and GraphQL Stack
 
Graphql
GraphqlGraphql
Graphql
 
codersera_com (1).pdf
codersera_com (1).pdfcodersera_com (1).pdf
codersera_com (1).pdf
 
James Baxley - Statically typing your GraphQL app
James Baxley - Statically typing your GraphQL appJames Baxley - Statically typing your GraphQL app
James Baxley - Statically typing your GraphQL app
 
API Description Languages: Which Is The Right One For Me?
 API Description Languages: Which Is The Right One For Me?  API Description Languages: Which Is The Right One For Me?
API Description Languages: Which Is The Right One For Me?
 
Service worker API
Service worker APIService worker API
Service worker API
 
GraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits togetherGraphQL across the stack: How everything fits together
GraphQL across the stack: How everything fits together
 
Nyc mule soft_meetup_13_march_2021
Nyc mule soft_meetup_13_march_2021Nyc mule soft_meetup_13_march_2021
Nyc mule soft_meetup_13_march_2021
 
React and GraphQL at Stripe
React and GraphQL at StripeReact and GraphQL at Stripe
React and GraphQL at Stripe
 
Create GraphQL server with apolloJS
Create GraphQL server with apolloJSCreate GraphQL server with apolloJS
Create GraphQL server with apolloJS
 
Top 5 backend frameworks for web development in.pptx
Top 5 backend frameworks for web development in.pptxTop 5 backend frameworks for web development in.pptx
Top 5 backend frameworks for web development in.pptx
 
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and DataflowHow to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
How to build unified Batch & Streaming Pipelines with Apache Beam and Dataflow
 
Introduction to GCP Data Flow Presentation
Introduction to GCP Data Flow PresentationIntroduction to GCP Data Flow Presentation
Introduction to GCP Data Flow Presentation
 
Introduction to GCP DataFlow Presentation
Introduction to GCP DataFlow PresentationIntroduction to GCP DataFlow Presentation
Introduction to GCP DataFlow Presentation
 
Full Stack Web Development: Vision, Challenges and Future Scope
Full Stack Web Development: Vision, Challenges and Future ScopeFull Stack Web Development: Vision, Challenges and Future Scope
Full Stack Web Development: Vision, Challenges and Future Scope
 
Krishnagopal Thogiti_Java
Krishnagopal Thogiti_JavaKrishnagopal Thogiti_Java
Krishnagopal Thogiti_Java
 

Recently uploaded

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 

Recently uploaded (20)

From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 

GraphQL for Native Apps

  • 1. CASE STUDY GraphQL for Native Apps 
 The MyAXA App MARCH 22ND, 2019
  • 2. We will discuss thebest practices, 
 architecture patterns and lessons learned in adopting the GraphQLAPI query language in the context of 
 theMyAXAnative app. INTRO
  • 3. Principal Software Architect @ frog Emanuele Di Saverio CS Engineering graduate ’06 from Rome, started writing embedded software when Symbian S40 was a thing. Software Architect for Mobile and Web, specialising in UX - in the frog pond since 2011. Former Agile enthusiast, now just agile, wrote a book about Android. INTRO Software Architect Team Lead iOS @ AXA Italy Andrea Baldon Software engineer and architect with many years spent on coding mobile apps, deploy backend and frontend sites plus a bunch of things on IOT and voice control apps. Actually working on Disruption technology for AXA Insurance company. @hazam /emanueledisaverio @ultranano /baldonandrea
  • 7. <SECTION> It’s a completely new way
 to explore insurance!
 MyAXA is the official app available on iOS and Android dedicated to customers who have signed insurance policies with the AXA Italy Group. WHAT'S MYAXA
  • 9. A (very) Conceptual Architecture SOLUTION OVERVIEW AXA Core IT An App is never just an App The MyAXA app needs to be joined by a dedicated middleware layer, cloud-native and flexible enough to serve mobile-optimized content. <SOAP/> MessageQueues ETLs Batch REST Proxies
  • 10. A (very) Conceptual Architecture SOLUTION OVERVIEW AXA Core IT An App is never just an App Middleware The MyAXA app needs to be joined by a dedicated middleware layer, cloud-native and flexible enough to serve mobile-optimized content. ETLs Batch Proxies <SOAP/> MessageQueues REST (Anti-corruption layer, Facade)
  • 11. Taking the fast track GraphQL soundness and schema-centricity enables complex tooling to be developed, resulting in • tremendous speedup of FE development • DRY and modular BE development This is what we were looking for, and we found it. An “agile” tool The most surprising outcome that we didn’t expect was the flexibility of the tool, and how it affects the team dynamics, communication and workflow. The discoverability, flexibility and tooling had direct impact over team members interactions and communications. SOLUTION OVERVIEW <tl;dr>
 GraphQL is custom API Gateway for all clients, with one codebase.
  • 14. Open from the start Facebook took care in open-sourcing the whole spec in 2015, of this new tech they were using internally, including Relay, they client side library. There are many implementations of the spec, for every language. If you really want to, you would build one yourself. INTRO TO GRAPHQL GraphQL is a Specification https://facebook.github.io/graphql Relevant Players The companies really fueling the GraphQL community are Meteor, Facebook, GraphCool, Gatsby. Case studies grow every day! We’re going to reference the apollo ecosystem as one of the most widespread and well documented. https://www.apollographql.com/
  • 15. INTRO TO GRAPHQL The Schema Types and Operations GraphQL implementation revolves around the full specification of • the data types involved • the queries • the data manipulations (Mutations) Everything is strongly typed - allowing you be loose everywhere else.
  • 16. Remote Procedure Call e.g. gRPC, SOAP, Thrift, Corba INTRO TO GRAPHQL GraphQL implements an
 API paradigm Resource-Based Query Language e.g. REST + HATEOAS, FTP, ODATA e.g. Cipher, SparQL, LINQ, SQL, GraphQL We scratch our heads to decompose data to serve UX FE developers scavenge the right data P. Sturgeon - https://philsturgeon.uk/2018/05/21/picking-an-api-paradigm-implementation/ We try decouple tangled systems
  • 19. INTRO TO GRAPHQL GraphQL is designed to work as an Evolving Gateway towards multiple clients
  • 21. GRAPHQL FOR NATIVE APPS Promises Kept&Broken
  • 22. The curse of the multi-model While at the business level, the model is one, at the technical level you usually have 3 (or more) implementations on your app: • the on-the wire one, between client and server • the persisted one, to save data on SQLite for example • the runtime one, used to manipulate data in app And you have to manage them all! PROMISES One Schema to Rule them All JSON
 Model Model.swift SQL Schema
  • 23. GraphQL SchemaGraphQL Schema The GraphQL schema is flexible, opt-in, standard and strongly typed. • flexible it has been designed with change in mind as key feature, so you don’t risk to be locked in • opt-in clients needs to explicitly write query and ask for a given field on some type - no way to * ! • strongly typed and standardization allow for powerful tooling to automate the 3 models PROMISES One Schema to Rule them All JSON
 Model Model.swift SQL Schema Caveats • GraphQL schema dictates how you write your code, it’s not just data spec • May not translate in a smooth way to all languages - optionals and fragments
  • 24. We group here considerations regarding how well the GraphQL technology and his related implementation libraries Apollo works with the target technology. As a powerful abstraction, we expected some impedance mismatch when analyzing the details and low level implementation. And we found some. PROMISES Mechanical Sympathy
  • 25. Minimize Payloads Query language allows the client to be in control of the payload, so it can, at any time request only the minimum amount of data needed on a given Fragment / ViewController. No more overfetching! PROMISES Mechanical Sympathy:
 Network Efficiency 
 just what you need
  • 26. PROMISES The Big Cookie R. Meier - Google I/O 2012 - Making Good Apps Great Mobile is Different When working over 3G or 4G connections, the Round Trip Time dominates over bandwidth. GZIP works better with long payloads, and radio has “warmup cycles” to exploit. It’s much better to have “big data sync” requests. Network queries tend to be more like “get all the data” Mechanical Sympathy:
 Network Efficiency 
 just what you need
  • 27. Protocol Agnostic GraphQL is not designed with a specific transport protocol, but most of the implementations rely on HTTP. All queries are exposed through a single endpoint (typically /graph) and through POST with the query content in the body. The whole set of HTTP semantic is bypassed. Caching is a casualty GraphQL requests are opaque - so they can;’t be cached by any proxy along the connection. This means that client apps have to use a client side cache. PROMISES Mechanical Sympathy: 
 HTTP Caching
  • 28. PROMISES Mechanical Sympathy: 
 HTTP Caching A Step Behind in Internet - friendliness 1990s CORBA Treat remote objects as if they were local 2000s SOAP Standardize Remote Method Innovation 2010s REST Going back to true WWW sematics 2015 GraphQL …we actually don’t care about HTTP.
  • 29. Another Casualty For similar reasons, the HTTP Status-Code based information is not available - all application-level errors are 200s, and details are always in the payload. The actual format is rich and articulated, including support for partial errors (i.e. errors on only some branch of the query tree), but overall, doesn’t play well with what used to be key tenets of HTTP - let alone other libraries and infrastructure. PROMISES Mechanical Sympathy: 
 Error Handling
  • 30. More than just queries PROMISES You can use GraphQL for 
 all kinds of services The standard includes support for Mutations: specific requests that can CRUD data. Most of the tooling also support Subscriptions: pub/sub for data changes (i.e. over WebSockets). Now we can use it for everything, right?
  • 31. More than just queries A Query Language is for Querying While we could implement everything, there is no advantage in implementing “business-rocess” style services over GraphQL. Examples: • Logins, Registrations • Payments, Enrollments • Wizards Moreover, support for binary payloads (file down/upload, streaming) not supported *. PROMISES You can use GraphQL for 
 all kinds of services The standard includes support for Mutations: specific requests that can CRUD data. Most of the tooling also support Subscriptions: pub/sub for data changes (i.e. over WebSockets). Now we can use it for everything, right?
  • 32. PROMISES The service 
 evolves smoothly and indefinitely
  • 33. Grow your Schema The strategy that is suggested for evolving GraphQL schema is to: • Always add fields, never change or delete • Mark obsolete fields with @Deprecated and keep supporting them • monitor service usage, and remove only when usage of old field is ~0% As we started our journey, we added the REST-style version prefix /v1 to our /graph, as an added “safety net” for backward compat. So far has not been used. Caveats • Cost of mistakes during domain modeling is relevant - actually stays in the schema forever. • Need for “graphql aware” logging and report (example: Apollo Engine Optics) PROMISES The service
 evolves smoothly and indefinitely Definitely Works
  • 34. Schema as Communication tool Having the schema as a pivotal artifact affects greatly the team workflow. The back-end team can spend less time documenting and tailoring the services to serve the UX (BFF-style). This frees us from waterfall-ish contraints, as the back- end is built on business objects and not on querying constraints. This also assumes a thick-client approach, with App developers expert in the problem domain. PROMISES Team Workflow skyrockets UI DESIGN REST ENDPTS APP DEVCONCEPT with REST UI DESIGN SCHEMA DEV APP DEVCONCEPT with GraphQL
  • 35. Schema is a Tooling Platform The apollo-ios and apollo-android libraries implement the GraphQL standard and a series of convenience features: • Model Code generation in Java / Swift • Local Cache, which is a full fledged instance of Repository +ORM • Watcher query, custom Scalars and Datatypes They a bit lagging in respect to server counterpart (i.e binary support) Definitely Works Proper tooling saved many weeks of “monkey” coding, Caveats • The apollo native libraries are developed by a much looser community (forget project governance structures). • There is the possibility to roll-your-own component - but this way you miss most of the value • Code generated is not perfect (as always) PROMISES Development Time To Market skyrockets
  • 37. Do you need to expose a heterogenous setof services and data sources, to clients of all sorts?
  • 38. Are you serving mostly textualand 
 authenticateddata? How about 
 “transactional” services?
  • 39. Do you hate HTTP?
  • 40. Can you live 
 without server-definedcaching, 
 without networkcaching, 
 without HTTPsemantics?
  • 41. Are you developing a digital product in a context where 
 fast turnaroundis key, and being 
 flexible and robustto accomodate new features?
  • 42.
  • 43. GRAPHQL FOR NATIVE APPS 
 BeyondGraphQL
  • 44. The native app is the User eXperience touch-point of a wide array of technologies: MyAXA Technologies GRAPHQL FOR NATIVE APPS ➡ ChatBots, Telemedicine ➡ Video/Image Recognition ➡ Microservices (Kubernetes + AWS) ➡ IoT for Car and Home