Zero-to-Hero with Serverless in 4 weeks —workshop by Yan Cui (Ads)
Join 20+ AWS Heroes & Community Builders and 1000+ happy students in leveling up your serverless game & becoming the serverless expert in your company. The workshop is taught by Yan Cui, AWS Serverless Hero and Consultant.
Last week, we talked about how containers work under the hood. Our next containers series #3 is on its way and it’s all about how docker works, multi-stage docker builds, and a demo of dockerizing React Application. Stay tuned.
This week, we are going to talk about Serverless on AWS. We are going to discuss the common serverless architecture patterns, benefits, use cases, and some best practices.
Before we start, let’s play an AWS quiz:
Introduction to Serverless
When was the last time you ssh into a server? Did some system updates and so on. And did your server always maintain uptime? Are you worried about the traffic spikes?
In serverless, you don’t have to think about the operational overhead, everything is done by vendors. It scales automatically based on your needs and you pay based on what you use.
Serverless came into popularity when AWS launched Lambda back in 2014 and most popular companies like Netflix started adopting it. It completely abstracted away the compute and developers didn’t have to think about the servers anymore.
Use Cases
Microservices Architecture: Easily deploy independent, small services that can scale individually.
Data Processing: Efficiently process and transform large datasets with services like AWS Lambda.
Real-Time File Processing: Automatically handle file uploads and processing with services like Amazon S3 and Lambda Functions.
Web and Mobile Backends: Develop backends for web and mobile applications with AWS API Gateway and AWS Lambda Functions.
By utilizing serverless architecture, organizations can benefit from reduced complexity, improved scalability, and cost savings, while enabling developers to innovate faster and deliver better products.
Common Serverless Architecture Patterns on AWS
Here are some common serverless patterns on AWS. These are the simple common patterns. By integrating these services we can handle much more complex logic.
Amazon API Gateway + Lambda: This pattern is used to build serverless APIs. API Gateway acts as the entry point for API requests, which then triggers a Lambda function to process the request and return a response.
Amazon S3 + AWS Lambda: This pattern is often used for data processing or event-driven scenarios. When an object is uploaded to an S3 bucket, it can trigger a Lambda function to perform operations on the object, such as data transformation, image resizing, or video transcoding.
Step Functions + Lambda: Step Functions is a serverless function orchestrator that allows you to sequence multiple Lambda functions into a workflow. This pattern is useful for building complex, long-running workflows with branching logic and error handling.
DynamoDB + Lambda: DynamoDB is a serverless NoSQL database. It seamlessly integrates with Lambda. It can trigger a Lambda function when data is inserted, updated, or deleted. This pattern is useful for building event-driven architectures or implementing serverless data processing pipelines.
EventBridge + Lambda: EventBridge is a serverless event bus that can route events from various AWS services (or custom applications) to Lambda functions. This pattern is useful for building event-driven architectures or implementing serverless workflows triggered by specific events.
Kinesis + Lambda: Kinesis is a serverless data streaming service that can trigger Lambda functions to process real-time data streams. This pattern is useful for building data processing pipelines, real-time analytics, or event-driven architectures.
SQS + Lambda: SQS is a serverless message queueing service that can trigger Lambda functions to process messages from the queue. This pattern is useful for building asynchronous processing systems, decoupling components, or implementing serverless workers.
API Gateway + Lambda + Step Functions: This pattern combines API Gateway, Lambda, and Step Functions to build complex, long-running serverless workflows triggered by API requests.
These patterns can be combined and extended to build more sophisticated serverless architectures on AWS. The choice of pattern depends on the specific requirements of the application, such as performance, scalability, and cost optimization.
AWS Serverless Offerings
Some of the most popular AWS Serverless services:
AWS Lambda—Serverless Compute Service
AWS API Gateway—for creating, publishing, maintaining, monitoring, and securing REST, HTTP, and WebSocket APIs at any scale.
AWS AppSync—Serverless GraphQL and Pub/Sub APIs
Amazon DynamoDB—Serverless No-SQL key-value database, built for massive scale.
Amazon EventBridge—Serverless Event Bus and Pipes for EDA.
Amazon S3—Store any kind of object data(Images, pdf, etc)
AWS Step Function—Orchestration for AWS Lambda
Amazon SQS—Queuing service
Amazon SNS—Notification service
AWS Fargate—Run Serverless containers on AWS
And some few other
Benefits of Serverless Computing
It offers a range of benefits that can significantly improve the development, deployment, and operation of applications. Here are some key advantages of using serverless architecture:
1. No Server Management
- Eliminates the need to provision, manage, and maintain servers.
- Allows developers to focus on writing code and developing features instead of managing infrastructure.
2. Automatic Scaling
- Automatically scales up and down based on demand.
- Ensures applications can handle varying loads without manual intervention, from zero to thousands of requests per second.
3. Cost Efficiency
- Pay only for the compute resources you use.
- Reduces costs as there are no charges for idle resources; billing is based on the actual execution time of the code.
4. Improved Developer Productivity
- Simplifies deployment and management, allowing for rapid development cycles.
- Speeds up the development process, enabling faster time-to-market and more frequent updates.
5. High Availability and Fault Tolerance
- Built-in high availability and automatic fault tolerance.
- Enhances reliability and uptime without extra configuration or management, ensuring applications are resilient to failures.
6. Event-Driven Execution
- Functions are triggered by various events such as HTTP requests, database updates, file uploads, etc.
- Facilitates the creation of responsive and interactive applications that react to real-time events.
7. Global Reach
- Easily deploy functions across multiple regions.
- Enables low-latency responses and high availability for users around the globe.
8. Built-in Integration with Other Services
- Seamless integration with a wide range of cloud services (databases, queues, storage, etc.).
- Simplifies the architecture and development of complex applications by leveraging managed services.
Tools to build Serverless on AWS
Here are some of the tools I use:
AWS SAM—Open-sourced Serverless Framework to build on AWS
AWS CDK—IaC tools with the power of programming languages
Serverless Framework
AWS Powertools—developer toolkit to implement Serverless best practices and increase developer velocity
Some Best Practices
Here are the top 5 best practices for serverless computing on AWS:
1. Embrace Serverless Mindset
Serverless computing requires a shift in mindset from traditional server-based architectures. Embrace the serverless model by designing your applications as a set of independent, stateless functions that can be easily scaled and composed together.
2. Right-Size Your Functions
Keep your Lambda functions small, focused, and stateless. Avoid monolithic functions and instead break down your application logic into smaller, reusable functions. This promotes better modularity, testability, and cost efficiency.
3. Optimize for Cost
Serverless architectures on AWS are generally cost-effective, but it's essential to optimize your resource usage and leverage best practices for cost optimization. This includes setting appropriate memory configurations, using provisioned concurrency for latency-sensitive workloads, and taking advantage of AWS Lambda's pricing model based on execution duration.
4. Leverage Event-Driven Architecture
Serverless computing on AWS is well-suited for event-driven architectures. Use services like Amazon EventBridge, Amazon Simple Queue Service (SQS), and Amazon Simple Notification Service (SNS) to decouple your application components and build reactive, scalable systems.
5. Implement Robust Observability and Monitoring
Serverless applications can be challenging to monitor and debug due to their distributed nature and ephemeral execution environments. Implement robust observability practices, such as centralized logging with Amazon CloudWatch Logs, distributed tracing with AWS X-Ray, and monitoring with Amazon CloudWatch metrics and alarms.
Use Infrastructure as Code (IaC)
Leverage IaC tools like AWS CloudFormation or AWS Serverless Application Model (SAM) to define and manage your serverless resources in a consistent and repeatable manner.
Implement Security Best Practices
Follow security best practices, such as using AWS Identity and Access Management (IAM) roles, encrypting data at rest and in transit, and implementing secure communication between components.
Automate Deployments and Testing
Implement continuous integration and continuous delivery (CI/CD) pipelines to automate the deployment and testing of your serverless applications, ensuring consistent and reliable deployments.
Leverage Caching Strategies
Implement caching strategies, such as using Amazon API Gateway caching or Amazon ElastiCache, to improve performance and reduce costs for frequently accessed data.
Design for Failure and Resiliency
Serverless applications should be designed to be fault-tolerant and resilient. Implement retry mechanisms, dead-letter queues, and circuit breakers to handle failures gracefully.
By following these best practices, you can build scalable, cost-effective, and reliable serverless applications on AWS.
Final Thoughts
At last, Serverless is cool. I love building things serverless. I have been learning it for many years now. One thing I like about building serverless on AWS is that it doesn’t cost much when you are prototyping initially. The cost is very low until you have millions of users. And the AWS free tiers are generous.
Thanks for reading. Over to you, how are you leveraging serverless in your company? I would love to hear in the comments.
Hey @Kisan Tamang, Nice explanation and valuable content!
I tried to write a few concepts in AWS and compared similar ones. You can refer to the following:
https://dotnet-fullstack-dev.blogspot.com/2024/10/Picking-the-Right-Tool-for-the-Job-Redshift-vs-DynamoDB-S3-vs-EFS.html
Feel free to add your thoughts on it.