Professional Documents
Culture Documents
DF Microservices - Architecture - 124notes SDF
DF Microservices - Architecture - 124notes SDF
Agenda
What are microservices and Why are they becoming popular
Best Practices
API Gateway
Microservices Architecture 1
structuring the different components and modules of a system, as well as for specifying
how those components and modules interact with each other.
Different architecture styles have different characteristics and are suited to different
types of systems and use cases. Some examples of architecture styles include:
2. Event-Driven Architecture: A style where the system is built around the concept of
events, with different components of the system reacting to and generating events.
It allows for greater scalability and flexibility, but can be difficult to debug and reason
about.
3. Layered (N-Tier) Architecture: A style where the system is divided into several
layers, each with a specific responsibility. It allows for separation of concerns and
easier maintenance, but can lead to tight coupling between layers. For example,
Spring MVC architecture.
The choice of architecture style depends on the specific requirements of the system and
the desired trade-offs in terms of scalability, maintainability, and performance.
Each service is responsible for a specific business function and can be developed,
deployed, and scaled independently of the other services.
Microservices are typically built using modern technologies such as containers and
cloud-native infrastructure.
Microservices Architecture 2
Why are microservices becoming popular?
Microservices offer a number of benefits over traditional monolithic architectures -
● They allow for faster development and deployment, as each service can be developed
and deployed independently.
● They also make it easier to scale and manage an application, as each service can be
scaled independently.
● Additionally, microservices make it easier to implement new technologies and handle
changes in business requirements.
● Microservices also provide flexibility and allows for different teams to work on different
services independently and also promotes reuse of services.
● Microservices also provide fault isolation, as a failure in one service will not bring
down the entire system.
Microservices Architecture 3
responsible for one specific business function. This makes it easier to
understand, test, and maintain the service.
2. Loose Coupling
Microservices should be loosely coupled, meaning that they should have minimal
dependencies on other services. This allows for greater flexibility and makes it
easier to change or replace a service without affecting other services.
3. High Cohesion
Microservices should be highly cohesive, meaning that all the components within
a service should be closely related to the service's single responsibility. This
makes it easier to understand and maintain the service.
4. Autonomy
Microservices should be autonomous and able to function independently of
other services. This allows for faster development, deployment, and scaling of
services.
5. Stateless
Microservices should be stateless, meaning that they should not maintain any state
information. This allows for greater scalability and fault tolerance.
Microservices Architecture 4
ordering, payment, and shipping. Identify the key business functions for your e-
commerce application and determine which functions would be best suited for
implementation as microservices.
6. Test and deploy the services: Test each service individually, and deploy them to a
production environment using containerization and orchestration tools like Docker
and Kubernetes.
7. Scalability: Scale up or down the services independently based on the traffic and
resource requirements.
Best Practices
Communication between microservices should be done over a lightweight protocol,
such as HTTP or gRPC.
Microservices Architecture 5
Services should be designed to handle high-throughput and low-latency
communication.
Services should be designed to handle different types of data, such as text and
binary data.
1. Synchronous Communication
● Synchronous communication is when a service sends a request to another
service and waits for a response.
● This is the most common form of communication between microservices.
● Examples of synchronous communication include REST and gRPC.
2. Asynchronous Communication
● Asynchronous communication is when a service sends a request to another
service without waiting for a response.
● This can be useful for handling tasks that are time-consuming or can be
performed offline.
● Examples of asynchronous communication include message queues and event-
driven architectures.
3. API Gateway
● An API Gateway is a service that acts as an intermediary between the client and
the microservices.
● It can be used to handle tasks such as authentication, rate limiting, and request
routing.
● This can help to reduce the load on the microservices and simplify communication
between them. Examples of popular API gateways are Zuul Server and NGINX etc.
Microservices Architecture 6
4. Service Discovery and Registration
● Service Discovery and Registration is a mechanism that allows microservices to
discover and communicate with other services in the system.
● Examples of service discovery and registration include Netflix Eureka and Consul.
3. SOAP (Simple Object Access Protocol): SOAP protocol is used for exchanging
structured information in the implementation of web services in computer networks.
It uses XML as its message format, and can be carried over a variety of lower-level
protocols, including HTTP and SMTP.
Asynchronous Communication
Microservices Architecture 7
There are several ways to implement asynchronous communication between
microservices,
here are some common methods:
1. Message Queues: Message queues are a way for microservices to send and
receive messages asynchronously. The sender sends a message to the queue and
the receiver retrieves it from the queue. Some popular message queue technologies
include RabbitMQ, Apache Kafka and Amazon SQS.
3. Webhooks: Webhooks are a way for one service to send a notification to another
service when a specific event occurs. For example, service A may send a webhook
to service B when a new order is placed. Service B can then process the order
asynchronously without having to repeatedly poll service A for new orders.
API Gateways
It can handle tasks such as:
2. Authentication and Authorization: The API Gateway can handle tasks such as
authenticating the client and authorizing the request before forwarding it to the
microservice. This can include tasks such as verifying user credentials, checking
permissions, and enforcing security policies.
Microservices Architecture 8
3. Rate Limiting: The API Gateway can limit the number of requests that a client can
make in a given time period, to protect the microservices from excessive traffic.
4. Caching: The API Gateway can cache frequently requested data to reduce the load
on the microservices and improve performance. This can include data such as
product information, customer information, and order history.
5. Transformation: The API Gateway can transform requests and responses between
the client and the microservices to ensure compatibility. This can include tasks such
as converting data formats, encrypting or decrypting data, and compressing or
decompressing data.
6. Aggregation: The API Gateway can aggregate the responses from multiple
microservices to provide a single response to the client. This can include data such
as product catalog, shopping cart, order and payment details.
7. Monitoring and Logging: The API Gateway can collect and log data about
incoming requests and outgoing responses to help with debugging and
troubleshooting. This can include data such as request and response headers,
payloads, timestamps, and error messages.
1. Service Registry: The service registry is a central repository where all the
microservices register themselves, providing information such as their name, IP
address, and port number. This information can be used by other microservices to
locate and communicate with the registered services.
Microservices Architecture 9
4. Failure detection: The service registry and discovery mechanism can also be used
to detect when a service is no longer available and remove it from the registry. This
can be done by periodically sending heartbeats to the service and removing the
service from the registry if the heartbeat is not received.
Once the components have been deployed, it is important to test the system to ensure
that it functions as intended. This includes verifying that all of the components are
communicating correctly, ensuring that there are no security vulnerabilities, and
validating performance metrics.
Once all of the tests have been passed, the system can then be released into
production. During this phase, it is important to make sure that the system is monitored
closely in order to ensure that it remains stable and secure. This can be done by
monitoring performance metrics, logging errors, and regularly applying security patches.
Microservices Architecture 10