Micro service appraisal and thinking

By Sharon Stephens,2015-03-02 16:38
18 views 0
Micro service appraisal and thinking

    Micro service appraisal and thinking

    Micro service one and only a very special function, through the remote API to provide the system the function.For example, imagine a warehouse management system, such as micro service may provide some of the functions in the system are:

    ; Receive inventory

    ; Calculate the new inventory where the deposit

    ; Computing will inventory in warehouse to correct placement of the


    ; Distribution delivery routes for warehouse staff

    ; Receive the order

    ; Computing warehouse specified within a group of order picking route

    ; Distribution of picking route for warehouse staff

    These functions (possibly more) are made by a single micro service

    implementation.Each micro service has a separate thread operation, and can be independent of other services for deployment.As each service has its own special database, although every micro service and other services collaboration and communication.

    Have a completely different micro service in the system may be realized in different platforms, some may be. On the NET, the other in Erlang, the other in the Node. Js.As long as it can coordinate of the problem of language, various micro service normal communication with each other, will be able to work.HTTP is good communication options: the platform all mentioned above, there are many other platforms can handle HTTP., of course, also have other technology with micro service communication rules, such as some queue, some of the service bus and some binary protocol.Among these technologies, HTTP is probably the most widely supported, quite easy to understand, and as shown on the world wide web is very good, in general is a good solution.

    Again in warehouse system, for example: the system of a micro is picking route distribution services.Figure 1 shows the distribution of "picking route micro service" micro service request received from another collaboration: for designated staff set up the next picking route.Distribution of picking lines micro service must for employees to find the right line, while another micro service calculated the optimal route of the work done, picking route micro distribution service just received the notice of picking route and determine how to distribute the route for the employees.In the micro distribution of picking route service, received the request - assigned employees picking route, search the database, to find the right picking route, and choose a return to the micro service calls.

    What is the service architecture?

    Micro service is a type of architecture, belong to the service oriented architecture of lightweight, these services are strictly focus on the same thing and do it well.

    Using micro services as the main structure type of system is a distributed system with large Numbers of micro coordination services, each service in charge of your own process.Due to the close collaboration between micro service, each service only provide a small piece of the puzzle, and the system as a whole works.Collaboration, each service to each other through the medium of lightweight, not a binding concrete platform for communication, such as. NET, Java and Erlang.As mentioned earlier, all communication between the micro service in the book are via HTTP, but there are other alternatives, such as queues, bus, or a similar binary protocol of Thrift.

    In a complex building and maintenance of the server software system, micro service architecture type quickly in popularity.It is conceivable that this way: in the traditional method and overall architecture of service-oriented (monolithic architectures), services a large number of potential benefits.On the premise of functioning, the tiny segment plasticity, extensibility and flexibility advantages, and allow users to spend only a short period of time can achieve deployment process from start to the production environment.

    Micro service features

    Although so much has been said, but the definition is vague.In order to narrow definition of micro service scope, we first to explore the characteristics of the micro service.In my understanding, the term micro service features are:

    1. Responsible for a single function

    2. Separate deployment

    3. Contains one or more processes

    4. Has its own data store

    5. A small team can maintain several micro service

    6. Can be replaced

    This feature list not only helps identify micro service, also can in giving full play to the advantages of micro service (with a plasticity, extensibility and flexibility of the system) under the premise of help define and implement the service, in order to see it.

    Responsible for a single function

    The tiny segment of the whole system is only responsible for a single function.This sentence decomposition for content consists of two parts: first, the service is only a single responsibility;Second, is responsible for the function.Single responsibility principle there are several kinds of description, one of the traditional description is:

    "When you need to modify a class reasons and only one (" There should never be more than one reason for a class to change.") "- Robert c. Martin SRP: single responsibility principle

    Although this statement mentioned the "class", this principle is not only suitable for object-oriented language class level.Through micro service, here in the service level using the single responsibility principle.A relatively new idea is also describe the single responsibility principle:

    Polymerization for the same reason to change things, separate change due to different reasons.(" Gather together the things that change for the same. Having Separate those things that change for the company. Having ") - Robert c. Martin single responsibility principle

    This principle applies to the micro service: micro service should be realized is a function.The service must change only follow when change the function.In addition, should strive to make micro service related functions completely, so during function changes the service also must change accordingly.

    The service system of a function could mean a few things.First of all, the function may be business.Business function is done, the system contributes to the system for the purpose of things, such as prices continue to track the user's shopping cart or calculation.Combing a system with independent business function is a good idea, is to use the Domain Driven Design.Second, sometimes function can be more other micro service need to use technical functions, such as integrated into some of the third party system.Technical function is not the system is decomposed into micro service, but because of the micro service execution business functions need to be the same as a result of the technical ability.

    Independent deployment

    Each micro service should be deployed separately.That is to say: when you change a specific micro service, need to be able to change in the micro service deployed in a production environment, without having to deploy or touching other parts of the system.Micro systems in other services shall, in fact, changes of micro service deployment, and continue to run continuously after completion of new version of the deployment.

    Imagine e-commerce sites: every time shopping cart service changes, should be able to immediately deploy.Prices at the same time micro service, recommend service, product catalog, and so on shall continue to run and meet the user's request.

    Can be deployed separately for each service is very important, for several reasons.Which is, in a micro service system there are a lot of services, in collaboration with several other every micro service.Development work done at the same time of each part, or a lot of micro service in parallel.If you need to deploy all at the same speed or many micro service, management, deployment will soon become sparse, especially often leads to high risk deployment, this is we want to avoid.Instead we hope can be deployed to small changes each micro services, the risk will be lower.

    In when the rest of the system to normal operation of the deployment of a single service, build process should bear this in mind: every micro service must be packaged in different component or package.Similarly, the deployment process itself must also support the other micro service continues to run, independent deployment of micro service changes.Every time, for example, the process of micro service deployed to the server, in order to reduce downtime can use rolling deployment method.

    Micro interactive services are also affected by the expected independence deployment.Change the micro service interface must be, in most cases, backward compatibility, so other existing micro service can continue way according to merge with the old version and new version integration.In addition, the interactive services must be flexible, each service must occasionally go wrong in other micro service continue to maintain the best running state.A micro service errors, such as for deployment time short downtime - must not affect other service, just cause functional shrink or time longer.

    Contains one or more processes

    A micro service is composed of one or more of the process, this feature is there are always two sides to everything.First, each micro service independently of other micro service;Second, each service can have more than one process.

    A micro service independently, is due to want to keep every micro service independently of other micro service continues to run as much as possible.In addition, in order to separate the deployment of the service, the micro service cannot according to other micro way to run.Again in the shopping cart micro service for example: if the micro service run in the same way as with the product catalog, shopping cart code may cause negative effect in the catalog code, this represents a shopping cart micro service between micro service closely with the product catalog is not popular coupling.

    Now think about the deployment of a shopping cart the new version of the service.Either have to redeploy the catalogue service, or have to have some sort of dynamic code load function, to replace the running code in the shopping cart.Before an option and the principle of micro service independent deployment completely contrary, an option after is too complex and there are at least caused by micro service deployment shopping cart catalogue the risk of micro service downtime.

    Each service may contain more than one process, the surface may be surprising, try to make each micro service here as simple as possible, after all, good control, then why bother with more than one process?Using e-commerce to do an example: perform recommendation algorithm will show recommended options in e-commerce site, these algorithms in the process of the micro service belongs to run, also stores provide recommendations need data.This data may be stored in hard disk files, but are more likely to exist in the database, in the process of the second run database also belong to this service.A micro service usually has two or more processes of demand, it is just because of the micro service need to implement all that is needed, in order to provide includes such functions as data storage and background processing.

    Has its own data store

    A micro services include data storage, store the required data in the process, it is because we hope that the service is a complete range of functions.Most business functions need some data storage, such as for product catalog micro service, each product need to store the information.Micro service and other services in order to keep the product catalogue of loose coupling, completely information data stored product is included in the catalog service.By the catalog service determine when, how to store product information.Micro service, other services, such as shopping cart only through a catalogue of micro service interface to access product information, and can never be direct access to the directory to store products.

    Each micro service contains its own data store, which opened according to each service requirements, for the possibility of different micro service using database technology.Catalogue micro service may use SQL server to store product information, and shopping cart micro service may use Redis to each user's shopping cart information storage, micro service is recommended use Elastic Search index to provide recommendation service.For each of the micro service choice of database technology is part of the execution, for other micro service is hidden.Mix database technology with each micro service requirements in terms of matching the advantage of each service can use the most appropriate database.The development time, the performance and scalability is very good, but also poses a cost problem.Database technology is very complex, and learn to use in a production environment to run on a reliable database is not easy.For micro service selection database information, should consider the problem of choice.But also want to remember, as a result of micro service has its own data store, just a moment is also feasible to switch to another database.

    Small teams can maintain

    Until now has not discussed much micro service the scale of the problem, although the micro service of "micro" suggests that these services are small.But it doesn't think discussion service should have a few lines of code, demand/how many cases or shall perform the function point several these what is the point.All of these depends on the complexity of micro service function.Truly meaningful is to consider maintenance service work.Points out that the micro scale of service a rule of thumb is: the size of a small team should be able to maintain a few 5 people or more micro service.Maintain a micro service including maintain its normal operation and achieve their goals: the development of new functions, from development to a massive wave of micro service in a new micro, monitoring, testing and fixing bugs and other services.Considering a small team should be able to complete several micro service all of these work, you should be the typical size of micro service concept.


    A service is replaceable, representing it can be rewritten from scratch within a reasonable time frame.That is to say, the maintenance of the service team may decide to use the implementation of the new to replace the existing, and does not disturb the normal work process.This feature is a micro service scale constraint: if a micro services grow too large, replacement costs will be too high, only keep small to rewrite a reality.

    Why would teams decided to rewrite the micro service?One reason may be that the code is too messy, another reason is that the micro services cannot be run in a production environment is good.Although the situation is not wish, but embodies the advantages of the service.Even efforts to build service, time demand caused by the change could lead to the realization of the existing method cannot meet the demand and need to change.And over time, the code may be difficult due to the initial design too much and turned into a mess.Performance requirements may need a boost, and cannot meet the existing design.If a small to micro service within a reasonable time frame can be rewritten, occasional these conditions are all ok.Understand the existing implementations of all knowledge at the same time, combining the new demand, can simply rewrite the work done.

Report this document

For any questions or suggestions please email