My micro service road

Remember one day 14 years, the life force, embarked on this road programmer. By now, already sixth year. Fortunately, writing code is a variety of professional experiences in my life favorite occupation. Barring unforeseen circumstances, I will always do so until the end of life. 2019 will soon be over, to write this text as a souvenir, but also want to read this text students some insights. In particular, they want to switch to a programmer, or .NET, PHP would like to turn the direction of Java programmers, hoping to give you a little encouragement and help.

Micro service is a hot topic, as a service on top of the micro practice more than four years old driver, talk about my experience.

15 years I recruited a new company, responsible for the development of a mall system. In view of past experience in a small, multi-service system in order to solve a set of common user needs. The user, group, organization, roles and permissions Token independence from throughout the system. And store management system as a separate system further exist. Followed by another a few have developed a system call interface uses http protocol between them. No doubt, this is just a very simple and original multi-service architecture. Why do not micro-service architecture? First, a single service is still relatively large. Then there is no RPC framework is httpClient directly on. But there is no service registry / discovery, configuration centers, gateway, limiting / fuse, monitor, and is simply nothing to Han. But this time the various business apart to lay the foundation for the subsequent service of a true micro, but also took an important step forward. As a result of the .NET technology stack, so the back on the road to true micro-services system transformation step on a lot of the pit. Really long story, for the time being is not here to mute table.

17 years I returned to Hangzhou from Beijing, has entered an Internet start-up company as an architect. Well startups, early very simple, including the company's business systems, too. My task is to redesign the company's business systems, to meet the xxx and yyy, there zzz. In short, it requires quite tall on. At that time, the concept of micro-services have been very popular, and for micro-services, I also have some of their own understanding and then a Diudiu practical experience. To meet this ambitious vision for the boss, did not say, it is micro-services, is the separation of the front and rear end. Chart a few paintings, sure enough, the boss was satisfied, he turned around to take it hoodwinked investors to go ......

We planned a four centers:
User Center contains resources, users, groups, organizations, the role of authority, tenants, verify, it was demolished seven service.
Message center, responsible for message notification, SMS, e-mail, messages, etc. within the application, no further split service.
Payment center, responsible for docking Alipay, micro-letters, UnionPay payment channel, no more splits.
Order Center, split into areas of service orders and order management services two services.

Because Java is a technical team to, so naturally adopted the Spring family bucket, which has everything, really fragrant. Message Center and I am responsible for the payment center interface design, order center field only put forward the principle of separation of services and management services, specific design is another architect responsible. User Center for me hundreds of times, but added the concept of tenants, in order to support the needs of multi-tenant platform. In addition to resources and services to engage them, so that resources can be configured. Overall, equivalent to re-write the code again in Java. In the process of rewriting, due to the characteristics of Java language and C # still have a lot of different places, ideas implemented also changed. In different languages ​​to achieve the same demand, it is quite interesting. It feels like opening a door and found a new world. Spring boot also gave me a lot of surprises, often find some new play, then sigh loudly: FML, this can actually do!

This time practice, the biggest problem is the strong business foundation and weak. At that time Ali has not made clear its strategy in Taiwan, and our system has little meaning in the table. Demand from business point of view, in fact, do not need micro service, a bit over-designed. In fact, after only one year, the company went alas, vanished. Of course, the main reason for this outcome is that the boss rather than in technology. The benefits of these basic services, then after my entry of new companies has been reflected. Business depends on infrastructure construction have been good, and the rest need only concern for business is enough. Like the country has given you through the motorway network and high-speed rail, airports, ports, what are completed, local governments only need single-minded enough to engage in economic development. If a small, poor countries do so, it is estimated will die out themselves. Infrastructure really burn ah, we state also saved more than 20 years of belongings, to seize the international situation opportune chance to play again so.

For micro-service system, we focus on these three points will suffice: First, the selection of micro-service components, and second, how the service division, the third is how the data consistency issues.

Selection problem micro-services component, in fact, I do not have much advice, because I have only been exposed Spring Cloud this set. For me, Spring Cloud is relatively mature, easy to use solution. Supported languages ​​are many, if not support, it is easy to make in his own language other wheels to use. But I still have not used any of the distribution center, but simply engage in a configuration database, jenkins which replaces the configuration through scripts based environment. Always wanted to own put forward a simple configuration center, but it has been a good thought what features to achieve, it has been shelved.

The second question and the third question of fact, there is a correlation. My suggestion is that the service can be logically adequacy standard (there is no logic and other services dependent) were divided into the smallest particle size. Especially in the field of services and business management services on the field, the proposed split into multiple services. Because the field data is relatively stable, but the business logic is very easy to change, after the spin-off not only effectively enhance the stability field of services, but also facilitate business needs change at any time. Sub-library by field data may be, for example, the flow of processing order data and order data points is not necessary. In other words, under normal circumstances, it should be multiple services share a single database.

For data consistency, my experience is this:
1, can be used to ensure that the database transaction, use database transactions. This is also the reason why the database field by points.
2, cross-database data is a shuttle MQ, ensure that the final consistency of the data on it. If the data is inconsistent with the server like accidental power-down due to lost data due, my solution is to manually repair. As long as data can be derived, there is no data can not be repaired, artificial run a script, every minute fix.

Finally, I want to share with you my open source project: xuanbg (Brian Xan) · GitHub . Has now completed most of the server mentioned above message center server and user-centric, follow-up will add a financial center as well as their clients. I hope that this project may be able to provide some combination of micro-services infrastructure out of the box, in order to reduce the conversion to the micro-service architecture development costs.

Part of the list has been completed as follows:
User Services: https://github.com/xuanbg/insight_user
Tenant Services: GitHub - xuanbg / insight_tenant: Tenant Services
role services: https://github.com/xuanbg/insight_role
Authentication: GitHub - xuanbg / insight_auth: authentication service
gateway: GitHub - xuanbg / gateway: Spring Cloud gateway-based micro-service gateway
message center: GitHub - xuanbg / insight_message: message service Center

Unfinished:
Resource management service
organization serving
third-party payment unified access
settlement services (collection, payment, refund)
funds account service
user account services
purse Management Services

Multi-tenant platform management client
tenant system management client
financial center management client

Guess you like

Origin www.cnblogs.com/xuanbg/p/12079024.html