chapter four

4 Microservices Project Setup

 

This chapter covers

  • Using Hexagonal Architecture for microservice projects
  • Setting up toolkits for the services
  • Running a basic microservice application
  • Making initial request to running application

It is very normal to say How should I structure my project? before writing the first line of your Go microservice project. The answer to this question might seem very difficult at first, but you can see how easy it is if you apply some common software architecture pattern. Those patterns are mostly for solving the modularizaton problems to have testable components. Let’s see how we can apply those principles to a Go microservice project and perform some test to see how gRPC endpoints work.

4.1 Hexagonal Architecture

Hexagonal Architecture, proposed by Alistair Cockburn in 2005, is an architectural pattern that aims to build loosely coupled application components that can be connected to each other via ports and adapters. In Hexagonal Architecture, consumer arrives at application at Port via an Adapter and the output is sent from application through a Port to an Adapter. Therefore, Hexagonal Architecture is also known as Ports & Adapters. Using Ports and Adapters creates an abstraction layer that protects the core of the application from external dependencies. Now that we understand the components of Hexagonal Architecture in general, let’s dive a bit deeper for each of them.

4.1.1 Application

4.1.2 Actors

4.1.3 Ports

4.1.4 Adapters

4.2 Order Service Implementation

4.2.1 Project Folders

4.2.2 Initializing Go Project

4.2.3 Implementing Application Core

4.2.4 Implementing Ports

4.2.5 Implementing Adapters

4.2.6 Implementing gRPC Adapter

4.2.7 Dependency Injection & Running the Application

4.2.8 Calling gRPC endpoint

4.3 Summary