Translation API gateways (API Gateway)

Source: Internet
Author: User

This a translation of article ( http://microservices.io/patterns/apigateway.html) originally written and Copyrighted by Chris Richardson ( http://twitter.com/crichardson).

Mode: API GatewayBackground

Let's say you create an online store using MicroServices mode and are implementing the product detail page. You need to develop multiple versions of the Product Details user interface:

    • Html5/javascript-based ui-html for desktop and mobile browsers is generated via server-side web Apps

    • Local Android and iphone clients-these clients interact with the server through the rest API

for third parties public item details.

Product details can show a lot of information about a product . For example, Amazon.com on the POJOs in Action detail page shows:

    • Basic information about a book, such as title, author, price, etc.

    • Purchase History of Books

    • Is there any goods

    • Purchase parameters

    • Goods purchased at the same time as this book

    • What else did the user who bought the book buy?

    • User reviews

    • Rating of Sellers

    • ...

Now that the online store uses the MicroServices model, the product details data is expanded through the service. Such as:

    • Commodity Information Services (Product info Service)-Basic product information such as title, author

    • Price Services (Pricing Service)-Product price

    • Order service-Product purchase history

    • Inventory Services (Inventory service)-goods are in stock

    • Commenting services (Review service)-User reviews ...

Therefore, the code that displays the product details needs to obtain information from all of these services.

Problem

How do clients of MicroServices-based applications access these standalone services?

Driving force
    • The API granularity provided by MicroServices is usually different from the client's requirements. MicroServices generally provide fine-grained APIs, which means that clients need to interact with multiple services. As mentioned above, the client that needs the commodity details pulls the data from a large number of services.

    • Different clients require different data. For example, the desktop version of the product detail page is usually more detailed than the mobile version.

    • Different types of clients have different network performance. For example, mobile networks are generally slower and higher latency than non-mobile networks. Of course, a wide area network (WAN) is much slower than a local area network (LAN). This means that the network used by the mobile local client differs greatly from the performance characteristics of the server-side Web application's LAN. A server-side web app can send a large number of requests to the back-end service without impacting the user experience, but the mobile client can only send a small number of requests.

    • The partitioning of the service may vary over time, so it needs to be hidden from the client.

Solution Solutions

Implement an API gateway as the only entry for all clients. The API Gateway has two ways of handling requests. Some requests are simply proxied/routed to the appropriate service, and other requests are forwarded to a set of services.

Compared to providing a pervasive API,API gateway, different APIs are opened according to different clients. For example, the Netflix API gateway runs client-specific adapter code that provides the client with the most appropriate API for its needs.

The API gateway can also implement security, such as verifying that a client is authorized to make a request.

Example

Netflix API Gateway

Results

Using API gateways has the following benefits:

    • Hides to the client how the app is partitioned into microservices

    • Provide optimal API to each client

    • The logic of invoking a large number of services is transferred to the API Gateway, thus simplifying the client

    • Reduced number of requests/round trips. For example, the API enables clients to pull data from multiple services in a single request. Fewer requests, less overhead, and therefore improved user experience. API gateways are essential for mobile applications.

The API Gateway pattern also has some drawbacks:

    • Increased complexity-the API gateway itself is also a part that needs to be developed, deployed, and managed.

    • Increased response time because the API gateway is a network hop-but, for the vast majority of applications, the overhead of a single round trip is not obvious.

Problem:

    • How do I implement an API gateway? The event-driven/reactive (reactive) method is best if it is to scale to handle high loads. On the JVM, NIO-based libraries such as Netty, Spring reactor are also available. Nodejs is another option.

Related patterns

The MicroServices model provides the need for this pattern.

Known users
    • Netflix API Gateway

Change

Undecided


First: Integrated architecture (Monolithic Architecture)

Second: micro-service Architecture (MicroServices architecure)

Third:API gateways (API Gateway)

Translation API gateways (API Gateway)

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.