Slide 1

Slide 1 text

Modular Monolith Go Server with GraphQL Federation + gRPC @yuki.ito

Slide 2

Slide 2 text

newmo Architect Yuki Ito @mrno110

Slide 3

Slide 3 text

We are Hiring!!!

Slide 4

Slide 4 text

Agenda ✅ API Architecture ✅ Go Modular Monolith (+ Monorepo)

Slide 5

Slide 5 text

GraphQL + gRPC

Slide 6

Slide 6 text

GraphQL + gRPC

Slide 7

Slide 7 text

Why GraphQL? ✅ Ecosystem ✅ Federation ✅ Declarative

Slide 8

Slide 8 text

Why GraphQL? ✅ Ecosystem ✅ Federation ✅ Declarative

Slide 9

Slide 9 text

Evolution of API Architecture (by Netflix) https://netflixtechblog.com/how-netflix-scales-its-api-with-graphql-federation-part-1-ae3557c187e2

Slide 10

Slide 10 text

Evolution of API Architecture (by Netflix) https://netflixtechblog.com/how-netflix-scales-its-api-with-graphql-federation-part-1-ae3557c187e2

Slide 11

Slide 11 text

Evolution of API Architecture (by Netflix) https://netflixtechblog.com/how-netflix-scales-its-api-with-graphql-federation-part-1-ae3557c187e2

Slide 12

Slide 12 text

Evolution of API Architecture (by Netflix) https://netflixtechblog.com/how-netflix-scales-its-api-with-graphql-federation-part-1-ae3557c187e2

Slide 13

Slide 13 text

GraphQL - Direct Access

Slide 14

Slide 14 text

GraphQL - Direct Access type Driver { id: ID! name: String! } type Vehicle { id: ID! driverId: String! }

Slide 15

Slide 15 text

GraphQL - Direct Access ❌ Round Trips ❌ Aggregation Logics reside Web/Mobile side

Slide 16

Slide 16 text

GraphQL - Aggregation

Slide 17

Slide 17 text

GraphQL - Aggregation type Driver { id: ID! name: String! vehicles: [Vehicle!]! }

Slide 18

Slide 18 text

GraphQL - Aggregation ❌ Initiative ❌ Independence ❌ Autonomy

Slide 19

Slide 19 text

GraphQL - Federation

Slide 20

Slide 20 text

GraphQL - Federation type Driver @key(fields: "id") { id: ID! name: String! } type Driver @key(fields: "id") { id: ID! vehicles: [Vehicle!]! } type Vehicle { id: ID! } type Driver { id: ID! name: String! vehicles: [Vehicle!]! } +

Slide 21

Slide 21 text

GraphQL - Federation API Gateway Vehicle GraphQL GraphQL Federation (Apollo Router) Driver GraphQL Platform Business

Slide 22

Slide 22 text

gqlgen https://gqlgen.com/

Slide 23

Slide 23 text

gqlgen type Driver @key(fields: "id") { id: ID! name: String! } type QueryResolver interface { Driver(ctx context.Context) (*Driver, error) } type EntityResolver interface { FindDriverByID(ctx context.Context, id string) (*Driver, error) }

Slide 24

Slide 24 text

Go Components

Slide 25

Slide 25 text

Go Components

Slide 26

Slide 26 text

Modular Monolith ... splitting applications into independently deployable microservices is not without its challenges, some of which directly contradict the benefits. Towards Modern Development of Cloud Applications Google (ServiceWeaver) https://dl.acm.org/doi/10.1145/3593856.3595909 ... Write monolithic applications that are modularized into logically distinct components.

Slide 27

Slide 27 text

Go Modular Monolith Application Component Component Component

Slide 28

Slide 28 text

Modular Monolith - Application func main() { app.Run(application) } func application(ctx context.Context, a *app.Application) error { a.AddComponent("driver", driver.Component) a.AddComponent("vehicle", passenger.Component) return a.Run(ctx) }

Slide 29

Slide 29 text

Modular Monolith - Component func Component(ctx context.Context, c *app.Component) error { env := new(environments) err := c.LoadEnvironments(env) db, err := c.GetDatabase(ctx) // ... c.AddGraphQLHandler(/*...*/) c.AddGRPCService(/*...*/) return c.Run(ctx) }

Slide 30

Slide 30 text

Go Modular Monolith Application Component Component Component HTTP (GraphQL) Server gRPC Server

Slide 31

Slide 31 text

Architecture

Slide 32

Slide 32 text

We are Hiring!!!