Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should an API Gateway Communicate via a Queue or directly to other μServices?

I was wondering which of my two methods is more appropriate, or is there event another one?

(1) Direct

direct communication Direct communication between GATEWAY and μSERVICE A

  1. UI sends HTTP request to GATEWAY
  2. GATEWAY sends HTTP request to μSERVICE A
  3. μSERVICE A returns either SUCCESS or ERROR
  4. Event is stored in EVENT STORE and published to QUEUE
  5. PROJECTION DATABASE is updated
  6. Other μSERVICES might consume event

(2) Events

queue communication Event-based communication via a message queue

  1. UI sends HTTP request to GATEWAY
  2. GATEWAY published event to QUEUE
  3. μSERVICE A consumes event
  4. Event is stored in EVENT STORE and published to QUEUE
  5. PROJECTION DATABASE is updated
  6. Other μSERVICES might consume event
  7. GATEWAY consumes event and sends response (SUCCESS or ERROR) to UI

I am really sorry if I misunderstood some concept, I am relatively new to this style of architecture.

Thanks in advance for every help! :)

like image 921
Flo Avatar asked Jun 16 '19 20:06

Flo


People also ask

How does API gateway communicate with microservices?

The API Gateway offers a reverse proxy to redirect or route requests (layer 7 routing, usually HTTP requests) to the endpoints of the internal microservices. The gateway provides a single endpoint or URL for the client apps and then internally maps the requests to a group of internal microservices.

Should microservices communicate through a gateway?

Internal microservices benefit from using different communication protocols by using API gateway. An API gateway can provide a unified REST-based API for various protocols to choose the best internal architecture for the applications.

How does an API gateway work?

An API gateway is an API management tool that sits between a client and a collection of backend services. An API gateway acts as a reverse proxy to accept all application programming interface (API) calls, aggregate the various services required to fulfill them, and return the appropriate result.

Which API Gateway is best for microservices?

Kong Gateway is a highly scalable, open source API gateway optimized for microservices and distributed architectures. Kong built the gateway on top of top of the NGINX web server, and governs it using the Apache 2.0 license.


1 Answers

Second approach is a preferred way and is async approach.

Direct

In first approach your microsvc B and C wait for the event to get published . The scalability of this system is directly dependent on microsvc A. what if microsvc A is down or falling behind writing events to queue? it's like single point of failure and bottleneck. you can't scale system easily.

Events

In microservices we keep system async so they can scale. Gateway should be writing to the queue using pub/sub and all these microservices can use events at same time. system over all is more robust and can be scaled.

like image 152
Imran Arshad Avatar answered Jan 04 '23 06:01

Imran Arshad