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 the initial request to running application

It is very normal to ask 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 initially, but you can see how easy it is to apply some common software architecture patterns. Those patterns are mostly for solving the challenges like building modular projects to have testable components. Let’s see how to apply those principles to a Go microservice project and perform some tests to see how gRPC endpoints work.

4.1 Hexagonal Architecture

Hexagonal Architecture (https://alistair.cockburn.us/hexagonal-architecture/), proposed by Alistair Cockburn in 2005, is an architectural pattern that aims to build loosely coupled application components that can be connected via ports and adapters. In this pattern, the consumer arrives at the application at Port via an Adapter, and the output is sent through a Port to an Adapter. Therefore, Hexagonal Architecture is also known as Ports & Adapters. Using Ports and Adapters creates an abstraction layer that isolates the application's core from external dependencies. Now that we understand the components of Hexagonal Architecture in general let’s dive deeper into each.

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