Event-driven Serverless Microservices Design with AWS Lambda
In this article, we are going to discuss about How we can design Event-driven Serverless Microservices with AWS Lambda when developing Serverless E-Commerce application.
At the end of the article we will be design the Reference Architecture above which is a Real-world Serverless E-commerce 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 IaC — Infrastructure 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.
Event-driven Serverless Microservices Design with AWS Lambda
We will follow AWS Lambda design principles and the best practices
when developing our Lambda-based Event-driven Serverless E-commerce applications.
Event-driven architecture provides developers with increased availability, elasticity, scalability, and cost optimization. With the rise of microservices and the cloud, event-driven architecture is becoming increasingly important for developers to understand.
AWS Lambda is very good fit with event-driven architectures, because the nature of lambda executions trigger from events. Events can come lots of resources and able to trigger lambda functions.
The main purpose of AWS Lambda functions is to handle events.
An event triggering a Lambda function could be almost anything, you can see in the image, from REST API HTTP request with Amazon API Gateway, a schedule task managed by an Amazon EventBridge rule, or an Amazon S3 notification like object uploaded into bucket.
Even the simplest Lambda-based application uses at least one event. So that's why we said, AWS Lambda is very good fit for the Event-Driven Architectures. Because the fuel of AWS Lambda is events.
Event-driven architectures rely on creating events into all application state changes that are observable by other services, but the event publisher system is unaware of which consumers are subscribing that event. We call that, these are loosely coupled services.
Most Lambda-based applications use a combination of AWS services, for different requirements about Storage, API Management and integrating with other system and services. You can see image below;
In these applications, AWS Lambda is connecting between services, providing business logic to transform data that moves between services.
Also There are some design patterns in distributed architectures that we will follow when build and implement application using AWS services.
AWS Services has already implement some of distributed architectures design patterns that we can use easily without investing time to develop these patterns from scratch.
AWS Serverless Microservices with Event-Driven Lambda Invocations
So we will also follow these lambda design principles and the best practices when developing our Lambda-based event-driven serverless e-commerce applications.
We will map Event-driven Lambda Invocation Types, So AWS Lambda Invocation Types will be our Serverless Integrations when developing our Serverless e-commerce application.
If we map these Lambda Invocation Types with our microservices architecture when developing serverless e-commerce application, you can see the diagram below;
So AWS Lambda Invocation Types will be our Microservices Communications when developing our Serverless Event-driven E-commerce Microservices application.
So during the article, we will follow these Lambda Invocation types as a Microservices Communication types of our serverless e-commerce microservices project.
Lambda Invocation Types = Sync -> Async -> Event Mapping
Following Microservices Communication Types for Serverless
- Synchronous Communication
- Asynchronous Communication
- Event Source Mapping for Poling queue events
So how we can follow these invocation types into our application ?
Synchronous Communication for RESTful Microservices
Synchronous commands are request/response. In a synchronous model, the client makes a request and waits for a response. We will developed RESTful Microservices with API Gateway, Lambda Functions and DynamoDB.
We called this = RESTful Microservices
- REST API and CRUD endpoints (AWS Lambda, API Gateway)
- Data persistence (AWS DynamoDB)
AWS API Gateway -for- Restful API-Driven Development for performing CRUD operations amongst lambda and DynamoDB.
Asynchronous Communication
In an asynchronous design, the client sends a request and may get an acknowledgement that the event was received, but it doesn’t get a response that includes the results of the request.
We will use
- Amazon EventBridge -for- Event-Driven asynchronous communication between Microservices
We will develop Amazon EventBridge with Lambda Basket microservices which publish the event in asynchronous way and this will consume by Ordering queue.
Event Source Mapping for Polling Event Messages
In a polling event, consumers poll the producer for messages in batches and then process the batch before returning for a new batch of records.
We will use
- AWS SQS -for- Decouple Microservices and processing events asynchronously using queues
We will develop AWS SQS with Lambda Ordering microservices which consumes by polling the event from the Ordering queue.
As you can see that we follow Serverless Microservices with AWS Lambda Invocation Types; Following Microservices Communication Types for Serverless;
- Synchronous Communication
- Asynchronous Communication
- Event Source Mapping for Poling events
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.
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
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 IaC — Infrastructure 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.