Dive deep into serverless system design: event-driven, NoSQL, decouple, real-world practice
Published: 2024-04-22 15:09:56

# Introduction of serverless

<br/> &nbsp;
## What is serverless?

- Serverless uses cloud services without servers to manage.
- Developers focus on code without worrying about infrastructure.
- Scales are automatically based on events like API calls.
- Pay only for resources used instead of always-on servers.
- Uses compute services like AWS Lambda for building apps.
- Apps built from independent functions that run on-demand.
- Well-suited for APIs, microservices, and event-driven architectures.
- Removes server management overhead and reduces costs.

[serverless-computing](https://aws.amazon.com/what-is/serverless-computing/)
[CHAP_Serverless](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Serverless.html)
[serverless-next-steps](https://docs.aws.amazon.com/serverless/latest/devguide/serverless-next-steps.html)


<br/> &nbsp;
## What is event-driven design?

- Events trigger code execution instead of direct calls.
- Independent services communicate through event messages.
- Events are generated when the application state changes.
- Services subscribe to relevant events asynchronously.
- Events decouple services for independent development.
- Microservices process single events without coordination.
- Event brokers distribute events to multiple consumers.
- Services are scaled independently based on event load.
- Fault tolerance through duplicate event processing.

[event-driven-benefits](https://docs.aws.amazon.com/lambda/latest/operatorguide/event-driven-benefits.html)


<br/> &nbsp;
## What is a serverless microservice?
<u>software architecture:</u>
collection of small, independent, and loosely coupled services
<u>Serverless microservice: </u>
Decentralized architecture with minimal infrastructure management.
<u>No dedicated servers: </u>
Services run on ephemeral computing resources.
<u>Event-driven: </u>
Triggered by specific events or requests from other services.
<u>Scalability: </u>
Automatically scales based on demand, reducing operational complexity.
<u>Pay-per-use: </u>
Billed for actual resource consumption rather than fixed capacity.
<u>Stateless: </u>
Services don't maintain a session state, promoting scalability and fault tolerance.
<u>Third-party services: </u>
Use managed services for databases, storage, and authentication.
<u>Rapid development: </u>
Focus on coding business logic rather than infrastructure.
<u>Fault tolerance: </u>
Resilient to failures through redundancy and distributed design.
<u>Increased agility: </u>
Enables faster deployment and iteration of individual microservices.


<br/> &nbsp;
## The underlying mechanism of AWS Lambda

- Lambda runs code on virtual machines called Workers.
- Workers are isolated AWS accounts using EC2 instances.
- Firecracker creates secure containers for functions.
- Functions run in containers on Workers.
- Lambda scales Workers automatically for the load.
- Workers have short lifetimes for security.
- Lambda assumes execution roles to run functions.
- Functions have isolated environments and storage.
- The data plane uses encryption for communication.

<br/> &nbsp;
## The underlying mechanism of lambda running

- Lambda runs code in response to events like HTTP requests.
- Code runs in ephemeral containers on virtual machines.
- Containers managed by AWS on computing optimized for serverless.
- Lambda scales automatically based on incoming events.
- Pay only when resources are used, not for idle computing capacity.
- Code runs in isolated environments without servers to manage.
- Events trigger code without worrying about provisioning.
- AWS handles all infrastructure management for developers.
- Lambda invokes code asynchronously and parallelizes executions.

<br/> &nbsp;
## The Underlying step of running lambda

1. Configure trigger event for function code execution.
2. Upload function code to Lambda.
3. Assign execution role for Lambda to access resources.
4. Lambda scales automatically based on event traffic.
5. Lambda runs code in a containerized environment.
6. Code handled and executed by AWS Lambda service.
7. Lambda invokes code in response to a configured trigger.
8. Logs and metrics were sent to CloudWatch for monitoring.
9. Lambda bills only for compute duration used.
10. Automatic management of computing resources by AWS.

[welcome](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)
[level-abstraction](https://docs.aws.amazon.com/lambda/latest/operatorguide/level-abstraction.html)
[getting-started](https://docs.aws.amazon.com/lambda/latest/dg/getting-started.html)
[lambda-foundation](https://docs.aws.amazon.com/lambda/latest/dg/lambda-foundation.html)


<br/> &nbsp;
## What is an API gateway?

- Manages access to APIs and services.
- Acts as a front door for applications.
- Routes requests to appropriate backends.
- Handles traffic management and security.
- Scales automatically for performance.
- Enforces usage plans and quotas.
- Integrates APIs and microservices.
- Monitors APIs for observability.
- Manages versions and deployments.

[welcome](https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html)

<br/> &nbsp;
## System design - 
single service lambda with API gateway (merchant to merchant)

<br/> &nbsp;
## 

<br/> &nbsp;
## 

<br/> &nbsp;
## 

<br/> &nbsp;
## 

<br/> &nbsp;
## 

<br/> &nbsp;
## 

<br/> &nbsp;
## 

<br/> &nbsp;
##