Platforms, Microservices, DevOps and APIs · Insper

Service Models

Who operates each layer of the stack?

The store has to run somewhere real

The gateway, auth, account, product, order and exchange, plus Postgres, Redis and Kafka, run fine on a laptop with Docker Compose. Four kinds of options:

  1. Buy servers.
  2. Rent virtual machines.
  3. Hand your code or container to a platform that runs it.
  4. Skip the component and pay for a product that already does the job.

The one idea: every service model answers the same question — who operates each layer of the stack? The more you hand over, the faster you move and the less you control.

What makes it "cloud"?

NIST SP 800-145: five essential characteristics, and a service must have all of them.

Characteristic In the store
On-demand self-service aws rds create-db-instance creates Postgres in minutes
Broad network access the gateway is an HTTPS endpoint
Resource pooling order may share a physical host with another company's workload, isolated
Rapid elasticity Black Friday: order goes from 2 to 20 replicas, then back
Measured service the bill shows vCPU-hours, GB stored, GB transferred

Renting a server in a datacentre on a three-year contract is not cloud, even if the server is far away.

CapEx vs OpEx

CapEx (capital expenditure) — buy servers

  • A large payment up front.
  • Hardware sized for the peak you expect.

OpEx (operational expenditure) — the cloud

  • Pay monthly for what you use.
  • Removes the up-front bet…
  • …but is not automatically cheaper: full load 24/7 for years can cost more than owned hardware.

Service model ≠ deployment model. Deployment models say who shares the infrastructure: public, private, hybrid, community. This class is about the other axis: how much of it you operate.

CapEx vs OpEx: capacity and demand

Capacity vs demand Two charts of resources over time with the same rising demand. Left, CapEx: capacity grows in large steps bought ahead; it sits far above demand for long periods (idle capacity you paid for) and falls behind before the next purchase arrives (shortage). Right, OpEx: capacity follows demand closely, with a small margin. CapEx: capacity bought in steps time → resources → OpEx: capacity follows demand time → resources → purchase purchase capacity demand idle (paid, unused) shortage (lost demand)

CapEx buys capacity in steps months ahead: idle after each purchase, shortage before the next. OpEx follows demand with a small margin.

The responsibility stack

Every application in production needs the same six layers. Read them from the bottom up:

Layer What it is In the store
Data and access what the application stores and who may read it orders, accounts, DB users, API keys
Application your code the gateway and the services
Middleware what your code needs to run JDK, web server, Redis
OS the operating system of each machine Linux
Virtualisation hypervisor slicing a host into VMs KVM, Xen
Hardware servers, disks, network, power, cooling the datacentre

The central picture

From left to right, the provider takes over more of the stack: you operate it · provider operates it

On-premises
IaaS
CaaS
PaaS
FaaS
SaaS
Data and access
you
you
you
you
you
you
Application
you
you
you
you
you
provider
Middleware
you
you
you
provider
provider
provider
OS
you
you
provider
provider
provider
provider
Virtualisation
you
provider
provider
provider
provider
provider
Hardware
you
provider
provider
provider
provider
provider

Three things to notice

  • The top row never changes. The provider may store your data, but only you decide who may read it: security of the cloud (provider) vs security in the cloud (customer).
  • CaaS and PaaS differ by one layer: the middleware. On CaaS the JDK is inside the image you build; on PaaS the platform supplies it.
  • PaaS and FaaS have the same colours. What changes is the size of what you deploy: an application or a single function.

Pizza as a service. On-premises: you cook at home · IaaS: you rent a kitchen · PaaS: you order delivery · SaaS: you eat at a restaurant — and you still decide who sits at your table.

Who acts when something happens?

Find the event and read across the row: you operate it · provider operates it

On-premises
IaaS
CaaS
PaaS
FaaS
SaaS
A disk fails
you
provider
provider
provider
provider
provider
A flaw in the Linux kernel
you
you
provider
provider
provider
provider
A flaw in the JDK
you
you
you
provider
provider
provider
Black Friday: traffic ×10
you
you
provider
provider
provider
provider
A bug in the application
you
you
you
you
you
provider
An access key leaks
you
you
you
you
you
you

The usual setup of each model. On CaaS and PaaS the platform scales, but you still set the limits; on managed Kubernetes with classic node groups the OS of the nodes is still partly yours.

Check your understanding

The store runs on a PaaS and a flaw is published in the Linux kernel. What does your team do?

  • Nothing, as far as the OS is concerned: the provider patches it (the OS row).
  • Now the store runs on CaaS and the flaw is in the JDK…
  • …your team acts: the JDK is inside your image. Update the base image, rebuild, deploy again.

Climbing the stack, one model at a time

NIST defines three foundational models: IaaS, PaaS and SaaS. The market later added CaaS and FaaS between them.

Each model gets the same parts, so you can compare them:

  • what you hand over and what you keep;
  • the order service (or the store) on that model;
  • choose it when / avoid it when.

What you deploy tells the models apart: a VM (IaaS), an image (CaaS), code (PaaS), a function (FaaS) or nothing (SaaS).

IaaS: Infrastructure as a Service

You rent a machine and do the rest. You hand over datacentre, hardware and hypervisor; you keep the OS (patches, hardening), runtime, code, data, firewall rules and backups.

aws ec2 run-instances --image-id <ubuntu-ami> --instance-type t3.medium --key-name <key>
ssh ubuntu@<public-ip>
sudo apt update && sudo apt install -y openjdk-21-jre-headless nginx
java -jar order.jar

That is just the first day: configure nginx, restart the service if it crashes, patch the OS, schedule backups.

  • Choose it when you need control of the OS (kernel, drivers, GPUs) or for lift-and-shift of an existing application.
  • Avoid it when nobody wants to be on call for servers: every layer above the hypervisor is yours.

AWS EC2, Google Compute Engine, Azure Virtual Machines, DigitalOcean Droplets.

CaaS: Container as a Service

You hand over a container image; the platform runs it. The provider handles scheduling, networking, scaling and machine health; everything inside the image (base image, JDK, code) is still yours.

docker build -t <registry>/order:1.0 .
docker push <registry>/order:1.0
gcloud run deploy order --image <registry>/order:1.0 --region southamerica-east1 --max-instances 10

The same image you run with Docker Compose: moving provider means pushing it somewhere else.

  • Managed Kubernetes (EKS, GKE, AKS) is CaaS too: the provider runs the control plane, you use the standard Kubernetes API. Your project uses it.
  • Choose it when your services are already containers. Avoid it when the team would rather not patch base images: PaaS is one step up.

AWS ECS / Fargate, Google Cloud Run, Azure Container Apps.

PaaS: Platform as a Service

You hand over the code; the platform builds and runs it. It supplies OS, JDK, deploys, load balancing and scaling; you keep the code, the configuration (env vars, scaling rules), data and access.

heroku create store-order
heroku addons:create heroku-postgresql:essential-0
git push heroku main
heroku ps:scale web=2

A buildpack finds the pom.xml and builds the project: nobody installed a JDK or a database.

  • 12-factor app: stateless processes, config in env vars, logs to stdout — the platform may restart or move your process and wipe its local disk.
  • Choose it when the team wants to ship features, not manage servers. Avoid it when you need software the platform lacks, or at large, steady scale.

Heroku, AWS Elastic Beanstalk, Google App Engine, Azure App Service, Railway, Render.

FaaS: Function as a Service

You hand over a single function; it runs only when something calls it. PaaS taken to the extreme (serverless): instances on demand, scale to zero, pay per invocation and per millisecond.

The whole order service is not a good fit, but the e-mail sent after each order is:

public class OrderCreated implements RequestHandler<Map<String, Object>, String> {
    @Override
    public String handleRequest(Map<String, Object> event, Context context) {
        // send the confirmation e-mail for this order
        return "sent";
    }
}

AWS Lambda, Google Cloud Functions, Azure Functions, Cloudflare Workers.

FaaS: two constraints

  • Cold start: the first request to a function with no instance ready waits for a sandbox, the code and the runtime — seconds for a Spring Boot application.
  • Maximum execution time: 15 minutes on Lambda.
  • Choose it when the work is short, event-driven and sporadic: webhooks, scheduled jobs, a file after upload.
  • Avoid it when every request needs low latency or traffic is steady and heavy: an always-on container is cheaper and more predictable.

Serverless containers blur the line. Cloud Run and Azure Container Apps also scale to zero and bill by usage, but run any image. "Serverless" is the operating model, not only functions.

SaaS: Software as a Service

You use the product; the provider runs everything else. You keep user accounts and permissions, the data you enter and the integrations (APIs, webhooks).

  • The store on SaaS: Shopify already is a store. Create an account, register products, set up payments — live the same day, but it can only do what the product allows.
  • Multi-tenant: one application serves all customers, each one's data kept apart — that is what makes SaaS cheap and instant.
  • Choose it when a product meets the need and the tool is not your differentiator: e-mail, CRM, monitoring, CI/CD.
  • Avoid it when the software is your differentiator, or you need customisation the product will never offer.

Google Workspace, Salesforce, Slack, GitHub, Datadog, Shopify.

Managed building blocks: DBaaS

Not everything fits on the ladder. DBaaS applies the same handover to a single component: instead of operating a Postgres server, you rent one.

Running Postgres on a VM Using a DBaaS
You install it and patch the OS and the database The provider patches in a window you choose
You write backup scripts and test them You set the retention period
You build replication and failover You turn on an option (Multi-AZ on RDS)
Schema, queries, access Schema, queries, access: these stay with you

AWS RDS, Amazon Aurora, Google Cloud SQL, Azure Database, Neon.

The same idea for other components

Model Abbreviation Examples
Storage as a Service STaaS AWS S3, Google Cloud Storage, Backblaze B2
AI / ML as a Service AIaaS AWS Bedrock, Google Vertex AI, Azure AI
Monitoring as a Service — Datadog, New Relic, Grafana Cloud
Security as a Service SECaaS Cloudflare, AWS Shield, Snyk
Communication as a Service CPaaS Twilio, SendGrid, AWS SES

Comparing the models

Read by rows, watching each characteristic change from left to right:

On-premises IaaS CaaS PaaS FaaS SaaS
You deploy everything a VM an image code a function nothing
Control maximum high medium medium low minimal
Time to go live months hours minutes minutes minutes immediate
Scaling buy hardware manual or scripted automatic (some to zero) automatic automatic to zero automatic
You pay for hardware (CapEx) VM-hours container time instances or usage invocations and duration users or seats
Portability full high high (the image) medium low (vendor API) low (data export)

Who offers each model

Model AWS Google Cloud Microsoft Other providers
IaaS EC2 Compute Engine Azure Virtual Machines DigitalOcean Droplets, Oracle Cloud Compute, Magalu Cloud
CaaS ECS / Fargate, EKS Cloud Run, GKE Azure Container Apps, AKS DigitalOcean Kubernetes, Fly.io
PaaS Elastic Beanstalk App Engine Azure App Service Heroku, Railway, Render
FaaS Lambda Cloud Run functions Azure Functions Cloudflare Workers, Vercel Functions
SaaS Amazon Connect, QuickSight Google Workspace Microsoft 365, Dynamics 365 Salesforce, Slack, GitHub, Shopify, TOTVS
Managed blocks RDS, ElastiCache, MSK Cloud SQL, Memorystore Azure Database, Azure Cache for Redis Neon, Upstash, Confluent Cloud

Read by columns: a model describes a service, not a company — AWS appears on every row. The big clouds offer almost every model; smaller providers specialise in one step of the stack.

How to choose

Per component, not per system. Start from the most managed option; ask in order and stop at the first yes (each no goes one step down):

1 · Does a product already do the job?
yes →
SaaS · GitHub Actions, Datadog
2 · A standard database, cache or broker?
yes →
Managed service · RDS, ElastiCache, MSK
3 · Short, event-driven and sporadic?
yes →
FaaS · Lambda, Cloud Functions
4 · Control of the OS or special hardware?
yes →
IaaS · EC2, Compute Engine, Azure VM
5 · A container that needs the Kubernetes API?
yes →
CaaS, managed Kubernetes · EKS, GKE, AKS
6 · A container?
yes →
CaaS, managed containers · Cloud Run, ECS Fargate
None of the above
→
PaaS · Heroku, App Engine

The store on AWS

Running each component through the questions gives one reasonable result, with the same shape as the course project:

Client
→
CaaS · EKS
gatewayCaaS: EKS
accountCaaS: EKS
orderCaaS: EKS
→
Managed data
PostgresDBaaS: RDS
RedisDBaaS: ElastiCache
Kafkamanaged: Amazon MSK
→
Events
notificationFaaS: Lambda
↓
e-mailCPaaS: AWS SES

Real systems mix models: CaaS for the services, DBaaS for the data, FaaS for the sporadic work. The data and access row stays yours in every box.

The store, component by component

Component Do it yourself Managed option What changes for the team
gateway, account, order Compose on EC2 (IaaS) EKS or ECS Fargate (CaaS) no SSH or OS patching; manifests instead
Postgres Postgres on EC2 RDS (DBaaS) backups, replication, failover become options
Redis container on the VM ElastiCache (DBaaS) survives a VM reboot; pay per node
Kafka brokers on VMs Amazon MSK broker patching and replacement move to AWS
Order notification consumer always running Lambda on the Kafka topic (FaaS) pay per message; cold starts on an async path
CI/CD Jenkins in a container GitHub Actions (SaaS) no Jenkins server to upgrade
Monitoring Prometheus and Grafana Grafana Cloud or Datadog (SaaS) no metric storage to size

Real systems mix models — the same shape as the course project. The data and access row never goes away: you still decide who connects to RDS and who reaches the gateway.

Your turn: the exchange service

Where would you run exchange, which converts currencies by calling an external rate API?

  • No product does this job, and it is not a database.
  • Synchronous requests during checkout: FaaS is possible, but cold starts would hurt.
  • No OS control needed; already a container; the project has Kubernetes → CaaS on EKS.
  • A small team without a cluster could reasonably pick Cloud Run: what matters is the justification.

Common mistakes

  • "Managed" as "not my problem": most cloud leaks are customer-side configuration — a public S3 bucket, a database open to 0.0.0.0/0, a leaked access key.
  • Ignoring lock-in: the higher the model, the more you depend on one vendor's API. Prefer containers, Postgres, the Kubernetes API.
  • The higher model is always cheaper: managed services charge a premium per unit; at large, steady scale running it yourself can pay off.
  • State on a PaaS or FaaS instance: local files and in-memory sessions vanish on restart or scale-in.
  • FaaS for a latency-critical, high-traffic API: an always-on container is cheaper and more predictable.

Takeaways

  • A service model defines who operates each layer of the stack; from IaaS to SaaS you hand over more of it.
  • More managed = faster, less operations, but less control and portability.
  • What you deploy tells the models apart: a VM, an image, code, a function or nothing.
  • "Cloud" = the five NIST characteristics; it turns CapEx into OpEx, which is not always cheaper.
  • Real systems mix models: choose per component, starting from the most managed option.
  • Your data, access rules and configuration are always yours.

On the class page: try the simulators to move the line between you and the provider, and compare costs.

Objectives: explain what makes a service "cloud" and CapEx vs OpEx; place IaaS, CaaS, PaaS, FaaS and SaaS on the responsibility stack, saying who acts when something breaks; compare the models; choose a model per component; name what never moves to the provider. Outline: (1) what makes it cloud; (2) the responsibility stack; (3) climbing the stack, one model at a time; (4) managed building blocks; (5) comparing the models; (6) how to choose, the store component by component; (7) mistakes.

Each option draws a different line between what your team operates and what someone else operates. That line is what a cloud service model defines.

The gap between the staircase and the demand is the cost of guessing: orange is money spent on capacity nobody uses, red is customers turned away. Autoscaling on OpEx closes the gap, but pays a premium per unit (see the cost simulator on the page).

This is the picture to remember. Ask the class to read it column by column before the next slide.

Control and portability fall as time to go live improves. FaaS is the outlier on portability: the code is written against a vendor API.

The store could use a single provider (on AWS: EKS for the services, RDS for Postgres) or mix providers (GitHub for the code and CI): the requirement of each component decides, as the next slide shows. Cloud Run functions was formerly called Cloud Functions.

Arrows: client → gateway → account and order; account and order → Postgres; order → Redis and Kafka; Kafka triggers the Lambda, which sends the e-mail through SES.