AWS Event-driven Serverless Microservices using AWS Lambda, API Gateway, EventBridge, SQS, DynamoDB and CDK for IaC

In this article, we will learn AWS Serverless Event-driven Microservices with using AWS Lambda, AWS DynamoDB, AWS API Gateway, AWS EventBridge, AWS SQS which stands for Simple Queue Service, AWS CDK stands for Cloud Development Kit for IaC — Infrastructure as Code tool and AWS CloudWatch for monitoring.

Serverless Event-driven E-commerce Microservices Architecture

We will be following the Reference Architecture above which is a real-world Serverless E-commerce application and it includes;

  • REST API and CRUD endpoints with using AWS Lambda, API Gateway
  • Data persistence with using AWS DynamoDB
  • Decouple microservices with events using AWS EventBridge
  • Message Queues for cross-service communication using AWS SQS
  • Cloud stack development with IaC using AWS CloudFormation CDK

By the end of the article, you will learn how to develop reliable and scalable Serverless applications, following the microservices architecture. We will develop Event-driven Microservices with AWS Serverless services which comes with power of cloud high availability and high scalability by nature. Of course we will follow the Serverless Design Patterns and Best Practices when designing our E-commerce Event-driven Microservices application.

Step by Step Design AWS Architectures w/ Course

I have just published a new course — AWS Serverless Microservices with Patterns & Best Practices.

In this course, we’re going to learn how to Design and Develop AWS Serverless Event-driven Microservices with using AWS Lambda, AWS DynamoDB, AWS API Gateway, AWS EventBridge, AWS SQS, AWS CDK for IaCInfrastructure as Code tool and AWS CloudWatch for monitoring.

Source Code

Get the Source Code from Serverless Microservices GitHub — Clone or fork this repository, if you like don’t forget the star. If you find or ask anything you can directly open issue on repository.

AWS Serverless Microservices for Ecommerce Application Architecture

Here you can find the main overall Serverless Architecture for our application. This is the big picture of what we are going to develop together for AWS Serverless Event-driven E-commerce Microservices application that is Step by Step Implementation together.

Serverless Event-driven E-commerce Microservices Architecture

We have several microservices and integration components;

Product Microservices is basically implementing RESTful Microservices with using AWS Lambda, API Gateway and DynamoDB for performing CRUD operations.

Basket Microservices is implementing RESTful Microservices like Product microservices. But also Basket Microservices creates and trigger Checkout Basket event to the Amazon EventBridge for Event-Driven asynchronous Communication between Microservices in order to Decoupling Basket and Ordering Microservices.

After that Amazon EventBridge publish Checkout event to the AWS SQS and this SQS queue messages receive from Ordering microservices in order to processing events asynchronously using queues.

Ordering Microservice also expose RESTful APIs for querying Order tables.

And all these Serverless E-commerce application infrastructure developed with using AWS CDK. This architecture will be 100% hands-on, and we will be develop all infrastructure and microservice codes with together and step by step.

So there are a couple of microservices which implemented e-commerce modules over Product, Basket and Ordering microservices.
We will use AWS Lambda service as a microservices and use power of lambda functions. And this microservice’s databases will store NoSQL AWS DynamoDB databases.

And also we have followed communication patterns and best practices
when designing Serverless microservice communications.
For synchronous and asynchronous communications with using AWS API Gateway, AWS EventBridge as a Eventbus and AWS SQS as a queue service.

We will use

  • AWS API Gateway -for- Restful API-Driven Development and Synchronous Event Sources
  • AWS EventBridge -for- Event-Driven Asynchronous Communication between Microservices
  • AWS SQS -for- Decouple Microservices and processing events asynchronously using queues

That means we design our architecture rely on asynchronous connections that gives us much more flexible and resilient application.

Serverless E-Commerce Application Architecture

The application proposes a microservice oriented architecture implementation with AWS Serverless world using Event-driven patterns and best practices. So the project will be the E-commerce application that will be totally serverless components.

Serverless Event-driven E-commerce Microservices Architecture

Let me try to introduce Serverless components one by one;

Api Gateway

This is entry point of our microservices. API Gateway provides Restful API-Driven Development and Synchronous Event Sources. Synchronous commands are request/response. API Gateway is a synchronous event source and provides a serverless API proxy to Lambda. API Gateway Redirects to CRUD request to internal microservices.

Product Lambda Microservices

It performs CRUD operations using DynamoDB table over the AWS API Gateway. This will cover product table operations fully Serverless in microservices architecture. Synchronous requests will manage by AWS API Gateway and routing requests to Product Lambda Microservices that perform CRUD operations.

We will develop Lambda functions with using AWS SDK for interacting other AWS resources for example in Product case we will interact with AWS Serverless DynamoDB to perform all crud operations.

Basket Lambda Microservices

It performs Add-Remove synchronous basket operations with using AWS API Gateway and DynamoDB. Again Synchronous requests will manage by AWS API Gateway and routing requests to Basket Lambda Microservices that perform CRUD operations.

We will write Lambda functions with using AWS SDK for interacting other AWS resources for example in Basket case we interact with AWS Serverless DynamoDB to perform all crud operations.

But also, Basket microservice triggers to event-driven use case which is the checkout basket. When checkout basket, this will publish and create event to Serverless Eventbus which is Amazon EventBridge.

So this asynchronous communication will held by Basket Lambda Microservice and Amazon EventBridge and consumed by Ordering microservices over the AWS SQS.

AWS Event Bridge

So asynchronous communication held by AWS Serverless Eventbus service which is Amazon EventBridge. We will create Rules and Target definitions for Amazon EventBridge from Basket Lambda microservices.
That means we will develop Basket Lambda Microservices when publishing checkout message to Amazon EventBridge with using AWS SDK for development purpose.

AWS SQS and Ordering Lambda Microservices

So after publishing checkout event to the EventBridge, this event will consume by Ordering part. EventBridge send to event to AWS SQS in order to gain power of AWS SQS queue.

After that Ordering lambda microservice will consume this event with polling. That means we will use event source mapping communication type here when consuming events, ordering lambda microservices send polling request and get event from the AWS queue.

After consuming the event from the AWS Queue, Ordering lambda microservices process the event with creating order record into its DynamoDB table.
Ordering lambda microservices perform all these operations with developing lambda functions with using AWS SDK. So we will develop together and step by step.

Microservices Communications with AWS Lambda Invocation Types

We have 3 communication types;

Serverless Event-driven E-commerce Microservices Invocation Types

1- Synchronous Communication with AWS API Gateway for routing request from client applications to downstream microservices.
2- Asynchronous Communication with AWS Serverless Eventbus which is EventBridge for applying Event Driven asynchronous Communication patterns.
3- And lastly we have Event Source Mapping Communication when polling queue records from lambda services to AWS SQS-Simple Queue Service for Decouple Microservice and processing events asynchronously.

When designing our application, we will follow these Microservice communication types with Lambda invocations, and develop our sections following these arrows that you can find on the above diagram.

And also we will follow devops best practices when coding infrastructure. This whole picture, we will develop infrastructure as code Serverless Stacks with using AWS CDK — Cloud Development Kit.
We will use AWS CDK for IaC Serverless Stacks developments that we will develop and provision all services step by step with together.

Taco Bell — Fully Serverless Food Delivery Company

I would like to give just 1 example from last AWS reInvent session
Here you can find real-world project.

https://www.youtube.com/watch?v=U5GZNt0iMZY

This image from the last re-Invent session, Robbie Kohler the Director of Software Engineering at Taco Bell — Food Service Delivery Company.

Taco Bell is fully Serverless food delivery company that developing on fully serverless services on AWS. And we will follow the same development steps of this kind of serverless applications when designing our architecture.

Besides that, you will get hands-on experience with most popular and useful services on the AWS Serverless landscape.

Demand for AWS jobs is continuously on the rise, as AWS holds the biggest stake amongst all cloud providers. So this application will give you practice of AWS services that you can use in real-world projects.

AWS Serverless + CDK Automation + Integration Patterns = AWSome Microservices!

https://www.youtube.com/watch?v=ttJAIQf7cTw

Last reInvent Session Gregor Hophe shared great session and as he always says;

  • AWS Serverless + CDK Automation + Integration Patterns = AWSome Microservices!

This will be the manifesto of our application. We will follow this manifesto every place of our architecture and the Serverless E-commerce application.

First one is Serverless; we have learned that AWS Serverless will be our application development framework.

Second one is AWS CDK; AWS CDK is IaC tool that we will develop whole infrastructure with typescript coding, we have seen how AWS CDK is powerful with following the IaC best practices. We can easily implement integration patterns with using “CDK Serverless Patterns with Solution Constructs”.

And last one is Integration Patterns that we will follow Queue-Chaning, Publish-Subscribe and Fan-out design patterns when developing our Serverless E-commerce application.

So when we combine all of these keywords, it becomes awsome microservices !

Within our application architecture, you’ll learn how to design and developing AWS Event-driven microservices with using Serverless patterns and best practices. You can find the final application in GitHub at the repository below.

Step by Step Design AWS Architectures w/ Course

I have just published a new course — AWS Serverless Microservices with Patterns & Best Practices.

In this course, we’re going to learn how to Design and Develop AWS Serverless Event-driven Microservices with using AWS Lambda, AWS DynamoDB, AWS API Gateway, AWS EventBridge, AWS SQS, AWS CDK for IaCInfrastructure as Code tool and AWS CloudWatch for monitoring.

Source Code

Get the Source Code from Serverless Microservices GitHub — Clone or fork this repository, if you like don’t forget the star. If you find or ask anything you can directly open issue on repository.

--

--

Mehmet Ozkaya
AWS Serverless Microservices with Patterns & Best Practices

Software Architect | Udemy Instructor | AWS Community Builder | Cloud-Native and Serverless Event-driven Microservices https://github.com/mehmetozkaya