Slide 1

Slide 1 text

shahidh_k AWS Community Day Bangalore Architecture of scalable and resilient apps with GraphQL, Amazon RDS and AWS Lambda 1

Slide 2

Slide 2 text

shahidh_k 2 I’m Shahidh

Slide 3

Slide 3 text

shahidh_k The Problem 3

Slide 4

Slide 4 text

shahidh_k Traditional architecture App Database API Payment microservice Restaurant microservice Delivery microservice 4 1. Scalable? 2. Resilient?

Slide 5

Slide 5 text

shahidh_k Moving towards scale & resilience 5

Slide 6

Slide 6 text

shahidh_k Async architecture App Database API Event system Payment processing Restaurant approval Delivery assignment Async microservices 6

Slide 7

Slide 7 text

shahidh_k Serverless 7

Slide 8

Slide 8 text

shahidh_k Serverless  $ cat index.js exports.function = (req, res) => { res.json({"message": "Hello World"}); } 8 $ serverless functions deploy hello_world --trigger-http https://serverless.functions.net/hello_world $ curl https://serverless.functions.net/hello_world {"message": "Hello World"}

Slide 9

Slide 9 text

shahidh_k Scalable! ● No OPS ● No VMs to manage ● Don’t need to worry about scaling ● Just write the code ● Deploy ● Scale for “free” Graphic Source 9

Slide 10

Slide 10 text

shahidh_k Resilient? ● Serverless functions are ephemeral ● No knowledge of state - async ● Trigger them on events ● Add retries to the mix ● We have resiliency 10

Slide 11

Slide 11 text

shahidh_k Example: Food ordering app Column | Value -------------------+--------------------------------------- id | a705a43d-c55b-4a8a-ac16-80679bd02404 created_at | 2018-09-23 13:24:32.159024+00 user_id | eca786b6-73ae-44c7-b34f-1757af554464 is_validated | false is_paid | false is_approved | false is_agent_assigned | false 11

Slide 12

Slide 12 text

shahidh_k Order state machine with serverless is_validated | false is_paid | false is_approved | false is_agent_assigned | false is_validated | true is_paid | false is_approved | false is_agent_assigned | false is_validated | true is_paid | true is_approved | false is_agent_assigned | false is_validated | true is_paid | true is_approved | true is_agent_assigned | false is_validated | true is_paid | true is_approved | true is_agent_assigned | true Checks payment New order Validate order Restaurant approval Agent assignment Completed 12

Slide 13

Slide 13 text

shahidh_k Architecture Recap ● Microservices became serverless functions ● Serverless functions are scalable by nature ● Database events trigger async serverless functions ● Resiliency by event source tool instead of in the API code ● Moved specific failure handling logic to generic failure handling 13

Slide 14

Slide 14 text

shahidh_k The cost 14 App Database API Event system Payment processing Restaurant approval Delivery assignment Generic Event System Event system Async Serverless Fns Payment processing Restaurant approval Delivery assignment

Slide 15

Slide 15 text

shahidh_k High level overview Database Event system Payment processing Restaurant approval Delivery assignment Async serverless functions A Database API layer Payment microservice Restaurant microservice Delivery microservice Synchronous logic Asynchronous logic 15

Slide 16

Slide 16 text

shahidh_k However, there’s still one problem

Slide 17

Slide 17 text

shahidh_k GraphQL 17

Slide 18

Slide 18 text

shahidh_k REST vs GraphQL Product Brand Category GET PUT POST PATCH DELETE GET PUT POST PATCH DELETE GET PUT POST PATCH DELETE ProductWithBrand 18

Slide 19

Slide 19 text

shahidh_k GraphQL changes the way we think about UI + API ● UI First modelling ● Makes API usage more natural ● Maps UI components to GraphQL queries ● Faster iterations - no back and forth b/n frontend-backend 19

Slide 20

Slide 20 text

shahidh_k GraphQL Subscriptions Consume async info from the backend without any worries It’s as if REST had a WATCH verb Datastore App 20

Slide 21

Slide 21 text

shahidh_k Let’s say I want to build... 21

Slide 22

Slide 22 text

shahidh_k Without GraphQL ● Polling from the client ● Websockets - custom API ● Community fragmentation ● Various patterns in different frameworks ● More work for the developer 22

Slide 23

Slide 23 text

shahidh_k With GraphQL ● Standardised spec ● All GraphQL Clients are compatible with all GraphQL Servers ● Client implementations available for all major platforms and frameworks ● Subscriptions: access to async info ● Less work for the developer 23

Slide 24

Slide 24 text

shahidh_k GraphQL Subscriptions App Datastore Process payment Validate order Agent assignme nt Restauran t approval New Order Complete 24

Slide 25

Slide 25 text

shahidh_k However, the cost is... 25 App Database API Event system Payment processing Restaurant approval Delivery assignment Generic Event System Event system Async Serverless Fns Payment processing Restaurant approval Delivery assignment GraphQL Server Subscriptions

Slide 26

Slide 26 text

shahidh_k Traditional vs GraphQL + Serverless Architecture 26

Slide 27

Slide 27 text

shahidh_k Traditional architecture App Database API layer Payment microservice Restaurant microservice Delivery microservice 27

Slide 28

Slide 28 text

shahidh_k Moving towards scale & resilience App Database API Event system Payment processing Restaurant approval Delivery assignment Async microservices 28

Slide 29

Slide 29 text

shahidh_k GraphQL & Serverless architecture 29 App Database Payment processing Restaurant approval Delivery assignment Mutation/Subscriptions Async serverless functions

Slide 30

Slide 30 text

shahidh_k Demo Time! 30

Slide 31

Slide 31 text

shahidh_k Food ordering app 31 https://serverless-demo-aws.hasura.app/order-app

Slide 32

Slide 32 text

shahidh_k Food ordering app - scalable 32 https://serverless-demo-aws.hasura.app/analytics-app

Slide 33

Slide 33 text

shahidh_k Food ordering app - resilient 33 https://serverless-demo-aws.hasura.app/console

Slide 34

Slide 34 text

shahidh_k 34 Thanks Questions?