Microservices Architecture
Microservices Architecture
Microservices
Architecture
CSC4307
What are Microservices?
• Server-side
systems based on
single
applications
• Easy to develop,
deploy and
manage
Challenges of Monoliths
Microservices
9
Microservices Example
11
Authentication
microservices
12
What to choose ?
Monoliths Microservices
13
Characteristics of microservices
Self-contained
Do not have external Lightweight
dependencies. They manage their Communicate using lightweight
own data and implement their protocols
own user interface.
Business-oriented
Should implement business capabilities
and needs, rather than simply provide
a technical service.
14
• A well-designed microservice should
have high cohesion and low coupling.
• Cohesion
• High cohesion means that all the
parts that are needed to deliver the
Cohesion & component’s functionality are
Coupling included in the component.
• Coupling
• Low coupling means that
components do not have many
relationships with other
components.
15
How big
should a
microservice
be?
“Rule of
twos”
Range of functionality that might be
included in a password management
microservice.
Password
management
microservice
example
17
Support code that is needed in all
microservices.
Microservice
support code
example
18
Exercises
23
• Associate services with business
capabilities
What are the
microservices
that makeup a • Design services so that they only have
system? access to the data that they need
Decomposition
Guidelines • Balance fine-grain functionality and
system performance
24
Imagine that you are developing a photo
printing service for mobile devices:
• Users can upload photos to your server from
their phone or specify photos from their
Instagram account that they would like to be
printed.
photo printing • Prints can be made at different sizes and on
different media. Users can choose print size
system for and print medium. For example, they may
decide to print a picture onto a mug or a T-
mobile devices shirt.
• The prints or other media are prepared and
then posted to their home.
• They pay for prints either using a payment
service such as Google or Apple Pay or by
registering a credit card with the printing
service provider.
25
Microservices architecture for a photo
printing system
26
Microservices architecture - key
design questions
27
• You must establish a standard for
communications that all microservices
should follow.
28
Synchronous and
asynchronous
microservice
interaction
29
Direct and
indirect service
communication
30
Examples of
Message
Brokers
31
• A message protocol is an agreement between
services that sets out how messages between
these services should be structured.
32
Microservices architecture - key
design questions
33
How should
data be • Isolate data within each system service
distributed with as little data sharing as possible.
and shared?
• If data sharing is unavoidable, design
Microservice microservices so that most sharing is
data design ‘read-only’, with a minimal number of
services responsible for data updates.
34
• Dependent data inconsistency
• The actions or failures of one service can
cause the data managed by another
service to become inconsistent. use
“compensating transactions”
• Replica inconsistency
Inconsistency
management • There are several replicas of the same
service that are executing concurrently.
These all have their own database copy
and each updates its own copy of the
service data. You need a way of making
these databases ‘eventually consistent’ so
that all replicas are working on the same
data.
35
• Eventual consistency is a situation where
the system guarantees that the databases
will eventually become consistent.
Eventual
consistency
36
Microservices architecture - key
design questions
37
Orchestration and Choreography
40
• Internal service failure
Conditions that are detected by the service and
can be reported to the service client in an error
message.
Failure types
in a • External service failure
microservices These failures have an external cause, which
system affects the availability of a service.
41
• To report microservice failures use
HTTP status codes, which indicate
whether a request has succeeded.
microservice • Status code 200 means the request
failures has been successful,
Reporting • Codes from 300 to 500 indicate
service failure.
• 401 Unauthorized
• 404 Not Found
Timeouts and circuit breakers
43
Using a circuit breaker to cope with
service failure
44
RESTful services
REST Definition
USE HTTP VERBS STATELESS SERVICES
RESTful
service
principles
49
• Create: Implemented using HTTP POST,
which creates the resource with the given
URI.
51
HTTP request and response
message organization
52
• Accept specifies the content-types that
can be processed by the requesting
service and that are therefore acceptable
in the service response. Commonly used
types are text/plain and text/json.
• Users can query the system to discover incidents on the roads on which
they are planning to travel.
• When implemented as a RESTful web service, you need to design the
resource structure so that incidents are organized hierarchically.
• For example, incidents may be recorded according to the road
identifier (e.g. A90), the location (e.g. stonehaven), the carriageway
direction (e.g. north) and an incident number (e.g. 1). Therefore,
each incident can be accessed using its URI:
• https://trafficinfo.net/incidents/A90/stonehaven/north/1
54
• Incident ID: A90N17061714391
• Date: 17 June 2017
• Time reported: 1439
Incident
• Severity: Significant
description • Description: Broken-down bus on north
carriageway. One lane closed. Expect
delays of up to 30 minutes
55
• Retrieve
• Returns information about a reported
incident or incidents. Accessed using
the GET verb.
• Add
• Adds information about a new
incident. Accessed using the POST
Service verb.
operations • Update
• Updates the information about a
reported incident. Accessed using the
PUT verb.
• Delete
• Deletes an incident. The DELETE verb
is used when an incident has been
cleared.
56
Practice
Service
deployment
58
• Continuous deployment means that as soon
as a change to a service has been made and
validated, the modified service is redeployed.
Service
deployment
59
• CD depends on automation → when a change is
committed, a series of automated tests is
triggered.→ test passes, software automatically
packaged and deployed.
Deployment
automation
60
A continuous deployment
pipeline
61
Versioned services
62
Topic presentations
1. Define and Describe Orchestration list all existing orchestration tools and
provide a complete description of Kubernetes.
2. What is Advanced Message Queuing Protocol (AMQP) and how it is used and
supported by RabbitMQ ?
3. Explain what is description and discovery of RESTful services and how it is
implemented?
4. Docker uses a technology called namespaces describe what is it and what it is
used for?
5. Describe and identify all CI/CD pipeline tools provided by the following cloud
service provider: Google
6. Describe and identify all CI/CD pipeline tools provided by the following cloud
service provider Amazon
7. Describe and identify all CI/CD pipeline tools provided by the following cloud
service provider IBM
8. Describe and identify all CI/CD pipeline tools provided by the following cloud
service provider Alibaba
9. Describe and identify all CI/CD pipeline tools provided by the following cloud
service provider Microsoft Azure
10. Describe and identify all CI/CD pipeline tools provided by the following cloud
service provider Heroku
11. Define and explain authentication and authorization and how they differ?
Topic presentations (cont.)
1. Describe and identify all CI/CD pipeline tools provided by the following cloud
service provider Oracle Cloud
2. Describe and identify all CI/CD pipeline tools provided by the following cloud
service provider RedHat
3. What is refactoring and why is it useful, explain with example?
4. Describe various types of software failures and how can we deals/prevent
them?
5. Defines and describe serverless and microservices and how they are different?
6. Explain what are design patterns and why using them in your code contributes
to fault avoidance.
7. Identify and describe the main types of threat that have to be considered when
planning how to secure a software product against cyberattacks.
8. Define Conway law and describe how can it applies to software development?
9. Define and describe Version control systems and source code management and
what is the difference between them?
10. Describe Gitlab and GitHub and Bitbucket and What is difference between
them?
11. What is the difference between symmetric and asymmetric encryption? Why
do we need both encryption methods?