Maximizing Efficiency and Minimizing Costs with Serverless Architecture
7 minute read
What do companies love the most? Having an infinitely scalable system that can handle thousands of users from Day 1, a team of developers that works and ships features fast, and not paying boatloads of money for infrastructure.
Leveraging your infrastructure using Serverless Architecture is possible in many cases. Let’s cover the key aspects of Serverless, its best use cases, and who should use it.
What is Serverless Architecture?
Despite its name, serverless architecture doesn't mean no servers are involved; instead, it abstracts away the complexity of server management from the developers, allowing them to focus solely on writing code to implement their application's functionality.
At its core, Serverless architecture is a cloud computing paradigm where developers build and run applications without managing the underlying infrastructure. In traditional application deployment, developers are responsible for provisioning, scaling, and maintaining servers to handle the application's workload. However, with Serverless, the cloud service provider takes care of all these tasks, making it an efficient and cost-effective approach for building scalable applications.
What are the real benefits of Serverless Architecture?
Yes, no more load balancers, clusters, autoscaling groups, server provisioning, memory issues, or the need for a dedicated DevOps team to maintain all this infrastructure.
You might be wondering: If it’s so good, why isn’t it the go-to architecture for every company?
This kind of architecture is not a one-size-fits-all solution, so you need to evaluate your use case and check if the conditions of Serverless architecture are a good fit for it.
Who should use this architecture?
If you have an already-working architecture on top of Kubernetes or a container orchestrator like ECS, you can simply migrate the whole system. Still, you can start by using some serverless microservices.
But let’s focus on the most exciting case: You are starting a new project. Should you use Serverless? Let’s figure it out in the following diagram!
You may run into a situation not covered in this diagram, but the main takeaway here is:
If processing your requests is not CPU-intensive and doesn’t take too long, go with serverless!
Let's see some practical examples with accurate pricing on top of AWS Lambda:
Suppose that you are running a Python API with the following structure:
How much would that cost?
Less than $100 per month.
Now, let’s think of another example, but this time, let’s put something in the middle:
Suppose that you are running a Python API that serves a machine learning model (mid-size):
How much would that cost?
Approximately $ 13,000 per month.
As you can see, it depends on your use case. But I can confidently say that a Kubernetes cluster handling 100 million requests per month serving the same machine learning model wouldn’t be cheap either, so even in this case, maybe Lambda would be the best way to go.
Starting your own serverless project
We are huge fans of Serverless at Taller. This architecture is compelling and makes it easier to face today's challenges. We have hundreds of microservices running on top of Serverless services like AWS Lambda, DynamoDB, SQS, and S3.
The best part? It’s very straightforward to get started.
I recommend using the Serverless framework and handling your infrastructure with it.
Going back to the previously mentioned example of the Python API, you can define the whole infrastructure with a YAML file like this:
yamlservice: fastapi-serverless-templateframeworkVersion: '3'provider:name: awsruntime: python3.9memorySize: 512 # optional, in MB, default is 1024timeout: 10 # optional, in seconds, default is 6versionFunctions: false # optional, default is truestage: ${opt:stage, 'dev'}region: ${opt:region, 'us-east-2'}functions:api:handler: api/main.handlerurl: trueplugins:- serverless-python-requirementspackage:exclude:- venv/**- node_modules/**
If you want to start trying this right away, you can do it by following these steps:
1) Install the Serverless framework with this command: npm install -g serverless
2) Create a FastAPI serverless project using a starter template I created, just by using the command: serverless --template-url=https://github.com/agusmdev/fastapi-serverless-template
And that’s it! you’re ready to deploy your first Serverless API!
Conclusion
Serverless architecture is a game-changing approach that is reshaping the way we develop and deploy applications. By abstracting away server management, it allows businesses to focus more on their core products and less on operational concerns. The ability to only pay for what you use, combined with automatic scaling, can lead to significant cost savings and increased efficiency.
Adopting a serverless architecture is not just about minimizing costs and maximizing efficiency. It's about enabling your organization to be more agile, scalable, and focused on what truly matters – delivering value to your customers.
As we move forward into an increasingly digital future, this approach will continue to play a pivotal role in helping businesses stay competitive, innovative, and responsive to changing market demands. The journey to serverless may require a shift in mindset and practices, but its benefits make it a worthwhile investment.