7 How Do We Build the Inside of our Microservice?

 

In this chapter we’re going to look at some of the patterns that can be used within microservices to encapsulate the business logic and loosely couple the modules within them. Since we are looking inside the microservice, we’ll use a few code examples, using pseudo-Java. These are just examples– they aren’t necessary to understand the ideas, so you can follow along, or just ignore the code and focus on the design concepts.

7.1 Why spend so much time on how to call a Microservice?

Up to now, we’ve been talking about the ways we can call microservices while keeping things cohesive and loosely coupled. Describing how to call a microservice is bigger than it looks, isn’t it? There are so many ways to craft the outside part that calls the microservice. This is all very exciting, but when do we talk about the secret sauce that goes inside?

In a totally unrelated incident, Bullwinkle called me up today. He was looking at his monthly sales report and asked me why we were spending so much time on how to call our microservices, and not so much time on selling Fantlers. I bet you know the answer (no cheating by going back to Chapter 2 to check!). It’s because microservices make promises:

7.2 Which Calling Protocol should we use?

7.3 Layered Software Architecture

7.4 The problem with Layers

7.5 Hexagonal Architecture

7.6 External Actors

7.7 Ports and Adapters

7.8 Dependency Inversion

7.9 Creating an Abstract Interface from a Concrete Implementation

7.10 Hexagonal Architecture for Microservices

7.11 Designing the Fantlers Store Microservice Using Hexagonal Architecture

7.11.1 Identifying the External Actors

7.11.2 Creating Ports

7.11.3 Adding Adapters

7.12 Modifying our Fantlers Store Microservice

7.13 Final Thoughts on Building the Inside of a Microservice

7.14 Summary