SERVERLESS VS CONTAINERS - WHAT TO CHOOSE?

article

Serverless and containers are two widely discussed application development trends in 2019-2020. Some devs fiercely claim that serverless comes to replace containers, a team across the river argues and gives preference to containers. That's why comparison serverless vs containers remains actual even now.

Let's figure out the main difference, advantages and drawbacks, use cases and finally try to find out how these technologies coexist.

What are containers?

Containers are the isolated environment that literally contains code, its dependencies, libraries, binaries, configuration files. Thus, an application runs swiftly and can be transited among environments faultlessly.

Containerization provide more flexibility and robustness into the local development, which enables teams to work independently since they work only on the piece of application they are responsible for. As a result, such architecture provides a more convenient and reliable approach to deployment, testing, and management of the application.

Advantages using containers

Portability

Containerized applications can be deployed on different OS and hardware - Windows, Linux, MacOS, cloud, on-prem, FPGA.

Less resource consumption

Becasue containers don't need to emulate hardware - theycontainers consume less resources compared to than VMs and other alternatives

The highest control level

Developers can choose what programming language is better to use and how to pack the container. They have control over the ecosystem inside the container and the way the app behaves. Proper container allows to setup the main dependencies at the beginning and avoid situations like "It works on my machine".

No vendor lock-in

Since containers are portable and independent, you are autonomous from the vendor.

Version control

Environment versioning and image tagging allows developers to rollback to the previous version very quickly and eliminate needs of maintenance mode. At least from infrastructure perspective.

Limitless

Containerized applications may be as complicated as you require. No constraints like timeouts or memory limitations compared to serverless architectures.

Disadvantages using containers

Difficulties with management and setting up

Сontainers require deeper skills to be set up and managed. For example, when you add more logic into the application - more containers need to be added which may lead to the slower initial setup and infrastructure can become more difficult to manage.

Code optimization needed

If you want to leverage full power of container architecture additional changes in the application may be needed. Those are always good changes to the code, but you should be aware of them anyway.

Risk of additional technical debt

Incorrect initial setup and use of containers may add more to your technical debt that already exists ( let's be honest ) So it's crucial to make sure that you set up them in the right way from the beginning.

Higher costs as opposed to serverless

When it concerns serverless, you are charged only for the time of the function execution. What concerns containers, you need to pay for server usage even if there are no running computing operations. It is important to mention that we are talking about fine-architected serverless infrastructure. Otherwise the price for serverless can be multiple times higher compared to containers.

What is serverless?

Serverless is a cloud computing code execution model, where a certain cloud provider takes over the responsibility for servers running along with computing resources management. In simple words, there are no physical or virtual servers to manage, because they are automatically deployed in the cloud by the third-party vendors.

More about serverless meaning and its operational principles: https://alpacked.io/blog/what-is-serverless-computing

Advantages using serverless computing

No-Ops Autoscaling

The resources are scaled automatically when a sudden increase in traffic is predicted.

Zero administration required

A FaaS vendor assumes the burden of the infrastructure management.

Higher availability

Almost 100% availability can be easily gained because of autoscaling and automated infrastructure management. If an Ops specialist requires some time to handle a problem, a serverless vendor solves it within a few seconds.

Great pricing model

You are charged only for the resources you utilize, i.e. you pay for the time when the function is executing.

Microservices

Microservices-based architecture is the best case to use serverless.

Quicker time-to-market delivery

Submit new features to the consumers faster! Upload the code and the changes are initiated at once through calling API.

Disadvantages using serverless computing

Timeouts

Function timeouts cause the failure of some long-running computing operations.

Cold starts

Even though vendors scale your applications automatically - by default functions cannot handle big spikes of load quickly. You need to understand the load of your application and pre-warm the functions to better handle spikes in the application.

Basal time-lag

For some limited number of businesses, any time-lag may be catastrophic. For the wide circle of industries, even millisecond time-lag is hardly noticed.

Time- and energy-consuming transition

Migration to the serverless architecture may occur to be costly and resources-consuming since it requires many significant changes not only in the code and IT infrastructure but in cultural aspects.

Difficulties with monitoring and debugging

The app is broken down into pieces and each piece has its own bugs and issues. Sometimes it's challenging to gather everything under control and see the whole picture.

Vendor-dependency

Once you have chosen a FaaS provider, you get "lock-in" and it becomes a headache to use third-party services.

How containers and serverless are similar?

Containers and serverless allow developers to create cutting edge and adaptable apps. They both:

  • are suitable for microservices architectures.
  • run in the cloud.
  • start quiet swiftly (within a few secs).
  • are integrated with 3d party resources through API invocation.
  • have isolated environments.
  • reduce the responsibility for infrastructure maintenance and allow developers to focus on product improvement, rather than on its maintenance.

Difference between containers and serverless

PointContainersServerless

User's role

A user takes under control the whole process of container initiation.

The process is hidden from the user.

Management

Needs an Infrastructure engineer to manage and update a container.

A serverless vendor takes over the responsibility for infrastructure management.

Testability

Easy to test because containers are run on the same platform where they are deployed.

Difficult to test because of challenges with the backend environment replication on the local environment.

Timeouts

Continuous working until the container finishes the required event or is simply destroyed.

Max 15 min (900 sec) can be set. It is required for application to be able to work with timeouts or handle chunks of data instead of all-in-once.

Payment peculiarities

Needs a running server to stay available.

Pay for the function execution time.

Programming languages

Any. Containers allow heterogeneous development.

A vendor specifies the supported programming languages. Usually, the vendor supports Node.js, Python, Java, C#, Go (AWS Lambda).

Time-to-market

Takes a bit more time to get set up and developed, but once the container is configured, it takes a few secs to deploy.

Easy to deploy within milliseconds because there is no bundle with the system dependencies.

Heavy data processing

Allows to run long-lasting data processing jobs, there are no limits on resources by default.

If it takes more time to process a heavy resource, a serverless function must support beaking request down into smaller units.

Use cases for containers and serverless

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.

Conclusions

Serverless vs containers - which one should you pick? Both containers and serverless are two evolving TOP technologies to build a flexible and reliable application. As you see from this article, these solutions are not competing and have their pros and cons. That's why before making any decision, you should analyze which technology benefits would cover your business needs as much as possible.

Do you still have doubts about whether containers or serverless is a better fit for your application? Contact us to get help!

Let's arrange a free consultation

Just fill the form below and we will contaсt you via email to arrange a free call to discuss your project and estimates.