1

This is a system design question about creating a messaging application (like WhatsApp or FB messenger).

I saw a video that had the users connected via websocket to the API Gateway , then API GW pushed the message onto SQS - which was then polled by the EC2 compute layer to process the message (store it in the db) and hopefully send the message back to recipient.

How can the backend ec2 / compute layer send the message to the recipient (Bob) ? Can it just call a route on the API Gateway and it would know the connection details of the recipient and where to send? Would there need to be an additional caching layer to store info about the connection details of every user? I'm newer to AWS so not sure how this is accomplished and whether you can call API GW to send back to a user.

Also if you know how group chat would work please share.

enter image description here

Ryan
  • 449
  • 5
  • 21

1 Answers1

1

As mentioned in the documentation, your backend EC2 servers can send messages to the connected clients directly via the @connections API. This documentation page walks you through how to do that.

For this, you'll need to add the connectionId to the header. See this answer on how to do so.

Paolo
  • 21,270
  • 6
  • 38
  • 69
  • Thank you - it looks like there is just a connection ID that needs to be forwarded from the API GW to SQS when message is being sent to backend. Can API GW add this connection ID so the backend can use it? – Ryan Jun 26 '22 at 17:21
  • @Ryan Can you confirm which integration type you are using? – Paolo Jun 26 '22 at 17:46
  • Would adding a connectionId to the header be a separate lambda or can API GW do that? For integration types - what are the options ? I was thinking just a POST method to SQS can be setup when configuring the API GW Also do you know how group messages might work? We would just be passing along multiple connection ID's instead of one I guess? – Ryan Jun 26 '22 at 19:09
  • 1
    Oh I see API GW can forward the connection ID - that answers one of the questions. – Ryan Jun 26 '22 at 19:31