Patterns

API Composition

Over Data only

Similar with Using API Composition Pattern.

Drawing

Over Business Rules/Services

Where the API Composition would be a Service Composer that would receive data and run business rules over them, returning after the resulting data.

Drawing

Strangler Application

A way to decompose Microservices with two rules:

  1. Every new feature will be a microservice.

  2. Segregate small peaces of a monolith as a microservice.

At each interation, the monolithic system shrinks until it selft turns into a microservice.

ACL (Anti-Corruption Layer)

Just like in DDD microservices should use an Anti corruption layer to make services more independent.

In DDD an ACL is an interface, in microservices an ACL is another microservice in the middle.

Drawing

BFF (Backend for Frontend)

This is a technique used to serve data for specific frontend types, since each type of frontend expects different outputs from APIs.

To do this an ACL (Anti-Corruption Layer) is used to transform data returned from the APIs, depending on the Frontend that requested.

Drawing

How not to use BFFs

Writing the own API microservice to handle this is a solution if thinking ahead of time.

OR using solutions like GraphQL. Since the each Frontend client can choose the excat data that requests.

Transactional Outbox

This is a pattern to implement in a Microservice architecture, to highly increase Patterns, and avoid that requests don't get lost when microservices in the chain are unavailable. (Or even communication between Services and Queues)

Mainly used for transactions/requests that are not Sync, so that you don't need real time responses.

Drawing

To garantee that if at any step of the chain, the message won't be lost if a certain Microservice is down (Even with Patterns policies), you will have to persist this message in a Database or Queue.

So in the example of the image above, we could deal with:

With Database

MS 1 will have a Database specific for persisting these messages.

When MS 1 action starts the Message is persisted, and when MS 1 action ends it deletes from the Database.

Then if communication to MS 2 fails the message is persisted and MS 1 can still retry.

Examples of Database to use:

RDBMS

KV -> DynamoDB

Cache -> Redis

It is important to not mix this Database with the MS data Database.

With global Queue

Just like in the solution above, messages are produced when arrived in each Microservice, and a consumer runs on each of them, consuming the message as soon they finish.

Secret Manager

A mechanism to store Credentials inside a Microservice environment, so that they are not stored inside Environment Variables or stored inside the Microservices.

Logs

Good practice examples

Unify log lines to a single line:

Depending on the language or tools, it generates stack traces of logs or similars.

But a standerdized log should be in 1 line only.

More information, best practices and examples can be seen in #link_to_OTEL.

Last updated