hands-on lab

Sending Async Fan-Out Messages Using the Serverless Framework

Up to 1h 15m
Get guided in a real environmentPractice with a step-by-step scenario in a real, provisioned environment.
Learn and validateUse validations to check your solutions every step of the way.
See resultsTrack your knowledge and monitor your progress.


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


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:

Environment before

Environment after

About the author

Learning paths

Stefano studies Computer Science and is passionate about technology. He loves working with Cloud services and learning all the best practices for them. Google Cloud Platform and Amazon Web Services are the cloud providers he prefers. He is a Google Cloud Certified Associate Cloud Engineer. Node.js is the programming language he always uses to code. When he's not involved in studying or working, Stefano loves riding his motorbike and exploring new places.

Covered topics

Lab steps

Understanding the Structure of the Fan Out Pattern
Initializing a Project Using the Serverless Framework
Building and Deploying a Decoupled Microservice With the Serverless Framework
Testing the Asynchronous Microservice