serverless-operations / serverless-step-functions

AWS Step Functions plugin for Serverless Framework ⚡️
Other
1.02k stars 204 forks source link

micro-service orchestration through AWS step functions for sync communication between micro-services #397

Open s1mrankaur opened 3 years ago

s1mrankaur commented 3 years ago

I am following the AWS recommended tutorial for microservices in a multi-tenant serverless system as in the picture below. At places where microservices need to call other microservices synchronously, I would like to have an orchestration service implemented through AWS Step functions.

https://imgur.com/jZdNuSJ

I am looking at the concept of orchestration service for the first time and could not find any examples for my use case i.e building an orchestration service through AWS step functions that can call other microservices thus keep them loosely coupled. Can someone please point me to the right resource?

We are using Serverless framework.

For example: In the above particular example, In the tenant registration service,

  1. We first need to check if the tenant already exists in DDB A linked to the tenant management service
  2. If it does not, hit the user management service
  3. Once we have the response from the user management service, store the tenant in the DDBA linked to the tenant management service. What should it look like for an orchestration service that has this workflow?
theburningmonk commented 3 years ago

@s1mrankaur I'm not really sure what you're asking here... are you asking how to define a state machine that does this workflow? If you need help getting started with Step Functions then maybe have a look at the tutorials here, or check out my video course on Step Functions here

s1mrankaur commented 3 years ago

@theburningmonk I intend to have an orchestration microservice that is used to ensure microserviceA is not directly calling microserviceB when need to have synchronous communication to ensure loose coupling between them. My understanding is that AWS Step functions can be used to write this service that calls other services.

I would like to see an example where step functions are users in an orchestration service for facilitation communication between microservices.

theburningmonk commented 3 years ago

Sure, you'd have two Task states, one for calling microservice A and then another calling microservice B.

And if both microservices are running on API gateway then you can even use the new API Gateway integration to call them from the Task state, otherwise, you'll need a Lambda function to make the API calls to those microservices.

If you use the links I shared and learn about the basics of Step Functions then it should be apparent how this can work.

Another thing to consider is that, if this registration workflow has to run A Lot, then it might be worth using an Express Workflow instead for cost reasons.

s1mrankaur commented 3 years ago

@theburningmonk Thanks for your response. If an endpoint in "Tenant registration" service needs to call "Tenant management service" and "User management service", do we define a step function in "orchestration service" to call l "Tenant management service" and "User management service" and return to "Tenant registration" service? I did try looking but haven't found a similar example. may be I am not understanding it right.