An overview of the

  • preface
  • What is API Gateway
  • Why use API Gateway
  • Afterword.

preface

At first, feel bad I also describe what API gateway, looking at the article (microservices. IO/patterns/ap… If my article is helpful to you, welcome to pay attention to, like, forward, so THAT I will be more motivated to do original sharing.

What is API Gateway

The API Gateway stands between the client and the microservices and acts as a reverse proxy, routing different requests to the corresponding microservices. At the same time, it has the following functions: security, limiting, caching, logging, monitoring, retry, fuse and so on.

Why use API Gateway

First of all, let’s think boldly. You are the CTO of a company, and your company’s product is to make a book selling product similar to “Ding Ding Dang”. Your product might have three ends:

  • The web version
  • Android/iOS client
  • Of course, if your product is big enough, you’ll need to open up some REST APIS for third party calls. Now let’s discuss some features of the product:
  • Login registration (login registration, access to basic user information)
  • Price service (record price, double eleven special price, second price, coupon price, etc.)
  • Product services (product information, name, unit price, picture display)
  • Inventory service (recording product inventory)
  • Evaluation service (customer evaluation and discussion area after purchase)
  • Third party open interface (e.g. Wechat open platform, interface provided to third call)

So the question is: The question is: Here we go:

  • The client interacts with many micro-services, and the protocols are not unified. Some protocols are unfriendly to the client.
  • Data is not unified, and it may be necessary to assemble the data of multiple microservices in one operation, so that we can request the data we want at one time.
  • The IP address and port of the microservice are changed, but the client cannot detect the change.
  • Different terminals need different data. The mobile terminal may only solve the problem with JSON data, while the web terminal may need more data display.
  • As for authentication, many micro-services, does each micro-service have a set of authentication system independently?

Using API Gateway, many problems can be solved:

  • Each microservice first interacts with the API Gateway and is converted into a client-friendly REST API.
  • The data is assembled in the API Gateway and returned to the client.
  • Modifying the IP address and port in the API Gateway The client is not aware of the change and works normally.
  • Multiple API gateways are used, and different API gateways respond to different data to different terminals.
  • Unified authentication in the API Gateway, save redundant code.

After such modification, many problems are solved, the client is unaware of many micro services.

Afterword.

True microservices architecture is much more than that, service registration, service discovery, and so on. This is just going to take you through the door, and it’s going to take you through the door. I’m glad you’re here to learn more about microservices. Personal knowledge reserve is always limited, if there is a mistake, also ask the big guy to correct. Click to read the original article and link to my Zhihu, where I will correct the mistakes in the article.

This article was first published in the public account “zone7”, pay attention to the public account to get the latest tweets, background reply [xiaobai micro service] to get the source code.