Probably you would ask how you should choose between serverless and container and the answer is tricky. Sometimes we prefer serverless because of its simplicity of deployment and management - what is a crucial point for the client. In another case, we would choose containers because of their flexibility and the opportunity to take everything under control. Sometimes containers can be used together with serverless, for example with Knative.
So when to choose containerization?
Containers are a great choice if you:
- have a complex application with difficult architecture and you need a higher level of control over resource allocation, admin policy, and security.
- have a monolith system and you want to rebuild it into microservices to create a modern architecture.
- plan to migrate a monolithic system to the cloud
- want to build a modern application architecture and to have control over it and you have resources to deploy and maintain the application.
- have a big e-commerce platform with bulky business logic (product lists, payment processing, product management, etc). All these parts are packaged into containers according to the business logic.
- plan to scale your application continuously.
When to choose serverless?
Serverless is a brilliant fit for the following cases:
- you have a limited budget on infrastructure management and maintenance.
- you don't have the required resources to maintain a backend infrastructure.
- the traffic of your service is unpredictable, or you know the pattern of your traffic and can pre-warm infrastructure to handle everything. That's why you need the traffic behavior changes to be automatically detected and handled.
- application of the event-driven nature that doesn't always need to be running (for example, small e-commerce business or an IoT application).
- fast-growing apps requiring quick deployments and changes.
- video and image processing applications.
Can serverless and containers coexist and build a reliable hybrid architecture?
You will be surprised but yes! The most common use case is the main part of the application has a containerized microservices-based architecture and serverless functions and backends are used for some rare operations (which are actually CPU consuming). In such a way, they can complement each other's weak sides.
AWS Fargate is here to help developers build hybrid solutions, allowing running containers without the need to manage servers or clusters.
Another example is Knative that is built on top of k8s and allows to run your containers in serverless approach, you no longer need to pay for idle containers.