Framework service of Distributed system architecture

Source: Internet
Author: User
Tags session id

To make the business system infinitely scalable, the micro-service architecture is in the ascendant. Essentially, the service framework is formed by using API (for example, rest) to encapsulate service invocation.


Since it is a distributed API call, there are three common ways that network IO is involved:

1) bio:blocking IO, blocking mode, one socket with one thread processing

2) nio:non-blocking IO, event driven, with reactor mode, one thread handles multiple socket,jdk1.4 or more versions supported

3) Aio:asynchronous IO, asynchronous, using Proactor mode, NIO can be notified when the relevant operation, AIO when notified that the relevant operation has been completed, JDK1.7 above version support.


For the service's API calls, it is divided into synchronous service invocation and asynchronous service invocation.

Synchronous service Invocation

When synchronizing service calls are supported, it is common to have IO threads, data queues, communication object queues, and timed tasks.

1) The IO thread is specifically responsible for the socket connection for data transmission and receiving.

2) Send and receive data into the data queue

3) The Communication object queue holds the communication objects used by multiple threads, mainly to block the request thread, and the request thread puts the data into the data queue and generates a communication object, enters the communication object queue and waits on the communication object queue.

4) The communication object is used to wake the request thread.

5) If execution finishes and returns before the remote call times out, the IO thread notifies the communication object that the communication object ends the request thread's wait and passes the result to the request process for subsequent processing

6) The Timer task is responsible for checking which communication objects in the communication queue have timed out, and these communication objects will notify the request thread to time out.


Asynchronous service invocation

When you support asynchronous service invocation, there are four common ways to call

1) One-way request, basically equivalent to a notification that does not guarantee reliable arrival

2) callback, is a passive way. The requestor sets the callback object, writes the data to the data queue and continues to process itself. The execution of the callback is in the IO thread or in the thread of the timed task (the primary processing timeout), and it is recommended to execute the callback with the new thread.

3) The future of Future,java is very convenient, first put the future into the queue, then the data into the queue, processing in the thread, and so on, and so on after the other processing of the request threads, through the future to obtain the communication results and directly control the timeout.

4) reliable asynchronous, can ensure that the asynchronous request is executed remotely.

The service side has two main parts:

1) Registration management of the local service, the service needs to register to the service Registration Lookup center before being discovered by the service caller.

2) Locate the service and execute it according to the request. The registration is completed at startup, the listening port, and the communication part is also realized by NiO method. The processing of the IO thread for communication is usually multiple and complete the protocol parsing. The invocation service is typically performed on a worker thread, and deserialization depends on the implementation. Worker threads are actually thread pools of multiple different services that are isolated from each other.

There are two types of upgrades for services:

1) The interface is unchanged, the code is perfect or the function is perfect, but the implementation of the internal service changes.

2) need to modify the original interface

A) Add a method to the interface

b) Modify the invocation's argument list for some methods of the interface. Can be resolved by a version number, or the extensibility of parameters, such as a map parameter, should be considered in the design


Service governance is the ability to manage services and view services after the system has adopted a service framework. The management service needs to control and operate the services in the whole distributed system, looking at the state of the runtime or some specific information, historical data and so on. The details of the service include: Service information, quality of service, capacity, dependencies, distribution, statistics, metadata, service queries, reporting and monitoring. Service management content includes: Upper and lower line, routing, current limit downgrade, group, thread pool management, room rules, service authorization.


It is important to note the way in which session storage problems are handled in a distributed system:

1) Session Sticky: Responsible for balancing requires request forwarding based on the session ID of each request

2) session data synchronization is increased between sessions Replication:web server

3) Centralized storage of Session data: Large number of Web servers, the best session count

4) Use of cookies to use session data on client requests

Framework service of Distributed system architecture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.