Search Sreeni's Insights

Filter by content type
cloud August 3, 2017 6 min read

Containers vs PaaS vs Serverless - which one for which workload?

VMs, PaaS, containers and serverless offer different control and operational trade-offs, with workload context guiding the right Azure hosting model.

Share:

Containers vs PaaS vs Serverless - which one for which workload?

Choosing a hosting model is becoming difficult because every option is promising faster delivery and lower operations. A fund API can run on a virtual machine, App Service, a container cluster or a function, but the operational responsibility is changing in each case. Choosing only from the technology name is creating an architecture which is either too complex or too restrictive for the workload.

Last year, we discussed why we need a CDN for global users, which is helping us to think about the boundary between our application and the platform. In this article, we are going to compare VMs, PaaS, containers and serverless options available in Azure, and select the right model from the workload characteristics.

TL;DR Summary

  • VMs provide the highest control and the highest operations responsibility.
  • App Service is a PaaS option for web applications; Web App for Containers and App Service on Linux are preview capabilities here.
  • Containers on ACS or ACI provide packaging and portability, but orchestration and platform responsibility are different.
  • Azure Functions is serverless with event and HTTP triggers, a Consumption plan and a scale model managed by the platform.
  • Service Fabric is useful for services needing a distributed platform with more control than PaaS.
  • Select from control, scale model, cold start, state, runtime length, cost, skills and lock-in, not from fashion.

Challenges

Control versus operations

A VM allows us to install the exact runtime, operating-system package and network rule, but the team is also patching and monitoring that machine. A PaaS service removes much of this work, but it is narrowing the supported runtime and platform controls.

The trade-off is not only technical. Time spent patching a VM is reducing time available for fund features, while a platform limitation may require a design change which affects the business schedule.

Scale model does not fit every workload

A long-running API needs predictable capacity and health checks. A nightly batch needs compute for a short period. An event handler may be idle for most of the day and then receive a burst. Applying one scale model to all three workloads is creating either idle cost or slow response.

State and runtime behaviour

Functions are good for stateless handlers, but a long-running process, local state or a special native dependency may not fit the function model. Containers package the runtime, but a container still needs data, networking and orchestration decisions.

What is the hosting model?

Infrastructure as a Service (IaaS) provides virtual machines, disks and networks for us to operate. Platform as a Service (PaaS) provides a managed application platform. Containers package an application and its dependencies, while serverless runs functions or handlers without asking the team to manage application servers.

In simple terms, IaaS gives us a machine, PaaS gives us an application platform, containers give us a portable process package and serverless gives us an event-driven execution unit. Each model is moving responsibility between our team and the platform.

The following diagram compares the control and responsibility boundary for common Azure hosting choices.

Control versus responsibility for hosting models
Control versus responsibility for hosting models

The purple path is moving from more control and more operations toward more platform management and less infrastructure responsibility. It is not showing one universal best choice.

Why the hosting model is important?

The hosting model is important because it is influencing delivery speed, reliability, cost and the skills needed to operate the application. A mature team can benefit from containers, while a small team may gain more by keeping a simple API in App Service.

In our case, a fund API with a stable HTTP workload is normally starting with PaaS or a well-understood container platform. A nightly reconciliation job can use a container or Function depending on runtime and state. We should not introduce a cluster only because another team is already using one.

Hosting options available

ModelAzure optionResponsibility and trade-off
IaaSAzure VM+ Maximum control
− Patch, scale and monitor the machine
PaaSApp Service / Web App for Containers+ Managed web platform
− Platform and runtime constraints
Container platformACS with DC/OS, Swarm or Kubernetes+ Portable package and orchestration
− Cluster masters, nodes and networking need operations
Container instanceACI preview+ Fast start and per-second billing
− Preview limits and less orchestration
Distributed platformService Fabric+ Stateful and service-oriented platform
− More platform concepts and skills
ServerlessAzure Functions Consumption plan+ Event scale and pay-per-execution model
− Cold start, execution limits and platform coupling

App Service on Linux and Web App for Containers are preview options here. ACI is also preview, and Windows containers are preview. Azure Functions is generally available since November 2016, with a Consumption plan, but the workload still needs to fit its trigger, state and execution model.

Selection criteria

Let us discuss the key questions before choosing,

Control and team skills

Do we need operating-system access, custom drivers or a special network configuration? If yes, IaaS or containers may be suitable. If the team does not have cluster operations skills, App Service can be a healthier starting point.

Scale and cold start

Does the workload need constant capacity, burst capacity or scale-to-zero? A PaaS instance or container cluster is useful for a continuously available API. Functions are useful for bursts, but a cold start can affect a user-facing operation.

State and runtime length

Stateless HTTP and event handlers are fitting PaaS and serverless models. A process which runs for a long time, maintains a connection or needs local state is usually fitting a container or VM better. Persistent state should still be kept in a suitable data service, not inside an ephemeral process.

Cost model

Compare instance cost, per-second container cost, per-execution function cost and the team operations cost. A low infrastructure bill is not a saving if the architecture is requiring a new platform team.

Lock-in and portability

Containers can improve portability, but the surrounding service, identity, storage and network choices can still be platform-specific. Functions provide productivity, but the trigger and binding model is creating more coupling. Choose the lock-in which gives a sustainable business advantage.

Workload selection

WorkloadStarting choiceReason
Fund HTTP API with steady trafficApp Service or container platformPredictable HTTP scaling and simple health checks
Nightly reconciliation batchContainer or VM jobFull runtime control and a known execution window
Event processingAzure Functions or container workerNatural trigger and burst scale
Legacy Windows applicationAzure VMOperating-system compatibility
Stateful distributed serviceService Fabric or container platformRuntime and state management requirements
Short experiment or burst containerACI previewFast provisioning and per-second billing

These are starting choices. Measure the real workload and move to another model when the constraints are becoming more important than the platform benefit. Refer the 2016 hosting model and serverless articles for the earlier comparison.

Must Do / Should / Don’t

Must Do

  • Must record control, scale, state, runtime and cost requirements before selecting the platform.
  • Must define who owns patching, deployment, monitoring, identity and data.
  • Must test cold start and failure behaviour for burst workloads.

Should

  • Should start a stable fund API with the simplest platform which meets its requirements.
  • Should use containers when packaging and portability are valuable, not only because containers are popular.
  • Should compare infrastructure cost with operations effort and lock-in.

Don’t

  • Don’t use a cluster for a small workload which App Service can operate safely.
  • Don’t put state inside a serverless function or an ephemeral container.
  • Don’t call a PaaS service “serverless” and assume execution limits do not apply.
  • Don’t choose a platform before understanding the application’s long-running and networking needs.

Wrap up

In this article, we have looked at IaaS, PaaS, containers, ACI, ACS, Service Fabric and Azure Functions, and the criteria for choosing a workload model.

I really appreciate that you took the time to read this article. In the next article, I will walk you through designing for observability with logs, metrics and traces.

Related Posts