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

Building API Server-side Architecture for beginners

Building API Server-side Architecture for beginners

It is the material presented in GopherCon 2019 Lightning Talk
 

Kazuki Higashiguchi
PRO

July 24, 2019
Tweet

More Decks by Kazuki Higashiguchi

Other Decks in Programming

Transcript

  1. © - BASE, Inc.
    Building API server-side
    architecture for Beginners
    GopherCon
    . . - @hgsgtk

    View Slide

  2. © - BASE, Inc.
    Talk abstract
    • A practical approach to build server-side
    architecture in a Go project
    • Especially for teams who do not have Go
    experience in business

    View Slide

  3. © - BASE, Inc.
    Kazuki Higashiguchi / Backend engineer in Japan!
    About me
    @hgsgtk
    BASE BANK, Inc. / Dev Division / Tech lead

    View Slide

  4. © - BASE, Inc.
    Problem of building architecture for beginners
    Approach to build architecture
    Summary
    Talk structure

    View Slide

  5. © - BASE, Inc.
    Problem of building architecture
    for beginners
    Approach to build architecture
    Summary
    Talk structure

    View Slide

  6. © - BASE, Inc.
    Why I need server-side architecture
    .Keep a design easy to change
    • -> Separate external input/output and
    business logic
    .Reach common understanding of
    implementation policies in a team
    • -> To make readable and maintainable code

    View Slide

  7. © - BASE, Inc.
    • No absolute answer for any projects
    • We should determine a suitable architecture
    for the project
    Reality of building architecture

    View Slide

  8. © - BASE, Inc.
    • We should consider various things
    • Service requirements
    • Team member ability
    • Service scale
    • etc
    To determine a suitable architecture

    View Slide

  9. © - BASE, Inc.
    Problem of building architecture for beginners
    • We should consider various things
    • Service requirements
    • Team member ability
    • Service scale
    • etc
    For beginners, “Team member ability” is
    a factor that can not be ignored

    View Slide

  10. © - BASE, Inc.
    Go beginners have a lot of questions
    How to implement API server
    by net/http package
    How to write an unit test
    How to use interface type
    - Go basic questions -

    View Slide

  11. © - BASE, Inc.
    If we determine complicated architecture from the beginning
    How to implement API server
    by net/http package
    How to write an unit test
    - Go basic questions -
    ex. “Adopt clean architecture!”
    How to use interface type

    View Slide

  12. © - BASE, Inc.
    How to implement API server
    by net/http package
    How to write an unit test
    - Go basic questions -
    ex. “Adopt clean architecture!”
    - Architecture questions -
    What’s clean architecture?
    How to apply Dependency
    Inversion Principle in Go?
    What should we write in use
    case layer?
    How to use interface type
    If we determine complicated architecture from the beginning

    View Slide

  13. © - BASE, Inc.
    How to implement API server
    by net/http package
    How to write an unit testing
    - Go basic questions -
    ex. “Adopt clean architecture!”
    - Architecture questions -
    What’s clean architecture?
    How to apply Dependency
    Inversion Principle in Go?
    What should we write in use
    case layer?
    How to use interface type
    If we determine complicated architecture from beginning
    There are many questions
    in team members’ mind

    View Slide

  14. © - BASE, Inc.
    If we determine complicated architecture from beginning
    How to implement API server
    by net/http package
    How to write unit testing
    How to use interface type
    - Go Basic Questions -
    ex. “Adopt Clean Architecture!”
    - Architecture Questions -
    What’s clean architecture?
    How to apply Dependency
    Inversion Principle in Go?
    What we should write in use
    case layer?
    When it gets worst,
    Confusing

    View Slide

  15. © - BASE, Inc.
    Why I need server-side architecture
    .Keep a design easy to change
    • -> Separate external input/output and
    business logic
    .Common understanding of implementation
    policies in a team
    • -> To make readable and maintainable code
    We are not able to achieve
    “common understanding”

    View Slide

  16. © - BASE, Inc.
    Problem of building architecture for beginners
    Approach to build architecture
    Summary
    Talk structure

    View Slide

  17. © - BASE, Inc.
    Approach to build architecture
    Architectural
    complexity
    Go Skills/Knowledge

    View Slide

  18. © - BASE, Inc.
    Approach to build architecture
    Architectural
    complexity
    the final
    architecture
    . Define “the final architecture”
    that seems to be good for the project
    Go Skills/Knowledge

    View Slide

  19. © - BASE, Inc.
    Approach to build architecture
    Architectural
    complexity
    the final architecture
    . Set intermediate goals to
    “the final architecture”
    Go Skills/Knowledge

    View Slide

  20. © - BASE, Inc.
    Example of my team
    • The team have few Go experience in
    business
    • The Team has backend engineers
    • usually use PHP in work

    View Slide

  21. © - BASE, Inc.
    Example of my team
    Architectural
    complexity
    Layered
    Architecture + DIP
    Simple Model-Controller
    Model-Controller + DIP
    .
    .
    Go Skills/Knowledge

    View Slide

  22. © - BASE, Inc.
    Architectural
    complexity
    Layered
    Architecture + DIP
    Simple Model-Controller
    Model-Controller + DIP
    .
    .
    Go Skills/Knowledge
    . Define Layered Architecture + DIP
    as “the final architecture”
    Example of my team

    View Slide

  23. © - BASE, Inc.
    Layered Architecture + DIP
    • Refer to Layered Architecture
    • Apply DIP (Dependency Inversion
    Principle) to isolate domain logic
    from infrastructure
    implementations(ex. database
    handling)

    View Slide

  24. © - BASE, Inc.
    Architectural
    complexity
    Layered
    Architecture + DIP
    Simple Model-Controller
    Model-Controller + DIP
    .
    .
    Go Skills/Knowledge
    . Set intermediate goals
    Example of my team

    View Slide

  25. © - BASE, Inc.
    st goal: Simple Model-Controller
    • Simple design only with
    controller and model
    • Model includes implementations
    such as handling a database
    • To get used to Go API
    development

    View Slide

  26. © - BASE, Inc.
    At st goal, team will acquire
    How to implement API server
    by net/http package
    How to write an unit test
    How to use interface type
    - Go Basic Questions -
    Got it!

    View Slide

  27. © - BASE, Inc.
    At st goal, team will acquire
    How to implement API server
    by net/http package
    How to write an unit test
    How to use interface type
    - Go Basic Questions -
    Got it!
    Acquire Go Basic from simple design code

    View Slide

  28. © - BASE, Inc.
    nd goal: Model-Controller + DIP
    • Separate infrastructure
    implementations from model
    • Prepare repository package and
    move database handling
    implementation to datastore
    package. (apply DIP)
    • Get used to how to use interface
    in Go

    View Slide

  29. © - BASE, Inc.
    - Go Basic Questions -
    Final goal: “Layered Architecture + DIP”
    - Architecture Questions -
    What’s layered architecture?
    How to apply Dependency
    Inversion Principle in Go?
    What should we write in
    application layer?
    How to use interface type
    At nd goal, team will acquire
    How to implement API server
    by net/http package
    How to write an unit test
    Got it!

    View Slide

  30. © - BASE, Inc.
    Got it! - Go Basic Questions -
    Final goal: “Layered Architecture + DIP”
    - Architecture Questions -
    What’s layered architecture?
    How to apply Dependency
    Inversion Principle in Go?
    What should we write in
    application layer?
    How to use interface type
    At nd goal, team will acquire
    How to implement API server
    by net/http package
    How to write an unit test
    Acquire Basic of Go and Archictecture
    from more complicated design

    View Slide

  31. © - BASE, Inc.
    Final goal: Layered Architecture + DIP
    • Introduce service package
    corresponding to “service
    application layer” in DDD as
    processing becomes more
    complicated

    View Slide

  32. © - BASE, Inc.
    - Go Basic Questions -
    Final goal: “Layered Architecture + DIP”
    - Architecture Questions -
    What’s layered architecture?
    How to apply Dependency
    Inversion Principle in Go?
    What should we write in
    application layer?
    How to use interface type
    At final goal, team will reach
    How to implement API server
    by net/http package
    How to write an unit test
    Got it!

    View Slide

  33. © - BASE, Inc.
    - Go Basic Questions -
    Final goal: “Layered Architecture + DIP”
    - Architecture Questions -
    What’s layered architecture?
    How to apply Dependency
    Inversion Principle in Go?
    What should we write in
    application layer?
    How to use interface type
    At final goal, team will reach
    How to implement API server
    by net/http package
    How to write an unit test
    Got it! Reach common understanding of
    implementation policies

    View Slide

  34. © - BASE, Inc.
    Go Skills/Knowledge
    Architectural
    complexity
    Layered
    Architecture + DIP
    Simple Model-Controller
    Model-Controller + DIP
    .
    .
    Approach to build architecture
    To acquire Go skills and knowledge rapidly

    View Slide

  35. © - BASE, Inc.
    To acquire Go skills and knowledge rapidly
    .Use standard package as much as possible
    • To learn Go language itself
    • ex. use net/http package to serve HTTP
    .Write a test
    • To get feedback on the code design (such as
    testability)
    • For quick refactoring

    View Slide

  36. © - BASE, Inc.
    Problem of building architecture for beginners
    Approach to build architecture
    Summary
    Talk structure

    View Slide

  37. © - BASE, Inc.
    Summary
    • In my approach, an architecture grew with
    team members’ ability growth
    • Set a final goal and intermediate goals
    • To grow rapidly, use standard package as much
    as possible and write a test

    View Slide

  38. © - BASE, Inc.
    Feel free to ask me any Q
    GopherCon
    . . - @hgsgtk

    View Slide