How to inspect request responses and make complex routing decisions between applications and third party endpoint

0

I have two boxes let's say box A and Box B. Both has seperate service applications with its own dbs. Both boxes should expected to do calls with third-party legacy endpoint via (webhooks/websocket /rest) which cannot be changed in anyway.

When a box A initiate or receive (webhooks/rest/websocket) request to or from 3rd party endpoint relative response should arrive in Box A

same applies to Box B how to achieve this using AWS.

Ideally If there is a way we could look at requests and responses and compare it to the data in database then make decision on which box to send the response from third party then problem is solved But not sure how we should go about it with aws

3 Answers
0
Accepted Answer

Hi rePost-User-9416263,

Could you please confirm if I understand the problem statement correctly ? I took an example of the retrieve customer information flow, for better understanding of the scenario.

Scenario :

  1. There is a LEGACY APPLICATION deployed on one EC2 instance with a dedicated LEGACY CUSTOMER DATABASE.
  2. There is a MODERNZED NEW APPLICATION on another EC2 instance with a dedicated MIGRATED CUSTOMER DATABASE.
  3. Each of these EC2 instances are behind AWS Application Load Balancer (ALB).
  4. Consumer applications makes call to AWS ALB to retrieve customer information based on the customer number.
  5. If the customer number exists in the MIGRATED CUSTOMER DATABASE, then ALB should route the call to MODERNZED NEW APPLICATION.
  6. If the customer number exists in LEGACY CUSTOMER DATABASE, ALB should route the call to LEGACY APPLICATION.

Problem Statement:

  1. The information about legacy/migrated customer numbers is in the respective databases of the legacy / modernized applications.
  2. How will ALB know, if the customer number is migrated or not ?
  3. How will ALB decide, whether to route the call to new modernized application OR to old legacy application.

Content Based Routing To Legacy / Migrated Application Using Stored Business Data

Regards, Prince Arora

profile picture
answered 9 months ago
  • So a webhook event will be an asynchronous response from the third party. Below can be a possible solution for this asynchronous communication:

    1. While sending the request from Box (A or B) to 3rd party

      • retrieve a unique identifier from the request and store this identifier (correlation id) and source BOX hostname in a new mapping table in DB.
    2. When the response is received from the 3rd party application to AWS ALB:

      • the response should have the correlation id uniquely identifying the request for which this response is sent.
    3. For all incoming events from external party:

      • ALB will invoke a lambda function.
      • This lambda function will retrieve the correlation id from the response event.
      • The lambda function will query the mapping table and retrieve the box hostname corresponding to the correlation id received in the response.
      • The lambda function returns the hostname to ALB. ALB will have the rules configured to route the response based on the hostname of the EC2 instance.

    Hope this helps.

    Cheers! Prince Arora

0

Hi prince thanks for your reply.

box A and Box B are ec2s in ourside we have full control over them. Both A and B has seperate applications with its own dbs. Both boxes should expected to do calls with third-party legacy endpoint via (webhooks/websocket /rest). This third party endpoint is hosted by different company don't know anything about it's hosting environment or we don't have any access to that third party API. We just could call it via dedicated IP address or it could call us via webhooks That's about it

Problem we face is when we receive a response from third party API how do we send it to Box A or Box B. Only way we could think of is storing body data of the request in DB and when response comes back checking to understand where response should go. But how do we redirect reroute responses, how do we check this response against db on the fly is what we are trying to figure out

answered 9 months ago
  • Hi,

    The third party application is a rest API call. Isn't it a synchronous API ? If the 3rd party rest api call is triggered from Box A the response will be received by box A, if its a sync API. similarly if it is initiated from Box B, the response will be back to box B. Am I missing something ?

  • It has three types rest API, webhooks and websockets. So like you said if it's REST it's all good as the calls are synchronised but if it's webhook where third party calling with data we don't know how to redirect to the relevant box. It could be something to do with data that should go to A or Box B. That case we need to find by querying db where should this go

0

Without further detail, I would suggest you take a look at EventBridge and StepFunctions to see what fits best.

With StepFunctions you can create a workflow that helps you manage calls to third parties and receive calls or responses and route it as needed. In Serverless Land you can find workflow examples that can accelerate you.

With EventBridge, you can think with Event-Driven in mind and create rules to route events as desired.

Perhaps you would need to persist some information about calls to use for routing as responses are received, DynamoDB might be good for this.

Both approaches are different and sometimes they are better together.

profile pictureAWS
answered 9 months ago
profile picture
EXPERT
reviewed 9 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions