Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Modular Monolith Go Server with GraphQL Federat...

Yuki Ito
August 27, 2024

Modular Monolith Go Server with GraphQL Federation + gRPC

Yuki Ito

August 27, 2024
Tweet

More Decks by Yuki Ito

Other Decks in Programming

Transcript

  1. GraphQL - Direct Access type Driver { id: ID! name:

    String! } type Vehicle { id: ID! driverId: String! }
  2. 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!]! } +
  3. 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) }
  4. 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.
  5. 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) }
  6. 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) }