Knowledge Transfer

Ethickfox kb page with all notes


Project maintained by ethickfox Hosted on GitHub Pages — Theme by mattgraham

Microservices Design Patterns

92.png

Microservices

Microservices is an architectural style that structures an application as a collection of services that are loosely coupled, highly maintainable, pluggable, and owned by small teams based on services.

Set of software applications designed for a limited scope that work with each other to form a bigger solution. Each service has minimal capabilities for the sake of creating a very modularized overall architecture.

Микросервисы

Небольшие автономные сервисы, которые работают совместно

Хотя для микросервисов нет единого принятого определения, имеется несколько важных характеристик:

Преимущества:

Benefits

This solution has a number of benefits:

Drawbacks

This solution has a number of drawbacks:

Проблемы микросервисных архитектур

Балансировки нагрузки

Microservices patterns

When to use the microservice architecture?

One challenge with using this approach is deciding when it makes sense to use it. When developing the first version of an application, you often do not have the problems that this approach solves. Moreover, using an elaborate, distributed architecture will slow down development. This can be a major problem for startups whose biggest challenge is often how to rapidly evolve the business model and accompanying application. Using Y-axis splits might make it much more difficult to iterate rapidly. Later on, however, when the challenge is how to scale and you need to use functional decomposition, the tangled dependencies might make it difficult to decompose your monolithic application into a set of services.

How to decompose the application into services?

Another challenge is deciding how to partition the system into microservices. This is very much an art, but there are a number of strategies that can help:

Decompose by business capability and define services corresponding to business capabilities.

Decompose by domain-driven design subdomain.

Decompose by verb or use case and define services that are responsible for particular actions. e.g. a Shipping Service that’s responsible for shipping complete orders.

Decompose by by nouns or resources by defining a service that is responsible for all operations on entities/resources of a given type. e.g. an Account Service that is responsible for managing user accounts.

Ideally, each service should have only a small set of responsibilities. (Uncle) Bob Martin talks about designing classes using the Single Responsibility Principle (SRP). The SRP defines a responsibility of a class as a reason to change, and states that a class should only have one reason to change. It make sense to apply the SRP to service design as well.

Another analogy that helps with service design is the design of Unix utilities. Unix provides a large number of utilities such as grep, cat and find. Each utility does exactly one thing, often exceptionally well, and is intended to be combined with other utilities using a shell script to perform complex tasks.

How to maintain data consistency?

In order to ensure loose coupling, each service has its own database. Maintaining data consistency between services is a challenge because 2 phase-commit/distributed transactions is not an option for many applications. An application must instead use the Saga pattern. A service publishes an event when its data changes. Other services consume that event and update their data. There are several ways of reliably updating data and publishing events including Event Sourcing and Transaction Log Tailing.

How to implement queries?

Another challenge is implementing queries that need to retrieve data owned by multiple services.

The API Composition and Command Query Responsibility Segregation (CQRS) patterns.

Patterns

There are many patterns related to the microservices pattern. The Monolithic architecture is an alternative to the microservice architecture. The other patterns address issues that you will encounter when applying the microservice architecture.

Minuses

Untitled2.png

Untitled 2 4.png

19.png

34.png

26.png

36.png

38.png

96.png

81.png

3.png

Instead of ACID

API Layer - proxy

Data Layer

Circuit breaker

52.png

145.png

71.png

144.png

Atomic Transaction Microservices

Untitled 15 3.png

67.png