Opportunities & Challenges in Adopting Microservice Architecture ...
Microservice architecture design principles
-
Upload
sanjoy-kumar-roy -
Category
Technology
-
view
436 -
download
0
Transcript of Microservice architecture design principles
![Page 2: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/2.jpg)
Let’s take the inspiration from biological cells before talking about Microservice:• They are small and single purpose• They are many of them but they work in
concert with one another• Each cell is able to respond to its
environment• They communicate with each other using
messages• They can replicate• They keep outside out• Death is natural and expected
![Page 3: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/3.jpg)
Microservice architecture advocates creating a system
from a collection of small, isolated services, each of
which owns their data, and is independently isolated, scalable and resilient to
failure.
![Page 4: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/4.jpg)
Divide and ConquerA divide and conquer algorithm works
by recursively breaking down a problem into two or more sub-problems of the same (or related) type (divide), until these become simple enough to be
solved directly (conquer). The solutions to the sub-problems are then combined
to give a solution to the original problem.
![Page 5: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/5.jpg)
In Microservice Architecture we use
Divide and Conquer: the decomposition of the system
into discrete and isolated subsystems communicating over
well-defined protocols.
![Page 6: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/6.jpg)
Microservice
Single Responsibility Replaceable Organized around business capabilities
![Page 7: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/7.jpg)
Single Responsibility Principle
Single Responsibility Principle (SRP) states that a class or component should “only have one reason to
change.”
![Page 8: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/8.jpg)
Do One Thing, and Do It Well
This is the Unix philosophy: Write programs that do one thing and do
it well. Write programs to work together.
—Doug McIlroy
![Page 9: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/9.jpg)
“Micro” should refer to scope of responsibility.
A service has only one single reason to exist and should provide a single composable piece of functionality.
![Page 10: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/10.jpg)
A service should do one thing and do it well.
Focus should be on business capability.
![Page 11: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/11.jpg)
What about state?
Microservices are often stateful entities:
they encapsulate state and behavior.
![Page 12: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/12.jpg)
ProductService
CustomerService
OrderService
PaymentService
SearchService
DB
This is still a monolith.
![Page 13: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/13.jpg)
Oracle Couchbase Oracle
Customer Service
Customer Service
Customer Service
Customer Service
ProductService
ProductService
ProductService
ProductService
OrderService
OrderService
OrderService
Bounded Context Bounded Context Bounded Context
A microservice owns its data.
Business Capability Business Capability Business Capability
![Page 14: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/14.jpg)
Decentralized Data Management
• Each microservice manages it’s own database: either different instances of same database technology or completely different database system (polyglot persistence)
• Eventual consistency
![Page 15: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/15.jpg)
Microservices encapsulate state and behaviour.
Model each service as a Bounded Context.
Each service usually defines its own domain, each with its own Ubiquitous Language.
State(Data)
Behaviour(Business Rules) Business Capability
![Page 16: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/16.jpg)
Search Service
Search Service
SearchCache Couchbas
e
ProductService
ProductService
ProductService
ProductService
Bounded Context
Bounded Context
Client
Business Capability Business Capability
![Page 17: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/17.jpg)
IsolationIsolation is a prerequisite for resilience and elasticityEmbrace Share Nothing ArchitectureFailure Isolation (Bulkheading)Isolation between services makes it natural to adopt Continuous Delivery Isolation also makes it easier to scale each service, as well as allowing them to be monitored, debugged and tested independently Isolation is a prerequisite for autonomy
![Page 18: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/18.jpg)
An autonomous service can only promise its own behaviour by publishing its protocol/API.
All information needed to resolve a conflict or to repair under failure scenarios are available within the service itself, removing the need for communication and coordination.
APIs need to be well-defined and composable.
Autonomous Service
![Page 19: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/19.jpg)
Communicate through APIs
Service B
Couchbase
Service A
Oracle
APIinvoke expose
Contract
Shared understanding
![Page 20: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/20.jpg)
API Client/Server Guidelines REST level-3 with HAL+json Use proper HTTP techniques Base design on application states and transitions
Forward compatibility over versioning Drive documentation from code Don’t write smart clients
![Page 21: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/21.jpg)
Autonomy through Messaging
Service A(Pub)
Service B(Sub)
Service C(Sub)
Message Bus1 2 3
![Page 22: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/22.jpg)
•Only publish business events and IDs – avoid mutable data• Implement proper error handling• Beware of added complexity
Message Publisher Guidelines
![Page 23: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/23.jpg)
• Cater for duplicate message delivery through idempotency•Don’t rely on ordering• 1C late-commit pattern over 2PC• Implement proper error handling• Beware of added complexity
Message Receiver Guidelines
![Page 24: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/24.jpg)
Microservice benefits
• Strong module boundaries• Independent
deployment• Technology diversity• Failure isolation• Improves time to market• Reduced cost of change
and costs
• Distribution• Eventual consistency• Operational complexity
![Page 25: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/25.jpg)
General Microservice Architecture Principles
• Small and focused on a specific business capability• Eventual consistency • availability is more important than global and instant
consistency• Polyglot persistence• Pick most appropriate data and consistency model
• Async communication over sync• Failure resilient• Avoid SPOFs
![Page 26: Microservice architecture design principles](https://reader035.fdocuments.net/reader035/viewer/2022062316/58742faf1a28ab72188b74ed/html5/thumbnails/26.jpg)
Thank you