on the way of architecture: the separation mode between front and back
The separation mode
Before and after the separation of the study for some time, coincides with the company has a large project decided to try to use the front and back-end separation mode, and then participate in it. The project from the beginning of 2016 to date, flat stable to spend, but also emerged more and more problems, is definitely not to say that the front and rear separation mode is not good, but many companies in the attempt to separate the front and back when not fully prepared.
On the Internet to separate the introduction of the article has been common, then I use a little superficial words also talk about this piece, shortcoming.
why to separate.
If you only ask "is the significance of the separation of the front and the back." "This is nonsense, because the front and back end of the Web from the perspective of software architecture is not always separated from the beginning, and browser, server may be forever separated."
In order to understand this problem, we need to understand the evolution of the Web research and development model, on this subject, the following blog is good, this side will not be a porter.
https://github.com/lifesinger/blog/issues/184
Instead of "separating for separation", we should "separate to truly understand web development, to better fulfill requirements." the misunderstanding of the separation of front and back.
1, the front-end staff is adequate.
Because of the traditional development style of the company's previous projects, that is, the later-end MVC-oriented development model, the front-end staff only provide static HTML pages, the rest of the work is done by the backend developers. The use of the front and rear separation mode can reduce the background burden, speed up research and development efficiency, of course, if the front-end can do well. In the past, you only need to provide the front end of the static page, in the front and back end of the separation mode to be responsible for the View+controller part of the project, in addition to static pages, but also responsible for all the interactive code page, as well as nodejs and view layer and back-end API interaction work, Undoubtedly increased the front-end staff learning costs, in the absence of adequate knowledge and talent reserves, can only let front-end staff overtime. The result is a large number of front-end staff leaving (PS: do so many things, wages must be added. )
2. Responsibility distribution at the front and back.
Many companies believe that after the front-end separation, the front and rear end only need to interact through the specified API, the front is responsible for page rendering, Nodejs is responsible for routing allocation, the backend provides the API. Neglected a large number of key tasks, responsibility allocation and details of processing no corresponding documents, caching mechanism, upload download, data verification, language internationalization and so did not produce the appropriate information. In addition, a large number of neglected the role of the NODEJS layer, just Nodejs as a route relay, this is also the Nodejs technology of the unfamiliar cause, in fact, Nodejs can be responsible for a lot of things, in addition to complex business logic processing and data operations by the Java responsible, A lot of work can be done at the Nodejs level. PS: It is not enough to cause the foundation. )
3, back-end API is restful style.
It is unreasonable that the RESTful style API should be the best practice for front and back end separation when many companies adopt the back-end separation mode and the back-end API still adopts the traditional style. Resultful recommended that each URL can operate specific resources, but also can accurately describe the server's handling of resources, usually the server to support the resources get/post/put/delete/, etc., used to achieve the resources of deletion and modification. Before and after the end of the separation, these api-url are docking bridge, the use of resultful interface address meaning to be more clear, see known meaning. PS: With the spring4.x unexpectedly still do not have rest style, not justified AH)
4, the front and back end collaboration mode.
After the separation of the front and back end, whether the interface of the API or test work, are related to the communication between the front and back, many companies using the front and rear separation, the front and back end collaboration model with the strength of the end, waiting for each other, development efficiency is low, instead of traditional development model For example, when the backend API is not written, the front-end cannot be debugged, which causes the front-end to be blocked by the back end. While this pattern of waiting for each other needs to be improved, Mock Server may solve some of the problems. how to detach back and forth.
How to do the front and back separation. The big direction is
Back end focus on: Back-end control layer (Restful API) & Service layer & data access layer;
Front End focus: Front control layer (NODEJS) & View Layer
I think that the front and rear separation mode should be this, of course, this is not necessarily true:
1, the project design phase, the front and back end of the structure of the project as a whole to analyze, discuss and determine the API style, responsibility allocation, development assistance model, to determine staffing; After the design is determined, the front and back end personnel together develop the development interface.
2, the project development phase, the separation of the front and back is the respective division of labor, Collaborative agile Development, the backend provides the restful API, and gives detailed documentation, front-end staff for page rendering foreground task is to send the API (get,put,post,delete, etc.) to obtain data (JSON, XML) after rendering the page.
3, the project testing phase, before the API completes, the front-end staff will use mock server to simulate the test, the backend personnel use JUnit for API unit test, do not have to wait for each other; After the API is complete, the front and back end can be tested again, of course not all interfaces can be defined in advance Some are adjusted during the development process.
4, the project deployment phase, using Nginx to do reverse proxy, that is, Java + Nodejs + nginx mode. PostScript Language
From the classic Jsp+servlet+javabean MVC era, to the SSM (Spring + SPRINGMVC + mybatis) and ssh (Spring + Struts + Hibernate) Java Framework era, Then to the front-end framework (Knockoutjs, Angularjs, Vuejs, Reactjs)-oriented mv* era, and then the Nodejs led the whole stack era, technology and architecture has been progressing. Although the "Nodejs based full stack development" model is exciting, there are still a lot of ways to turn the whole stack of node based development into a stable and acceptable thing for everyone. The road to innovation will not stop, whether the back-end separation mode or other models, are to more easily solve the demand, but they are only a "transit point."
There may be more and more "transit points" passing by, but do not fade away.