Also talk about NodeJS based the whole development of stacked (based on the before and after the end of the NodeJS separation

By Helen Bell,2015-12-23 02:05
10 views 0
Also talk about NodeJS based the whole development of stacked (based on the before and after the end of the NodeJS separation

    Also talk about NodeJS based the whole development of

    stacked (based on the before and after the end of the

    NodeJS separation


    In order to solve the various problems brought by traditional Web development model, we made many attempts, but because the before/after the physical gap, try the solutions are the same.From these mistakes, today we rethink the definition of "front end", the introduction of the front-end NodeJS students are familiar with, trying to explore a new model of front end separation.

    With different terminal (Pad/Mobile/PC) rise, more and more high to the requirement of developer, pure the browser responsive already cannot satisfy the high requirements of the user experience, we often need for different terminal developing custom version.In order to improve development efficiency, the separation of front and rear end demand is more and more attention, the backend is responsible for the business/data interface, responsible for showcases/interactive logic, the same data interface, we can customize the development of multiple versions.

    This topic has recently been discussed more, some BU also some attempts on ali.After discussion for a long time, our team decided to explore a set of front and rear end separation scheme based on NodeJS, there are some changing in the process of understanding and thinking, record here, also want to see the students participate in discussions, to help us improve.

    A, what is the front end separation?

    The beginning I found in the process of group discussion, everyone's understanding of front end separation, in order to ensure that can discuss the same radio channel to agree on what is "the separation of front and back side.

    Everyone agreed on the front end of the separation of example is the SPA (Single - page application), all data is used to show the back-end through asynchronous interface (AJAX/json) way to provide, just showcases.

    In a sense, SPA did separation before and after the end, but there are two problems with this approach:

    ; A WEB service, SPA class accounts for the proportion of the very few.A lot of scenarios and

    synchronous/synchronization + asynchronous hybrid mode, the SPA cannot serve as a universal


    ; SPA in the present stage of development mode, the interface is usually provided according to show

    logic, sometimes in order to improve the efficiency, will help us to deal with some backend logic,

    which means that the backend or involved in the View layer, is not the real separation of front and

    back side.

    SPA type before and after the end of separation, from the physical layer do distinguish (think as long as it is on the client side is front end, on the server side is the back-end), such a method has been unable to meet the needs of our front end separation, we think it is divided from the responsibility to meet the current we use scene:

    ; Front end: responsible for the View and Controller layers.

    ; The backend: only responsible for Model layer, business process/data, and so on.

    Why to do this kind of the division of responsibilities, behind will continue to explore.

    Second, the separation why front and back side?

    About this problem, the jade articlesWeb development schema evolutionExplained in very full, we'll probably reason:

    2.1 the application of the existing development mode

    Jade "mentioned several development models, each have each applicable scenario, there is no a completely replace another.

    ; Such as back-end MVC, do some synchronous display business efficiency is very high, but meet

    synchronous asynchronous page, with the back-end development communication up and you will

    have trouble.

    ; Ajax SPA type development mode, suit to develop the APP type of scenario, but only for APP,

    issues because SEO is bad, for many types of systems, thus the ways of development. 2.2 before and after the end responsibility is not clear

    In business logic and complex system, we maintain the most afraid of mixed together before and after the end of the code, because there is no constraint, the M - V - C each layer possible other layer code, accumulate over a long period, no maintenance at all. Although the front end separation can't completely solve this problem, but can be eased.Because from the physical level ensures that you can't do that.

    2.3 development efficiency

    Taobao's Web webx are basically based on MVC framework, architecture determines the front-end only depending on the backend.

    So our development model is still, front end write good static demo, back-end translated into VM template, the model's problem is not, was fun for a long time.

    Directly based on the back-end environment development is also very pain, configuration is very troublesome installation and use.In order to solve this problem, we invented a variety of tools, such asVMarket, but the front or to write the VM, and rely on the backend data, efficiency is still not high.

    In addition, the back-end couldn't get rid of to show the strong attention, which focus on the development of the business logic layer.

    2.4 limitations of front end play

    Performance optimization if only on the front end do space is very limited, so we often need to the backend to collision out sparks of cooperation, but as a result of the back-end framework restrictions, it is difficult for us to use the Comet, indicate technical solutions to optimize performance.

    In order to solve some of the problems mentioned above, we made many attempts, developed a variety of tools, but don't have much better all the time, mainly because we can only be the small space in the back-end to our division to play.Only really separated before and after the end, we can completely solve the above problems.

    Three end separation before and after, how to do?

    What to do before and after the separation, in fact the first section has the answer:

    ; Front end: responsible for the View and Controller layers.

    ; The backend: responsible for Model layer, business process/data, and so on.

    Imagine if the front master Controller, we can do the url design, we can decide according to the scene in the service side synchronous rendering, or according to the view

    layer data output json data, we can also according to the requirements of the presentation layer is easy to do indicate that Comet, Socket, etc., is a total demand decided to use way. 3.1 based on NodeJS "stack" type development

    If you want to achieve above stratified, will need a web service to help us achieve the back-end do before, hence the title mentioned "full stack based on NodeJS type development"

    This picture looks simple and is easy to understand, but never tried, there will be a lot of questions.

    ; SPA model, the backend for the required data interface, view the front have been able to control,

    why do you want to add NodeJS this layer?

    ; Add one layer, performance?

    ; One more layer, the front increased workload?

    ; Add one layer is a layer of risk, how to break?

    ; JAVA NodeJS can do anything, why?

    It is not easy to clear these problems, the following said I the understanding of the process.

    3.2 why do you want to increase a layer of NodeJS?

    At this stage we mainly after the end of the MVC pattern of development, this pattern is seriously hindered the front development efficiency, also let the back-end can't focus on business development.

    Solution is to make the front Controller can control layer, but if it's hard to do under the existing technical system, because it is impossible to let all the front-end to learn Java, install the backend development environment, write the VM.

    NodeJS can very good solution to this problem, we don't need to learn a new language, it can be done previously developed to help us to do, everything is so natural.

    3.3 performance problems

    Stratification is involved in the communication between each layer, there will be some performance loss.But reasonable layer can make the responsibility clear, also facilitate collaboration, will greatly improve the development efficiency.Layered losses, can compensate in other aspects of revenue.

    In addition, once the hierarchical decision, we can through optimizing communication methods, communication protocol, as far as possible to minimize loss.

    For example:

    Taobao baby details after a static page, there are still many need real-time access to information, such as logistics, promotion, etc., because the information in a different business system, so I need the front send 5 or 6 an asynchronous request to backfill the content. After a NodeJS, front end can be in NodeJS to represent the five asynchronous request, also can easily do indicate that the optimization can make the whole rendering efficiency a lot. May be on the PC do you think of five or six asynchronous requests a nothing important also, but in the wireless terminal, in the customer phones to set up a HTTP requests are expensive, with this optimization, the performance for several times.

    Taobao details based on the optimization of NodeJS we are underway, online after I share the process optimization.

    3.4 the front increased workload?

    Relative to only cut the page/do the demo, affirmation is increased a little, but the current mode have the alignment, the communication link, the process is time, also easy to bug out, still difficult to maintain.

    So, although the workload increases a little, but overall development efficiency will improve a lot.

    In addition, the test cost will save you a lot.Previously developed interface is directed at the presentation layer, it is difficult to write test cases.If done before and after the separation, tests can be separated, even those who dedicated test interface, those who focus on testing the UI (this part of work can even use tools instead of).

    3.5 increase the risk of how to control the Node layer?

    As the Node of large-scale use, system/ops/security department classmates will join the infrastructure, they will help us to improve each link may appear problem, safeguard the stability of the system.

    3.6 the Node can do anything, why JAVA?

    Our original intention is to do front end separate, if consider this question is a bit against our original intention.Use replace Java Node, we can't guarantee not appear such issues encountered today, such as the responsibility is not clear.Our purpose is hierarchical development, professional people do professional focus.Based on JAVA infrastructure is very strong and stable, and more suitable for do now architecture.

    Fourth, taobao, based on the separation of the before and after the end of the Node

    Above is my understanding of taobao separation layer before and after the end, based on

    the Node and the area of responsibility of the Node.Under the simple explanation: ; The top is the service side, that is, we often say the back-end.The backend for us, is a collection of

    the interface, the service side provide all kinds of interface for our use.Because of the Node layer,

    also need not what is limited in the form of services.For the backend development, they only care

    about business code interface implementation.

    ; The following of a service is a Node application.

    ; Node applications with a layer of the Model the Proxy and to communicate with the server.This

    layer mainly is the screeding calls to different interface, we need to encapsulate some view layer


    ; Node can easily realize the original vmcommon, TMS (reference taobao content management

    system), and other requirements.

    ; What to use the Node layer framework by the developer to decide.But it is recommended to use

    express + xTemplate combination, front and back side public xTemplate can do.

    ; How to use the Node to decide, but the exciting is that we can finally use the Node easily

    implement we want to output mode:

    JSON/JSON/RESTful/HTML/indicate/Comet/Socket/synchronous, asynchronous, think how the

    whole is how the whole, completely according to your scene.

    ; The browser layer, there is no change in our architecture, also do not want to because of the

    introduction of the Node to change you used to the development of cognitive in the browser.

    ; Introducing Node, is supposed to front end is just the part of the control to the front end control.

    This model we have two projects in development, although not online, but whether in the development efficiency, or in terms of performance optimization, we all have tasted the sweets.

    Fifth, we need to do?

    ; The development process of the Node are integrated into the taobao existing SCM process.

    ; The construction of infrastructure, such as the session, logger general module, etc.

    ; The development of best practice,

    ; Online success

    ; You know end of the concept of separation of before and after the Node

    ; security

    ; performance


    Won't have too much need to technology innovation and research, has very many ready-made accumulation.In fact some process is the key to get through and the accumulation of general solution, believe that as more of project practice, this will slowly become a stable process.

    Six, "midway island"

    Although "full stack type development based on NodeJS" pattern is very exciting, but the whole development of stack based on Node into a stable, let everybody can accept things still has a lot of way to go, we are conducting the "midway island" project is to solve the problem.Although westarted soon, but near the goal has been more and more!!!!!

Report this document

For any questions or suggestions please email