Microservice architecture route

1. Why did I choose the microservice architecture?

As we all know, monolithic applications, due to their various deficiencies, hardly support agile methods. If you want to create a software project for a large or complex business, it is best to start with a microservices architecture.

Microservice architecture is a flexible architecture that can significantly improve application flexibility, scalability, and more.

2. Microservice architecture route 

I know a lot of developers wondering how they should start their microservices architecture journey, with thousands of resources at their disposal, scattered all over the place. I decided to bring clarity to this journey by defining a roadmap for microservices architecture learning.

1. Basic ideas

Microservice-based architectures usually have several independent units that work together to receive and process various requests.

For example, if you decide to implement a microservice architecture, you should be familiar with various concerns in the application life cycle, such as persistence, logging, monitoring, load balancing, caching, etc., and you should also know which tools are better Or which stack is better for your application.

2、Docker 

Docker is an open-source platform for containerizing your applications, which includes the class libraries and dependencies your application needs to run in various environments. With the help of Docker, development teams are able to package applications into containers.

Why do I use it:

In fact, Docker is one of the best tools for containerizing applications, you can also create containers without using Docker, the real benefit of Docker is to make this process easier, safer, and simpler.

3. Container Orchestration

After containerizing the application, you will need some tools to manage the containerized application to perform some manual and automatic operations such as horizontal scaling.

Why do I use it:

Which of these tools is better to provide some services for your application management, such as automatic load balancing to ensure high availability of services.

This service is done by defining multiple manager nodes, if any failure occurs in one node manager, other managers can keep the application services available.

Which tools are better:

Kubernetes or K8s

4. API Gateway

An API Gateway can be thought of as a kind of middleware that acts as a middleware between your application services and different clients. An API Gateway can manage many things such as:

Routing: The gateway receives all API requests and forwards them to the target service.

Logging: You will be able to log all requests in one place.

Authorization: Check that you as a user are eligible to access the service, if not, you can deny the request

Performance profiling: You can estimate the execution time of each request and check your application bottlenecks.

Caching: By handling caching at the gateway level, you will eliminate a lot of traffic on the service.

In fact, it works as a reverse proxy, the client only needs to know your gateway, and the application service can be hidden and not directly exposed to other systems.

Why do I use it:

Without API Gateway, you may need to do some cross-cutting concerns in each service, for example, if you want to log the service's requests and responses. Also, if your application consists of multiple services, your client needs to know each service address, and in case of a service address change, multiple places should be updated.

Which tools are better:

Kong,Ocelot

5. Load balancing

The most important reason for us to choose microservice architecture is scalability, which means we will be able to handle more requests by running more service instances, but the question is, which instance should receive the request, or how the client will know which service instance Should the request be processed?

The answer to these questions is load balancing. Load balancing is a key component of highly available network infrastructure and is usually used to distribute workloads to multiple servers to improve the performance and reliability of websites, applications, databases or other services.

Why do I use it:

In order to scale your standalone service, you need to run multiple instances of the service. With a load balancer, the client does not need to know the correct instance of the service.

Which tools are better:

Traefik , NGINX,Seesaw

6. Service Discovery 

As the number of your application services increases, the services need to know each other's service instance addresses, but in a large application with many services, this cannot be handled. So we need service discovery, which is responsible for providing the addresses of all components in the application, which can easily send requests to the service discovery system and get the addresses of available service instances.

Why do I use it:

Service discovery is essential for your application when you can have multiple services in your application. Your application services don't need to know the address of each service instance, which means service discovery paves the way for you.

Which tools are better:

Consul,Zookeeper,Eureka,Nacos,etcd和Keepalived

7. Event bus

In the microservice architectural pattern, you will use two different types of communication, synchronous communication and asynchronous communication. Synchronous communication means that services call each other through HTTP or GRPC. Asynchronous communication means that services interact with each other through a message bus or event bus, which means there is no direct connection between services.

Your architecture can use both ways of communication, for example: in the online store example, you can send a message when an order is registered, and services subscribed to a specific channel will receive that message. But sometimes you may need some real-time queries, for example: you need to know the quantity of an item, you may use GRPC or HTTP calls between services to get the response.

Why do I use it:

If you want a scalable application with multiple services, one of the principles you will follow is to create loosely coupled services that interact with each other through an event bus. Also, if you need to create an application that can plug into a new service to receive a specific series of messages, you will need to use an event bus.

Which tools are better:

RabbitMQ, Kafka

8. Logging

When using the microservice architectural pattern, it is best to centralize service logs. These logs will be used to debug issues or aggregated according to their type for analysis.

Why do I use it:

When debugging the system, if you do not collect service logs in one place in advance, you may encounter difficulties. You can also associate logs related to a particular request with a unique correlation ID. This means that all logs from different services related to the request can be accessed through this correlation ID.

Which tools are better:

Elastic Logstash

9. Monitoring and Alerting

In microservices architecture, if you want a reliable application or service, you have to monitor the functionality, performance, communication and any other aspects of the application to achieve an accountable application.

Why do I use it:

You need to monitor overall functionality and service health, as well as monitor performance bottlenecks and prepare a plan to resolve failures. Optimize user experience by reducing service downtime by defining early alerts for services at critical points. When the load is heavy, etc., the overall resource consumption of the service can be monitored.

Which tools are better:

Prometheus , Kibana,Graphana

10. Distributed Tracking

Debugging is always one of the top concerns of developers, as you all have experience tracing or debugging singleton referenced programs. That's pretty straightforward and easy, but on a microservice architecture, since a request might go through different services, it makes debugging and tracing difficult because the services are not in one place, so distributed tracing tools will help.

Why do I use it:

Tracing your requests through different services can be frustrating or impossible without distributed tracing. You can easily trace requests and events with a rich UI that demonstrates request flow.

Which tools are better:

OpenTelemetry , Jeager,Zipkin

11. Data persistence

In most systems, we need to persist data, write application's data into physical files with different structure, so that the data can be used for further processing or reporting.

Why do I use it:

In monolithic applications we used to have one or two different persistence types, most monolithic applications used relational databases like SQL Server, Oracle, MySQL. But in microservice architecture, we should follow the "DataBase Per Service" pattern, which means keeping the persistent data of each microservice private to that service and accessible only through its API.

You will have different databases for different uses and scenarios. For example, a data presentation service might use a NoSQL database like ElasticSearch or MongoDB because they use a document infrastructure, which means that the persistent data in these databases is structured differently than relational databases and are more suitable for services with more reads and fewer writes .

On the other hand, in some microservices, you may need relational databases such as Oracle or SQL SERVER, or you may also need some databases that support graph structures or key-value structures.

So, in a microservice architecture, depending on the mission of the service, you will need different types of databases.

Which tools are better:

Relational database or RDBMS : PostgreSQL, MySQL, SQL SERVRE, Oracle

NoSQL databases: MongoDB, Cassandra, Elasticsearch

11. Cache

Caching reduces the latency of service-to-service communication for microservice architectures. A cache is a high-speed data storage layer. When data is requested from the cache, it is faster than accessing data from the hard disk.

Why do I use it:

In a microservices architecture, there are many strategies to implement caching in these ways. Consider the following:

1: Embedded cache (distributed and non-distributed)

2: Client-server caching (distributed)

3: Reverse proxy cache (Sidecar)

To reduce latency, caching can be implemented in different layers. Also, you can implement a distributed cache, which can be accessed by multiple microservices. They also have different purposes, such as current limiting. The purpose of current limiting is to protect the system by limiting the rate of concurrent access/requests or requests within a time window. Once the limit rate is reached, the service can be denied. .

which tools are better

Redis (Remote Dictionary Server), Apache Ignite,Hazelcast IMDG

 

12. Cloud provider

A cloud service provider is a third-party company that provides cloud-based platform, infrastructure, application or storage services. Just like homeowners pay for utilities like electricity or gas, companies typically only pay for the amount of cloud services they use based on business needs.

The most important categories of cloud providers:

  • Software as a Service (SaaS).

  • Platform as a Service (PaaS).

  • Infrastructure as a Service (IaaS).

why should i use it

One of the benefits of using cloud computing services is that companies can avoid the upfront cost and complexity of building and maintaining their own IT infrastructure, and pay only for what they use, as they are used. Today, companies can rent anything from applications to storage, rather than owning their own computing infrastructure or data centers.

which tools are better

Amazon Web Services (AWS), Microsoft Azure, Google Cloud,Alibaba Cloud

 

Guess you like

Origin blog.csdn.net/summer_fish/article/details/130635124