11

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! :)

Florian Ludewig
  • 4,338
  • 11
  • 71
  • 137

1 Answers1

7

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.

Imran Arshad
  • 3,794
  • 2
  • 22
  • 27
  • Great, thank you! One more question: When UI makes e. g. a post request, does the gateway wait and later return the HTTP response to the UI (success or error)? – Florian Ludewig Jun 17 '19 at 04:46
  • 1
    That's right . Gateway will be the entry and exit point for your request/Response. You can even aggregate response from different services at gateway. It normally also works for auth/authorization . Make sure gateway is highly available. It can be a bottleneck since if it goes down user can't reach any of your backend services. – Imran Arshad Jun 17 '19 at 04:52
  • It would be a pleasure if you could check out this question: https://stackoverflow.com/q/56654068/8586803 – Florian Ludewig Jun 18 '19 at 17:39