designing future apis for modern - developermarch€¦ · what is graphql? • graphql is a query...

1

Upload: others

Post on 23-May-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries
Page 2: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries
Page 3: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

Designing Future APIs for Modern Microservices World

April 23, 2019

Page 4: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

A Tale of Apollo, GraphQL, React & Spring boot

3

Page 5: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

AGENDA

4

• What is GraphQL ? • How does it compare with REST? What? • Efficiency • Type Safety • Tooling Why? • How GraphQL is used in Microservices?

• API Gateway • Event Based System • Serverless GraphQL

How?

Page 6: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

What is GraphQL?

• GraphQL is a query language for API’s • It provides server side runtime to execute type queries • Uses existing codebase used for REST • Request (GraphQL document) -> JSON Response

GraphQL was developed internally by Facebook in 2012 before being publicly released in 2015

5

Page 7: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

6

Client GQL Server

Data Access Layer

Business Layer Data Source

GraphQL Document

JSON Response

GraphQL Server exposes “one API to rule them all”

Page 8: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

Demo

7

Page 9: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

What is GraphQL ?

8

Query Language for API’s

Query Executor on Schema

For Frontend Developers

For Backend Developers

Page 10: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

GraphQL Vs REST

9

Page 11: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

GraphQL vs REST

10

REST GraphQL Why

Shared Definition No Yes Schema Specification in GraphQL

Conceptual Model Resources

Graphs Objects and Fields are presented in form of Graphs

Type Safety Weak Strong Strongly typed inputs and outputs

Introspection No Yes Introspect schema while writing query

Real Time No Yes Subscription provide real time data

Page 12: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

Challenges with Modern API’s

• EFFICIENCY

• PREDICTABILITY

• VERSIONING

• SECURITY

• DOCUMENTATION

• TOOLING

• CACHING

• .. MANY MORE

11

Page 13: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

Why GraphQL?

12

• EFFICIENCY

• Avoid overfetching and underfetching

• Clients to declare all the data they need in a single network request

• Reduces the need of client side joins, error handling and retry logic

• TYPE SAFETY

• Predictability

• TOOLING & DOCUMENTATION

• GraphiQL provides documentation via introspection query

• IDE integrates via GraphQL language service

Page 14: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

GraphQL in Microservices

API Gateway

13

Page 15: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

GraphQL in Microservices

Microservices

14

• Core Idea – Iterate on your part without blocking others

• Write different backbend's and features in different technologies

• Own your own data and enable more vertically integrated teams • Independently version the backend's to avoid monolithic release

process

Page 16: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

API Gateway

15

Messaging

Account Management Session

Web App Native App Other Service

REST REST REST

API Gateway

One centralized schema containing all REST details of underlying microservices

Page 17: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

API Gateway

16 Messaging

Account Management Session

Web App Native App Other Service

REST REST REST

API Gateway

One parent schema for all the underlying schema

Page 18: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

Schema Stitching

Schema stitching is the process of creating a single GraphQL schema from multiple underlying GraphQL APIs.

17

Page 19: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

GraphQL in Microservices

Schema stitching is the process of creating a single GraphQL schema from multiple underlying GraphQL APIs.

18

Page 20: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

GraphQL in Microservices (Event Driven)

Event System

Account Management Session

Login Messages Create

Messaging Alarm

Login

Subscriptions in GraphQL are being used to create event driven system architecture

Page 21: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

What makes Serverless and GraphQL a great fit?

20

Page 22: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

Serverless GraphQL

I have this code which I want to run

Just make it run and scale

1. No server management

2. Pay-per-execution (never pay for idle)

3. Auto-scale (scale based on demand)

4. Function as a unit of application logic

What is Serverless?

21

Page 23: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

22

Resources

• How To GraphQL - https://www.howtographql.com/

• Server – Server communication - https://medium.com/open-graphql/graphql-bindings-for-service-to-

service-communication-d1e89df66ecd

• Schema Stitching - https://blog.hasura.io/the-ultimate-guide-to-schema-stitching-in-graphql-

f30178ac0072/

• Serverless GraphQL

• https://acloud.guru/learn/serverless-with-graphql

• https://blog.pusher.com/graphql-api-serverless/

Page 24: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

Q&A

23

Page 25: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries
Page 26: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries

thank you

copyright publicis sapient | confidential

Page 27: Designing Future APIs for Modern - DeveloperMarch€¦ · What is GraphQL? • GraphQL is a query language for API’s • It provides server side runtime to execute . type. queries