Bismillah Insha allah
mockito
spring boot
aws (sqs)
redis
java better practice
read open source code
ext js
----
node js
---
micro service architecture
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.
https://microservices.io/patterns/microservices.html
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.
---
Decomposition patterns
Decompose by business capability
Decompose by subdomain
The Database per Service pattern describes how each service has its own database in order to ensure loose coupling.
The API Gateway pattern defines how clients access the services in a microservice architecture.
---
Cross-cutting concerns patterns: Microservice chassis pattern and Externalized configuration
--
Observability patterns:
Log aggregation
Application metrics
Audit logging
Distributed tracing
Exception tracking
Health check API
Log deployments and changes
UI patterns:
Server-side page fragment composition
Client-side UI composition
---
Netflix, which is a very popular video streaming service that’s responsible for up to 30% of Internet traffic, has a large scale, service-oriented architecture. They handle over a billion calls per day to their video streaming API from over 800 different kinds of devices. Each API call fans out to an average of six calls to backend services
---
Amazon.com originally had a two-tier architecture. In order to scale they migrated to a service-oriented architecture consisting of hundreds of backend services. Several applications call these services including the applications that implement the Amazon.com website and the web service API. The Amazon.com website application calls 100-150 services to get the data that used to build a web page.
---
The auction site ebay.com also evolved from a monolithic architecture to a service-oriented architecture. The application tier consists of multiple independent applications. Each application implements the business logic for a specific function area such as buying or selling. Each application uses X-axis splits and some applications such as search use Z-axis splits. Ebay.com also applies a combination of X-, Y- and Z-style scaling to the database tier.
--
https://microservices.io/microservices/news/2018/02/20/no-such-thing-as-a-microservice.html
--
The microservice architecture does this in two ways:
Simplifies testing and enables components to deployed independently
Structures the engineering organization as a collection of small (6-10 members), autonomous teams, each of which is responsible for one or more services
These benefits are not automatically guaranteed. Instead, they can only be achieved by the careful functional decomposition of the application into services.
A service must be small enough to be developed by a small team and to be easily tested. A useful guideline from object-oriented design (OOD) is 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 and design services that are cohesive and implement a small set of strongly related functions.
The application also be decomposed in a way so that most new and changed requirements only affect a single service. That is because changes that affect multiple services requires coordination across multiple teams, which slows down development. Another useful principle from OOD is the Common Closure Principle (CCP), which states that classes that change for the same reason should be in the same package. Perhaps, for instance, two classes implement different aspects of the same business rule. The goal is that when that business rule changes developers, only need to change code in a small number - ideally only one - of packages. This kind of thinking makes sense when designing services since it will help ensure that each change should impact only one service.
--
Forces
The architecture must be stable
Services must be cohesive. A service should implement a small set of strongly related functions.
Services must conform to the Common Closure Principle - things that change together should be packaged together - to ensure that each change affect only one service
Services must be loosely coupled - each service as an API that encapsulates its implementation. The implementation can be changed without affecting clients
A service should be testable
Each service be small enough to be developed by a “two pizza” team, i.e. a team of 6-10 people
Each team that owns one or more services must be autonomous. A team must be able to develop and deploy their services with minimal collaboration with other teams.
--
Solution
Define services corresponding to business capabilities. A business capability is a concept from business architecture modeling. It is something that a business does in order to generate value. A business capability often corresponds to a business object, e.g.
Order Management is responsible for orders
Customer Management is responsible for customers
Business capabilities are often organized into a multi-level hierarchy. For example, an enterprise application might have top-level categories such as Product/Service development, Product/Service delivery, Demand generation, etc.
--
Resulting Context
This pattern has the following benefits:
Stable architecture since the business capabilities are relatively stable
Development teams are cross-functional, autonomous, and organized around delivering business value rather than technical features
Services are cohesive and loosely coupled
--
Issues
There are the following issues to address:
How to identify business capabilities? Identifying business capabilities and hence services requires an understanding of the business. An organization’s business capabilities are identified by analyzing the organization’s purpose, structure, business processes, and areas of expertise. Bounded contexts are best identified using an iterative process. Good starting points for identifying business capabilities are:
organization structure - different groups within an organization might correspond to business capabilities or business capability groups.
high-level domain model - business capabilities often correspond to domain objects
--
Pattern: Decompose by subdomain
Context
--
Pattern: Transaction log tailing
Context
You have applied the Application events pattern. In order to be reliable, each step of a saga must atomically update the database and publish messages/events. It is not viable to use a distributed transaction that spans the database and the message broker.
Problem
How to publish messages/events into the outbox in the database to the message broker?
Forces
Solution
Tail the database transaction log and publish each message/event inserted into the outbox to the message broker.
The mechanism for trailing the transaction log depends on the database:
MySQL binlog
Postgres WAL
AWS DynamoDB table streams
Example
Eventuate Local implements transaction log tailing.
Resulting context
This pattern has the following benefits:
No 2PC
Guaranteed to be accurate
This pattern has the following drawbacks:
Relatively obscure although becoming increasing common
Requires database specific solutions
Tricky to avoid duplicate publishing
Related patterns
The Application events pattern creates the need for this pattern.
The Polling publisher is an alternative solution
https://microservices.io/patterns/data/transaction-log-tailing.html
https://github.com/eventuate-examples/eventuate-examples-java-customers-and-orders
https://github.com/eventuate-examples/es-kanban-board
https://github.com/cer/event-sourcing-examples
---
mockito
spring boot
aws (sqs)
redis
java better practice
read open source code
ext js
----
node js
---
micro service architecture
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.
https://microservices.io/patterns/microservices.html
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.
---
Decomposition patterns
Decompose by business capability
Decompose by subdomain
The Database per Service pattern describes how each service has its own database in order to ensure loose coupling.
The API Gateway pattern defines how clients access the services in a microservice architecture.
---
Cross-cutting concerns patterns: Microservice chassis pattern and Externalized configuration
--
Observability patterns:
Log aggregation
Application metrics
Audit logging
Distributed tracing
Exception tracking
Health check API
Log deployments and changes
UI patterns:
Server-side page fragment composition
Client-side UI composition
---
Netflix, which is a very popular video streaming service that’s responsible for up to 30% of Internet traffic, has a large scale, service-oriented architecture. They handle over a billion calls per day to their video streaming API from over 800 different kinds of devices. Each API call fans out to an average of six calls to backend services
---
Amazon.com originally had a two-tier architecture. In order to scale they migrated to a service-oriented architecture consisting of hundreds of backend services. Several applications call these services including the applications that implement the Amazon.com website and the web service API. The Amazon.com website application calls 100-150 services to get the data that used to build a web page.
---
The auction site ebay.com also evolved from a monolithic architecture to a service-oriented architecture. The application tier consists of multiple independent applications. Each application implements the business logic for a specific function area such as buying or selling. Each application uses X-axis splits and some applications such as search use Z-axis splits. Ebay.com also applies a combination of X-, Y- and Z-style scaling to the database tier.
--
https://microservices.io/microservices/news/2018/02/20/no-such-thing-as-a-microservice.html
--
The microservice architecture does this in two ways:
Simplifies testing and enables components to deployed independently
Structures the engineering organization as a collection of small (6-10 members), autonomous teams, each of which is responsible for one or more services
These benefits are not automatically guaranteed. Instead, they can only be achieved by the careful functional decomposition of the application into services.
A service must be small enough to be developed by a small team and to be easily tested. A useful guideline from object-oriented design (OOD) is 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 and design services that are cohesive and implement a small set of strongly related functions.
The application also be decomposed in a way so that most new and changed requirements only affect a single service. That is because changes that affect multiple services requires coordination across multiple teams, which slows down development. Another useful principle from OOD is the Common Closure Principle (CCP), which states that classes that change for the same reason should be in the same package. Perhaps, for instance, two classes implement different aspects of the same business rule. The goal is that when that business rule changes developers, only need to change code in a small number - ideally only one - of packages. This kind of thinking makes sense when designing services since it will help ensure that each change should impact only one service.
--
Forces
The architecture must be stable
Services must be cohesive. A service should implement a small set of strongly related functions.
Services must conform to the Common Closure Principle - things that change together should be packaged together - to ensure that each change affect only one service
Services must be loosely coupled - each service as an API that encapsulates its implementation. The implementation can be changed without affecting clients
A service should be testable
Each service be small enough to be developed by a “two pizza” team, i.e. a team of 6-10 people
Each team that owns one or more services must be autonomous. A team must be able to develop and deploy their services with minimal collaboration with other teams.
--
Solution
Define services corresponding to business capabilities. A business capability is a concept from business architecture modeling. It is something that a business does in order to generate value. A business capability often corresponds to a business object, e.g.
Order Management is responsible for orders
Customer Management is responsible for customers
Business capabilities are often organized into a multi-level hierarchy. For example, an enterprise application might have top-level categories such as Product/Service development, Product/Service delivery, Demand generation, etc.
--
Resulting Context
This pattern has the following benefits:
Stable architecture since the business capabilities are relatively stable
Development teams are cross-functional, autonomous, and organized around delivering business value rather than technical features
Services are cohesive and loosely coupled
--
Issues
There are the following issues to address:
How to identify business capabilities? Identifying business capabilities and hence services requires an understanding of the business. An organization’s business capabilities are identified by analyzing the organization’s purpose, structure, business processes, and areas of expertise. Bounded contexts are best identified using an iterative process. Good starting points for identifying business capabilities are:
organization structure - different groups within an organization might correspond to business capabilities or business capability groups.
high-level domain model - business capabilities often correspond to domain objects
--
Pattern: Decompose by subdomain
Context
--
Pattern: Transaction log tailing
Context
You have applied the Application events pattern. In order to be reliable, each step of a saga must atomically update the database and publish messages/events. It is not viable to use a distributed transaction that spans the database and the message broker.
Problem
How to publish messages/events into the outbox in the database to the message broker?
Forces
Solution
Tail the database transaction log and publish each message/event inserted into the outbox to the message broker.
The mechanism for trailing the transaction log depends on the database:
MySQL binlog
Postgres WAL
AWS DynamoDB table streams
Example
Eventuate Local implements transaction log tailing.
Resulting context
This pattern has the following benefits:
No 2PC
Guaranteed to be accurate
This pattern has the following drawbacks:
Relatively obscure although becoming increasing common
Requires database specific solutions
Tricky to avoid duplicate publishing
Related patterns
The Application events pattern creates the need for this pattern.
The Polling publisher is an alternative solution
https://microservices.io/patterns/data/transaction-log-tailing.html
https://github.com/eventuate-examples/eventuate-examples-java-customers-and-orders
https://github.com/eventuate-examples/es-kanban-board
https://github.com/cer/event-sourcing-examples
---
No comments:
Post a Comment