Mode: API Gateway

Mode: API Gateway

Context

Let's say you're building an online store using Microservice architecture patterns, and you are implementing the product details page. You need to develop multiple versions of the product details of the user interface:

  • For desktop and mobile browser-based HTML5 / JavaScript in UI - HTML generated by the server-side Web applications
  • Native Android and iPhone client - the client and server interaction via REST API

In addition, the online store must open REST API product details through, for third-party applications.
Product Details UI can display a lot of information about the product. For example, POJO in Action page displays details of Amazon.com:

  • Basic information about the book, such as title, author, price and so on.
  • We purchase history
  • Availability
  • Other options to buy the book frequently purchased goods
  • Customers buy the book
  • Purchase of other goods
  • Customer Reviews
  • Seller ranking
  • ...

As the online store using the micro-service architecture model, so the product detail data distributed across multiple services. E.g,

  • Product information - basic information about the product, such as title, author pricing service
  • Price Order Service
  • Product Purchase History Inventory Service
  • Product Availability Assessment Service
  • Customer reviews ...

Therefore, the display code product details need to obtain information from all of these services.

problem

Micro-based client application services end how to access the various services?

focus point

  • Particle size micro API services provided are usually required with different clients. Micro services typically provide fine-grained API, which means that clients need to interact with multiple services. For example, as noted above, clients need product details need to obtain data from a number of services.

  • Different clients require different data. For example, the product detail page desktop desktop browser versions are usually finer than the mobile version.

  • Different types of network client performance. For example, a mobile network typically much slower than a non-mobile network and having a higher latency. Of course, any WAN faster than LAN. This means that the present mobile network and a server client machine used by end Web applications use a LAN have very different performance characteristics. Server-side Web application can issue multiple requests for back-end services, without affecting the user experience, because the mobile client can only do something.

  • The number and location of service instances (host + port) Dynamic Change

  • Partition of services may over time change occurs, it should be hidden from the client

  • Service may use a variety of protocols, some agreements may not be suitable Web

solution

Implement the API Gateway, which is a single entry point for all clients. Gateway API request processing in one of two ways. Some agents only request / routed to the appropriate service. It to process other requests by multiple fan-out service.

API gateway can open a different API for each client, rather than providing a common style API. For example, API gateway functions Netflix adapter-specific client code, the code for each client API provides requirements for the most appropriate.

API Gateway security can be achieved, for example, verify that clients have the right to execute the request

variant

A variant of this mode is the mode of the rear end of the front end. It defines for each client a separate API gateway.

In this example, there are three clients: Web applications, mobile applications and external third-party applications. There are three different API gateway. Each API provides to its customers.

example

result

Using the API Gateway provides the following benefits:

  • The isolation and client application mode partition micro and services, so that the client service instance is determined from the position of the best questions for each client API reduction request / times is round. For example, API enables a client to a gateway serving data retrieved from the plurality of services through a single.
  • Fewer requests also means less overhead and improve the user experience.
  • API Gateway is crucial for mobile applications. To simplify client logic by calling for more mobile services from the client to the API gateway converts from the "standard" Web-friendly public API protocol to any protocol used internally 

API gateway mode has some drawbacks:

  • Increased complexity - API Gateway is required to develop, deploy and manage mobile due in part to another through the API gateway additional network jumps to increase the response time - but for most applications, the cost of an extra round trip is negligible.

problem:

  • How to implement the API Gateway? Event-driven / passive method is best to have to scale up to handle high loads. On the JVM, based NIO libraries (such as Netty, Spring Reactor, etc.) makes sense. NodeJS is another option.

Relevant examples

It is known to the

example

See the API Gateway that part of my Microservices pattern’s example application. It’s implemented using Spring Cloud Gateway.

Guess you like

Origin www.cnblogs.com/paxlyf/p/11278271.html