2. CONTENTS
1. Known uses
2. Key characteristics of a service
3. The structure of a service
4. Benefits and drawbacks
5. Microservice canvas
6. Forces of a service
/13
2
3. Known uses
A very popular video streaming service
Responsible for up to 30% of Internet traffic
A large scale, service-oriented architecture
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
相片(標題) CC BY-SA 授權
/13
3
1
Netflix proprietary server
(Source by broadband analytics firm Sandvine)
4. Known uses
A multinational technology company
Migrated to a service-oriented architecture
consisting of hundreds of backend services
Website application calls 100-150 services to
get the data that used to build a web page
/13
4
2
Amazon S3 data center
相片(標題) CC BY
(Source by Amazon Architecture http://highscalability.com/amazon-architecture )
5. Known uses
A multinational e-commerce corporation
The application tier consists of multiple
independent applications
Each application uses X-axis splits and
some applications such as search use Z-
axis splits
Also applies a combination of X-, Y- and
Z-style scaling to the database tier
/13
5
3
相片 (標題) CC BY-SA 授權
6. Key characteristics of a service
/13
6
Highly maintainable
and testable
• rapid and frequent
development and
deployment
Loosely coupled
with other services
• without being
impacted by changes
to other services
• without affecting
other services
Independently
deployable
• enables a team to
deploy their service
without having to
coordinate with other
teams
Capable of being
developed by a
small team
• avoiding the high
communication
overhead of large
teams
7. The structure of a service
/13
7
The core of the service is its business logic, which is surrounded by adapters that communicate with
other services and applications
Operations
A command is an operation
that mutates data;
A query is a command that
retrieves data
Events
A service publishes events
to a message channel
implemented by a message
broker
• operations of other
services
• subscribes to their events
• persists data in the
service’s database
8. The structure of a service -Example
/13
8
• Let’s imagine that you are building an
e-commerce application
• Services communicate using either
synchronous protocols such as
HTTP/REST or asynchronous protocols
such as AMQP
• Each service has its own database
• Data consistency between services is
maintained using the Saga pattern
Fictitious e-commerce application(checking credit, maintaining inventory
and shipping orders)
9. The structure of a service -Saga pattern
/13
9
A saga is a sequence of local transactions
Each local transaction updates the database and publishes a message or event to
trigger the next local transaction in the saga
If a local transaction fails then the saga undo the changes that were made by the
preceding local transactions
10. Benefits and drawbacks
/13
10
Enables the continuous delivery and deployment
• Improved maintainability (easier to change)
• Better testability (faster to test)
• Deployed independently
• Each team can develop, test, deploy and scale their services independently of all of the other teams
Each microservice is relatively small
• Making developers more productive (easier to understand)
• The application starts faster
Improved fault isolation
• Other services will continue to handle requests(if fault)
Eliminates any long-term commitment to a technology stack
11. Benefits and drawbacks
/13
11
Additional complexity of creating a distributed system
• Implement the inter-service communication mechanism and deal with partial failure
• Cross-multiple services is more difficult
• Testing the interactions is difficult
• Careful coordination between the teams
Deployment complexity
• Complexity of deploying and managing a system comprised of many different
services
Increased memory consumption
12. Microservice canvas
/13
12
External view
• Name:name of the service Name
• Description:a brief description of the service Description
• Capabilities:the business capabilities implemented by the service
• Service API:the operations implemented by the service and the
domain events published by the service
• Quality attributes:non-functional attributes
• Observability:includes health check endpoint, key metrics
Implementation
• DDD(domain-driven design) subdomain 、Use Case、Resources
Dependencies
• Invokes:the operations, which are implemented by other
services that this service invokes invoke
• Subscribes to:the messages, which includes events, that this
service subscribes to
Examples of the microservice canvas https://github.com/cer/microservice-canvas
(Matt McLarty and Irakli Nadareishvili, 2017)
Domain-Driven Design: Tackling Complexity in the Heart of Software
13. Forces of a service
/13
13
New team members must quickly become productive
The application must be easy to understand and modify
To practice continuous deployment of the application
Must run multiple instances of the application on multiple
machines in order to satisfy scalability and availability
requirements
To take advantage of emerging technologies
(frameworks, programming languages and etc)
15. •專屬伺服器、分流設計 Netflix解決全球驚人流量之道 https://www.cool3c.com/article/104032
•Pattern: Microservice Architecture https://microservices.io/patterns/microservices.html
•What’s a service - part 1? http://chrisrichardson.net/post/microservices/general/2019/02/16/whats-a-service-part-
1.html
•Pattern: Saga https://microservices.io/patterns/data/saga.html
•Node之可擴展性 --- Node的Cluster
https://mark-lin.com/posts/20170605/?msclkid=94b976b0c76011ecb073e53267a36d3c
•The Scale Cube https://microservices.io/articles/scalecube.html
x: 負載平衡
If there are N copies then each copy handles 1/N of the load
Y: Y-axis axis scaling splits the application into multiple
Each service is responsible for one or more closely related functions
(using noun / verb to split service )
Resources