Serverless vs. Containers: Which is Right for You? | Datadog
Serverless vs. Containers: Which is Right for You?

serverless

Comparing serverless and container-based architectures: which is right for your application?

What are the benefits and pitfalls of, and the differences between, serverless architecture and container-based architecture?

What are serverless and container-based architectures?

Application development has come a long way since the days of directly copying code from one application server to another. Serverless and container-based architectures are very different solutions and are evolutionary compared to traditional, server-based development environments. Traditional software development, with applications linked to dedicated servers or virtual machines (VMs) with their own environments, has always been tied to issues of scale, agility, and maintainability. Newer architecture designs take advantage of these limitations to improve development, testing, deployment, and management for teams of developers.

First, let’s describe these two types of architectures. Serverless architectures allow developers to build and run applications without having to manage the underlying architecture. A separate host entity, typically a cloud service provider (CSP), manages the environment where the applications run. Container-based architectures package up application code, its dependencies, and its settings within a container that can run in any environment. Up to hundreds of different containers can be run using their own codebases. Container management is usually orchestrated by Kubernetes, Docker, or similar platforms.

Next, we’ll map out both architectures’ specific capabilities and benefits and discuss how either of them, or a combination of the two, might be best suited to your next project.

The advantages of serverless and container-based architecture

The benefits of serverless architecture are straightforward: flexibility, cost-effectiveness, scalability, and productivity. A CSP supports an application’s infrastructure, and the customer is charged only for those devices and functionality using the required capacity and resources. This capability is also an advantage when it comes to scalability. As the demand for capacity grows or decreases, the CSP scales the infrastructure and support costs as needed. This elasticity allows for flexible resource allocation. The other chief advantage of using serverless and container-based architectures is increased productivity. Developers can deploy code via the CSP. There’s no need for server management or the addition of backup systems.

Container-based architecture also has distinct advantages. Containers can be created and dropped as needed by developers and engineers, which leads to scalability for containerized applications. Containers are also lightweight and resilient, and they have no underlying operating system (OS). This means separate containers can run completely different apps on the same machine or network device. Moreover, there’s compartmentalization—a container that experiences a fault or error will not affect other containers or the applications running in them.

Virtual machines and cloud computing

It’s important to differentiate between VMs and the cloud computing services found in serverless and container-based architecture. VMs are a technology that allows for the creation of multiple environments or resources on a single piece of hardware or a cluster (a collection of container nodes monitored by an orchestration platform such as Kubernetes). Virtualization software sits on top of physical hardware and abstracts the machine’s resources, which are used to create VMs.

Cloud computing is an environment that abstracts, pools, and shares scalable resources. It should be noted that both serverless and container-based architecture can use VMs.

How does serverless architecture work?

Moving to a serverless architecture from a traditional server-based infrastructure frees organizations from the need to maintain an extensive internal infrastructure. Developers can focus on delivering code while a CSP manages the infrastructure.

With the function-as-a-service (FaaS) software paradigm, developers can go even further when developing applications using serverless architecture. Developers write application code as a set of functions. A function performs a specific task triggered by an event, a set of request parameters, and so on. The code is deployed with function triggers attached to the CSP’s infrastructure. When a function is invoked, the CSP executes the function on an available server or spins up a new server to handle the request. FaaS in a serverless environment abstracts code execution so that developers can concentrate on writing application code and addressing technical issues without worrying about the underlying infrastructure.

What are the downsides of serverless architecture? Because CSPs control pricing, the costs of managing server farms, data centers, backups, and connectivity can substantially fluctuate. Another key aspect is security. Is your organization’s proprietary and valuable data safe while it resides in someone else’s data center? There can be issues with limited control in situations where teams must interact with another company’s infrastructure, and more robust Automatic Storage Management (ASM) or Container Storage Modules (CSMs) might be required. Additionally, teams are also locked in with the same technology that the CSP uses. Note also that serverless architecture is less suitable for long-running workloads (batch processing, for example), cold-start situations (for applications with long delays between input and response, such as videoconferencing applications), or low latency.

How does container-based architecture work?

Container-based architecture orchestration tools, such as Kubernetes and Docker, are runtimes that manage containers and deploy containers at scale. Unlike VMs, which require traditional hardware, containers have no underlying OS, making them leaner and lighter than full network server environments.

Packaging application code with its libraries, dependencies, configurations, variables, and settings is called containerization. A container runs on a cluster, a collection of nodes monitored by an orchestration platform. Note that with Kubernetes, the smallest deployable collection of containers that can be created and managed is referred to as a pod.

Kubernetes and similar orchestration tools standardize container behavior across the host network environment—creating, deploying, and dropping containers as needed. The management and allocation of resources depend on the type of runtime, which is either high-level or low-level. Examples of high-level container applications include email, search, and video-on-demand applications. Low-level container operations include orchestrations that handle migrations or interactions with an OS’s kernel, for instance.

There are downsides to container-based architecture. Not all applications work well in virtual container environments, particularly apps that require persistent data from databases. Containers are stateless: the moment a container is dropped, the data within that container is lost unless a process retains the data. Security is also a critical concern. Although there’s no underlying OS, containers share a host kernel. If one container is compromised, a hack could penetrate other containers. Lastly, large-scale container networking can be complex and must be managed using Kubernetes or a similar tool.

When to use serverless or container-based architecture?

Below are three scenarios examining the benefits of serverless and container-based architecture in each situation. These use cases showcase the most relevant and useful benefits of each architecture type.

Scenario #1: App modernization

As applications age, you might have to decide between either modernizing or replacing the apps. The considerations that factor into these decisions might include boosting cost-effectiveness, cutting ties to legacy systems, improving the customer experience, enhancing business agility, or reducing the amount of code to improve efficiency.

Advantages and Benefits of: Serverless architecture

Improved agility and scalability: Serverless computing can scale to meet demand without manual intervention, which could be beneficial for event-driven operations.

Cost efficiency: With serverless computing, costs depend on the resources used and can provide a more accurate cost-per-consumption model, as opposed to container-based computing, where the architecture incurs costs regardless of whether or not specific resources are being used.

Advantages and Benefits of: Container-based architecture

Consistency and control: Containers provide a consistent environment for applications, giving teams more control over the OS and software stack and providing a tailored environment.

Resource efficiency: Containers are more resource-efficient than serverless computing, especially when working with long-running applications.

Scenario #2: Cloud-migration transformation

Cloud-migration transformation is essential for businesses looking to adapt to new requirements and changing technologies. The reasons for this type of transformation might include economic efficiency, regulatory requirements, security requirements, or the need to adapt existing systems to a hybrid cloud infrastructure.

Advantages and Benefits of: Serverless architecture

Reduced operational overhead and costs: With serverless computing, the infrastructure is managed by an outside provider, which significantly reduces management overhead costs.

Event-driven scalability: Serverless computing is inherently designed for event-driven scenarios, allowing for continuous autoscaling, which is beneficial for data center operations. Examples include heavy user demand from point-of-sales operations (for example, popular shopping days with frequent sales), video streaming of a new series, and transactional events (pay-per-view).

Advantages and Benefits of: Container-based architecture

Portability: Containers encapsulate an application and its dependencies, making it easy to move containerized applications across different environments and even across different CSPs or on-premises data centers.

Control and predictability: With container architecture, organizations have more control over the operating environment and can ensure that the environment is consistent across all stages of the application lifecycle.

Scenario #3: Event-driven or high-traffic applications

Event-driven or high-traffic applications are becoming increasingly common in modern system planning. Applications demand real-time processing for e-commerce, financial services, gaming, notification systems, or collaboration applications. High-traffic examples include content distribution networks (CDNs) deployed for websites.

Advantages and Benefits of: Serverless architecture

Integration with cloud services: Serverless functions can quickly connect event processing logic with other cloud services, making them well-suited for building complex, event-driven applications.

Robust autoscaling: Serverless platforms provide robust autoscaling capabilities, and they can scale to zero and charge only for resources that are actually used—by the second—which is ideal for high-traffic application scenarios.

Advantages and Benefits of: Container-based architecture

Event-driven processing: Containers are well-suited for running microservices and applications that require event-driven processing.

Portability and open-source platforms: Containers enable the creation of modern apps with open standards on a Kubernetes foundation, with portability in mind. This is also beneficial for applications that need to be modernized and might need to run in various environments.

What are the challenges deploying serverless and container-based architecture?

The following are some of the key factors to consider before implementing a serverless or container-based architecture:

  1. Additional resources are required to monitor and manage either architecture, whether it’s with a CSP or a container orchestration platform like Kubernetes.

  2. Either architecture divides an application into smaller, abstract components or functions that must be managed and tracked. The greater the number of pieces, the greater the complexity.

  3. The more an application’s components are abstracted, the less visibility developers have into how those pieces work and fit together. Troubleshooting becomes an issue and requires advanced observability capabilities.

  4. Security (data protection) is a top-priority concern, and CSMs and ASM must be deployed alongside one another.

What shifts have occurred in the industry that could affect decisions regarding serverless and container-based architecture?

With both serverless and container-based architectures, organizations are building applications with less overhead and more flexibility than traditional environments. Developers are no longer restricted to a specific OS or programming environment. Either of these architectures reflects a growth in microservices—breaking complex apps down into smaller blocks or functions that are easier to manage and deploy.

There are no hard-and-fast rules when deciding which of these architectures to implement. Keep in mind that serverless architecture and container-based architecture can co-exist within the same infrastructure.

What should you keep in mind choosing a solution?

Datadog provides several solutions for your current or next application architecture, whether the choice is serverless, container-based, or both. Datadog Serverless Monitoring provides end-to-end visibility into the health of serverless applications by providing key metrics, tracing, and logging of serverless applications.

For your container-based architecture environments, Datadog recommends Datadog Container Monitoring. Datadog agents work in concert with Kubernetes clusters (a collection of nodes running containerized applications) to review, manage, and monitor containers as they’re created and dropped, and to inspect the services and operations occurring inside containers. Infrastructure teams can observe and report on container health, resource consumption, and deployment status.

Learn more

See the following articles to learn more about how Datadog assists teams with their questions and issues regarding serverless and container-based architectures:

  1. Containerized Applications Overview
  2. AWS Step Functions Overview
  3. Serverless Microservices Overview
  4. Serverless Architecture Overview

Related Content

Learn about Datadog at your own pace with these on-demand resources.

gated-asset/210524_Serverless_Preview

guide

Serverless Monitoring Product Brief
serverless/serverless-hero

product

Datadog End-to-end Serverless Monitoring
/blog/key-metrics-for-monitoring-aws-lambda/lambda_part1

BLOG

Key metrics for monitoring AWS Lambda
Get free unlimited monitoring for 14 days