It is the material presented in GopherCon 2019 Lightning Talk
© - BASE, Inc.Building API server-sidearchitecture for BeginnersGopherCon. . - @hgsgtk
View Slide
© - BASE, Inc.Talk abstract• A practical approach to build server-sidearchitecture in a Go project• Especially for teams who do not have Goexperience in business
© - BASE, Inc.Kazuki Higashiguchi / Backend engineer in Japan!About me@hgsgtkBASE BANK, Inc. / Dev Division / Tech lead
© - BASE, Inc.Problem of building architecture for beginnersApproach to build architectureSummaryTalk structure
© - BASE, Inc.Problem of building architecturefor beginnersApproach to build architectureSummaryTalk structure
© - BASE, Inc.Why I need server-side architecture.Keep a design easy to change• -> Separate external input/output andbusiness logic.Reach common understanding ofimplementation policies in a team• -> To make readable and maintainable code
© - BASE, Inc.• No absolute answer for any projects• We should determine a suitable architecturefor the projectReality of building architecture
© - BASE, Inc.• We should consider various things• Service requirements• Team member ability• Service scale• etcTo determine a suitable architecture
© - BASE, Inc.Problem of building architecture for beginners• We should consider various things• Service requirements• Team member ability• Service scale• etcFor beginners, “Team member ability” isa factor that can not be ignored
© - BASE, Inc.Go beginners have a lot of questionsHow to implement API serverby net/http packageHow to write an unit testHow to use interface type- Go basic questions -
© - BASE, Inc.If we determine complicated architecture from the beginningHow to implement API serverby net/http packageHow to write an unit test- Go basic questions -ex. “Adopt clean architecture!”How to use interface type
© - BASE, Inc.How to implement API serverby net/http packageHow to write an unit test- Go basic questions -ex. “Adopt clean architecture!”- Architecture questions -What’s clean architecture?How to apply DependencyInversion Principle in Go?What should we write in usecase layer?How to use interface typeIf we determine complicated architecture from the beginning
© - BASE, Inc.How to implement API serverby net/http packageHow to write an unit testing- Go basic questions -ex. “Adopt clean architecture!”- Architecture questions -What’s clean architecture?How to apply DependencyInversion Principle in Go?What should we write in usecase layer?How to use interface typeIf we determine complicated architecture from beginningThere are many questionsin team members’ mind
© - BASE, Inc.If we determine complicated architecture from beginningHow to implement API serverby net/http packageHow to write unit testingHow to use interface type- Go Basic Questions -ex. “Adopt Clean Architecture!”- Architecture Questions -What’s clean architecture?How to apply DependencyInversion Principle in Go?What we should write in usecase layer?When it gets worst,Confusing
© - BASE, Inc.Why I need server-side architecture.Keep a design easy to change• -> Separate external input/output andbusiness logic.Common understanding of implementationpolicies in a team• -> To make readable and maintainable codeWe are not able to achieve“common understanding”
© - BASE, Inc.Approach to build architectureArchitecturalcomplexityGo Skills/Knowledge
© - BASE, Inc.Approach to build architectureArchitecturalcomplexitythe finalarchitecture. Define “the final architecture”that seems to be good for the projectGo Skills/Knowledge
© - BASE, Inc.Approach to build architectureArchitecturalcomplexitythe final architecture. Set intermediate goals to“the final architecture”Go Skills/Knowledge
© - BASE, Inc.Example of my team• The team have few Go experience inbusiness• The Team has backend engineers• usually use PHP in work
© - BASE, Inc.Example of my teamArchitecturalcomplexityLayeredArchitecture + DIPSimple Model-ControllerModel-Controller + DIP..Go Skills/Knowledge
© - BASE, Inc.ArchitecturalcomplexityLayeredArchitecture + DIPSimple Model-ControllerModel-Controller + DIP..Go Skills/Knowledge. Define Layered Architecture + DIPas “the final architecture”Example of my team
© - BASE, Inc.Layered Architecture + DIP• Refer to Layered Architecture• Apply DIP (Dependency InversionPrinciple) to isolate domain logicfrom infrastructureimplementations(ex. databasehandling)
© - BASE, Inc.ArchitecturalcomplexityLayeredArchitecture + DIPSimple Model-ControllerModel-Controller + DIP..Go Skills/Knowledge. Set intermediate goalsExample of my team
© - BASE, Inc.st goal: Simple Model-Controller• Simple design only withcontroller and model• Model includes implementationssuch as handling a database• To get used to Go APIdevelopment
© - BASE, Inc.At st goal, team will acquireHow to implement API serverby net/http packageHow to write an unit testHow to use interface type- Go Basic Questions -Got it!
© - BASE, Inc.At st goal, team will acquireHow to implement API serverby net/http packageHow to write an unit testHow to use interface type- Go Basic Questions -Got it!Acquire Go Basic from simple design code
© - BASE, Inc.nd goal: Model-Controller + DIP• Separate infrastructureimplementations from model• Prepare repository package andmove database handlingimplementation to datastorepackage. (apply DIP)• Get used to how to use interfacein Go
© - BASE, Inc.- Go Basic Questions -Final goal: “Layered Architecture + DIP”- Architecture Questions -What’s layered architecture?How to apply DependencyInversion Principle in Go?What should we write inapplication layer?How to use interface typeAt nd goal, team will acquireHow to implement API serverby net/http packageHow to write an unit testGot it!
© - BASE, Inc.Got it! - Go Basic Questions -Final goal: “Layered Architecture + DIP”- Architecture Questions -What’s layered architecture?How to apply DependencyInversion Principle in Go?What should we write inapplication layer?How to use interface typeAt nd goal, team will acquireHow to implement API serverby net/http packageHow to write an unit testAcquire Basic of Go and Archictecturefrom more complicated design
© - BASE, Inc.Final goal: Layered Architecture + DIP• Introduce service packagecorresponding to “serviceapplication layer” in DDD asprocessing becomes morecomplicated
© - BASE, Inc.- Go Basic Questions -Final goal: “Layered Architecture + DIP”- Architecture Questions -What’s layered architecture?How to apply DependencyInversion Principle in Go?What should we write inapplication layer?How to use interface typeAt final goal, team will reachHow to implement API serverby net/http packageHow to write an unit testGot it!
© - BASE, Inc.- Go Basic Questions -Final goal: “Layered Architecture + DIP”- Architecture Questions -What’s layered architecture?How to apply DependencyInversion Principle in Go?What should we write inapplication layer?How to use interface typeAt final goal, team will reachHow to implement API serverby net/http packageHow to write an unit testGot it! Reach common understanding ofimplementation policies
© - BASE, Inc.Go Skills/KnowledgeArchitecturalcomplexityLayeredArchitecture + DIPSimple Model-ControllerModel-Controller + DIP..Approach to build architectureTo acquire Go skills and knowledge rapidly
© - 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 astestability)• For quick refactoring
© - BASE, Inc.Summary• In my approach, an architecture grew withteam members’ ability growth• Set a final goal and intermediate goals• To grow rapidly, use standard package as muchas possible and write a test
© - BASE, Inc.Feel free to ask me any Q GopherCon. . - @hgsgtk