Is it hard to have a technical architecture that doesn’t have to be something fancy, just multiple microservices?
I watched some videos, they all use es, MQ, Redis things, I do not use these things, simply have multiple services, is it feasible? For more Java learning materials and interview materials, click here
What are microservices
The father of Microservices, Martin. Fowler’s overview of microservices is as follows:
Currently, there is no uniform, standard definition of microservices While there is no precise definition of this architectural style. But generally speaking, microservices architecture is an architectural pattern or architectural style that advocates the partitioning of a single application into a set of small services, each running its own independent process, which coordinate and cooperate with each other to provide ultimate value to users. Services communicate with each other using lightweight communication mechanisms (usually RESTful apis based on HTTP). Each service is built around a specific business and can be independently deployed to a production environment, class production environment, and so on. In addition, unified and centralized service management mechanism should be avoided as far as possible. For a specific service, appropriate language and tools should be selected to build it according to the business context, so that there can be a very lightweight centralized management to coordinate these services. Services can be written in different languages, and different data stores can be used.
Small service
A small service has no specific standard or specification, but it must be small in general specification.
Process of independent
Each set of services runs independently, maybe one of my services is running on the Tomcat container and another is running on Jetty. The entire service can be continuously scaled horizontally in a process manner.
communication
The protocols of the past were heavy, like ESB, like SOAP, light communication, which meant that smarter and lighter services called each other than in the past, in terms of smart endpoints and dumb Pipes, these endpoints were decoupled. Completing a business communication call to string these Micro Services is like piping a series of command services through a Linux system.
In the past, we used to think about all kinds of dependencies and the problems of system coupling. Microservices can make developers more focused on business logic development.
The deployment of
It’s not just the business that needs to be independent, it’s also the deployment that needs to be independent. However, it also means that the traditional development process will change to a certain extent, and there will be some operational criticism of development suitability
management
Traditional enterprise-level SOA services tend to be large, difficult to manage, highly coupled, and costly for teams to develop. Microservices allow teams to choose their own technology implementation, and different services can choose different technology stacks to implement their business logic according to their own needs.
The pros and cons of microservices
Why microservices? Because it’s fun? Isn’t. Here are some of the more complete advantages I found on the Internet:
- Advantages Each service is cohesive and small enough that the code is easy to understand so that it can focus on a specific business function or business requirement
- Development is simple and efficient, and a service may be dedicated to doing only one thing.
- Microservices can be developed independently by small teams of two to five developers.
- Microservices are loosely coupled, functional services that are independent in both development and deployment phases.
- Microservices can be developed in different languages.
- Easy to integrate with third parties, microservices allow an easy and flexible way to integrate automatic deployment through continuous integration tools such as Jenkins,Hudson,bamboo.
- Microservices can be easily understood, modified, and maintained by a single developer so that small teams can focus on their own work. No – Value is achieved through cooperation. Microservices allow you to leverage the latest technology.
- Microservices are just code for business logic, not mixed with HTML,CSS, or other interface components.
- Each microservice has its own storage capacity and can have its own database. You can also have a unified database.
In general, the advantage of microservices is that, in the face of large systems, it can effectively reduce the complexity and make the logic of service architecture clearer.
However, it also brings many problems, such as data consistency in distributed environment, complexity of testing, and complexity of operation and maintenance.
Have you thought about using microservices?
First mall development according to your actual need to architecture, for example, only in WeChat small commodity scroll pictures show in the program, product categories, WeChat payment, order, address, shipping information briefly, and a set of background management system, including: users, roles, such as products, pricing, order, basically a complete market system can run. So is it necessary to micro service, or the single service is enough?
The main purpose of the microservice architecture is to solve the problem of frequent service function updates and releases, which always affect the large area of business jitter, thus reducing the agile iteration of new functions. Because this problem is unavoidable for a single service, it must affect reliability.
- Distributed CAP: However, in the microservice projects I have worked with, the microservice delivery mechanism is often not mature. In fact, every time a microservice is released and a single unit is released, all the services have to be stopped and redeployed. Why is that? Because online transaction systems must prioritize consistency, no matter what development teams talk the talk when it comes to microservices, they will be honest when it comes to deployment. Do you already know how CAP theory works in a distributed environment?
As long as it is online transaction, it is necessary to guarantee distributed strong consistency in microservice environment. As shown below:
- Distributed transactions: Another issue encountered by microservices is the separation of SQL operations from single applications to databases into PRC remote collaborations, where distributed transactions may be involved.
As shown in the figure below: The originator initiates a payment submission to the payment microservice. After the payment is completed, the payment microservice needs to notify the order service to update the order state with RPC call. At this time, the system has fallen into the vortex of distributed transactions. Are you ready for distributed transactions?
Technology is introduced gradually as the size of the business grows
Why Redis, ElasticSearch (es), MQ? Let’s go through each of these technologies in business, and you can evaluate whether to introduce them.
- Redis: the main function is query cache, prevent database breakdown, the main situation is the mall has a high concurrency access state, but congratulations, using Redis to prove your business is very successful.
As shown in the figure below: A relatively standard MySQL read-write separation, Redis acts as a distributed architecture coupling for online transaction processing as a query buffer. This situation also occurs when the MySQL read-write separation cannot solve the high concurrency caused by a peak moment, the breakdown of the database, need to increase a second level cache to solve.Please be sure to follow the K.I.S.S. principle, which is not added technically. Because there are always distributed consistency issues, in addition to the Redis cache, which is actually a very popular practice among engineers at present, but there are uncontrollable complexity in ensuring the consistency of MySQL master/slave replication, moreover, The introduction of data synchronization consistency between the cache system (Redis) and the database (MySQL) will make the overall architecture more complex, which will lead to a lot of unpredictable troubles after the online, so before full preparation, increase the complexity of the architecture should be cautious.
- Elasticsearch: Content retrieval to a large number of goods, advanced classification is not only a keyword query, more need to be a professional search the goods content provides full text retrieval, convenient for the user by combining keywords, faster you want to find the goods, unless to oneself of the programming language you think good, can directly use luence, otherwise the es is a very good choice.
MySQL binlog->Canal->Kafka->Elasticsearch This is the surface said to be simple, but really to do well, internal to ooze through the engineer’s hard work and sweat.
- MQ: When there is an interlocking situation between the mall’s micro-services and between the mall and the third-party services, the general micro-service architecture will form an event-driven mechanism, namely EDA. For example, after an order is initiated, it will be pushed to the downstream through messages, which may be processed by the distribution system of the order. So with MQ, the system is no longer a small commercial service, it is platform-level! As shown below:
Of course, the introduction of MQ does not necessarily mean that it has been developed to scale. It is also possible that the O2O business needs to be faced from the very beginning, and the online business events need to be pushed to the offline business system in the early stage, which requires MQ. It is recommended to consider mq supporting distributed transactions, such as RocketMQ. As shown in the figure below: When traditional enterprises engage in Internet +, at the very beginning, they have to consider using the message center to solve problems such as online and offline data docking, information security, and asynchronous collaboration.
conclusion
Finally, to sum up, I believe you should at least have a bottom in mind for the above content. You can make it clear that the technical system of the system architecture is constantly iterated and thickened, which is continuously supported according to the needs of the business and gradually produce good business support.
The more overdesign you have in the beginning, the more likely your system is to die, so should microservices be part of the design from the start? System performance optimization, advanced query, complex system optimization, etc., should be done in the early design? Is there already a matching team organization? These are all things that need to be considered, long term but deep.
If the article has the wrong place welcome to correct, everybody exchanges with each other. Accustomed to reading technical articles on wechat, students who want to get more Java learning materials and interview materials can: click to receive