Sending Async Fan-Out Messages Using the Serverless Framework
Description
When designing microservices, one of the most important things to avoid is the bottleneck. One of the most known parts that could cause a bottleneck is the synchronous communications between two different parts. Because of that, designing a microservice that communicates in an asynchronous way could be a winning choice. To do so, you should consider using middleware components such as topics and queues. If you need to send trigger multiple asynchronous parts and don't want to write code for each single invocation, you can consider the fan out pattern. The fan out pattern implements a single topic that will push each received message to multiple queues. That way, by only sending a single message from your code, it will be sent into multiple queues, so multiple functions will be invoked asynchronously.
The Serverless Framework allows you to easily define the resources of an asynchronous microservice, define the triggers (in that case a trigger could be a message in a queue or a message sent to a topic), and define the middleware components that are essential for realizing the asynchronous communication.
In this lab, you will leverage the Serverless Framework to create three serverless functions: one will be invoked synchronously by the user, the other two will be invoked asynchronously from the first one. You will use the Serverless Framework to create the two SQS queues (one for the second function, and the other one for the third function), and an SNS topic where the first function will send the messages to. This topic will realize the fan out pattern by pushing each received message to the two SQS queues.
Learning Objectives
Upon completion of this lab you will be able to:
- Build and deploy serverless functions and resources using the Serverless Framework
- Realize an asynchronous communication between different functions following the fan out pattern
Intended Audience
This lab is intended for:
- Software engineers mainly focused on serverless development
- Solutions architects that need to build asynchronous microservices
Prerequisites
To get the most from this lab, you should have basic knowledge of the Serverless Framework, SNS, and SQS. To get ready, you can use the following labs: