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

KAUCHE Loves Go

Yuki Ito
October 26, 2022

KAUCHE Loves Go

Yuki Ito

October 26, 2022
Tweet

More Decks by Yuki Ito

Other Decks in Programming

Transcript

  1. KAUCHE ❤ Go
    Yuki Ito (@mrno110)
    KAUCHE Tech Talk #3

    View Slide

  2. KAUCHE


    Platform Team: Architect
    Yuki Ito


    @mrno110

    View Slide

  3. https://gihyo.jp/book/2022/978-4-297-12519-6

    View Slide

  4. View Slide

  5. Agenda
    • Why Go?


    • Go at KAUCHE


    • Code Generation


    • Clean Architecture


    • From Modular Monolith


    To Microservice

    View Slide

  6. Agenda
    • Why Go?


    • Go at KAUCHE


    • Code Generation


    • Clean Architecture


    • From Modular Monolith


    To Microservice

    View Slide

  7. Why Go?
    • Simplicity


    • Ecosystem


    • e.g. gRPC, google-cloud-go etc...


    • Used by Many Cloud Native Softwares


    • e.g. Kubernetes, Istio etc...


    • Goroutines & Channel

    View Slide

  8. Agenda
    • Why Go?


    • Go at KAUCHE


    • Code Generation


    • Clean Architecture


    • From Modular Monolith


    To Microservice

    View Slide

  9. Architecture
    Run
    Tasks
    Pub/Sub
    Mobile App External Service
    Mobile API Web Hook API Job API
    Scheduler

    View Slide

  10. https://cloud.withgoogle.com/next/speakers?session=HIVE101-JP

    View Slide

  11. Code Generation - gRPC
    gRPC is a modern open source
    high performance Remote
    Procedure Call (RPC)
    framework that can run in
    any environment.
    https://grpc.io/

    View Slide

  12. Code Generation - gRPC
    rpc GetProduct(GetProductRequest) returns (GetProductResponse) {


    option (google.api.http) = {


    get: "/..."


    };


    }
    type CustomerServiceServer interface {


    GetProduct(context.Context, *GetProductRequest) (*GetProductResponse, error)


    // ...


    }
    Generate (protoc)
    Protocol Bu
    ff
    ers
    Go

    View Slide

  13. Code Generation - GraphQL
    GraphQL is a query language
    for APIs and a runtime for
    ful
    fi
    lling those queries with
    your existing data.
    https://graphql.org/

    View Slide

  14. Code Generation - GraphQL
    GraphQL Schema
    Generate (gqlgen)
    type QueryResolver interface {


    Products(ctx context.Context) ([]*Product, error)


    // ...


    }
    Go

    View Slide

  15. Code Generation - GraphQL
    https://github.com/99designs/gqlgen

    View Slide

  16. Code Generation - Database
    Fully managed relational
    database with unlimited
    scale, strong consistency, and
    up to 99.999% availability.
    https://cloud.google.com/spanner

    View Slide

  17. Code Generation - Database
    CREATE TABLE Products (
    ProductId STRING(36) NOT NULL,
    -- ...
    ) PRIMARY KEY(ProductId);
    Database Schema
    Generate (yo)
    func FindProduct(ctx context.Context, db YORODB, productID string) (*Product, error) {
    // ...
    }
    Go

    View Slide

  18. Code Generation - Database
    cloudspannerecosystem / yo
    https://github.com/cloudspannerecosystem/yo

    View Slide

  19. Agenda
    • Why Go?


    • Go at KAUCHE


    • Code Generation


    • Clean Architecture


    • From Modular Monolith


    To Microservice

    View Slide

  20. Clean Architecture
    https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html

    View Slide

  21. Clean Architecture
    • Entities


    • Business Objects


    • Use Cases


    • Application Business Rules


    • Drivers


    • gRPC


    • Cloud Spanner


    • Identity Platform


    • Event System


    • ...

    View Slide

  22. Agenda
    • Why Go?


    • Go at KAUCHE


    • Code Generation


    • Clean Architecture


    • From Modular Monolith


    To Microservice

    View Slide

  23. Architecture: 2020 ~
    Run
    Customer App
    Customer gRPC

    View Slide

  24. Architecture: 2021 ~
    Run
    Customer App
    Customer gRPC / Partner gRPC
    Partner App

    View Slide

  25. Modular Monolith
    Almost all the cases where I've heard of a system that was built
    as a microservice system from scratch, it has ended up in serious
    trouble. ...


    you shouldn't start a new project with microservices, even if
    you're sure your application will be big enough to make it
    worthwhile.
    MonolithFirst
    Martin Fowler
    https://martinfowler.com/bliki/MonolithFirst.html

    View Slide

  26. Modular Monolith
    ✅ Pros


    - Single Deployment Unit


    - Simple Design


    ❌ Cons


    - Independence


    - Autonomy

    View Slide

  27. Architecture: 2022 ~
    Customer App
    Customer gRPC
    Partner App
    Partner gRPC
    API Gateway

    View Slide

  28. Architecture: 2022 ~
    Commerce gRPC
    API Gateway
    Social GraphQL
    Customer GraphQL Federation (Apollo Router)
    Commerce GraphQL
    Social gRPC
    Platfrom
    Business

    View Slide

  29. Agenda
    • Why Go?


    • Go at KAUCHE


    • Code Generation


    • Clean Architecture


    • From Modular Monolith


    To Microservice

    View Slide