Application shapes

Monolith, microservices or serverless: where the boundaries fall

Monolithone deployablecataloguecartorderspaymentsone build, one deploy, in-process callsMicroservicescataloguecartorderspaymentsseparate services, each with its own dataServerlessAPI gatewayGET /itemsPOST /cartPOST /orderfunctions run per request; no serversOne application, three shapes. What changes is where the boundaries are and who runs the machines.A monolith is one deployable unit. Microservices split it into services that deploy and scale on their own. Serverlesshands the running of code to the provider: functions and managed services that scale to zero. These are not stages ofmaturity; each fits different teams and loads, and real systems mix them.

A monolith deploys as one unit; microservices deploy and scale separately; serverless leaves the machines to the provider.

Functions

A function runs once per event; concurrency is requests times duration

An event triggers a functionHTTP requestfile uploadedqueue messagescheduleFunctionstateless; up to 15 minConcurrency = requests a second × seconds each400 requests/s × 0.25 s = 100 running at onceeach dot = 2 instancesDefault limit: 1,000 at once per account and region (can be raised).Memory 128 MB to 10 GB; processor power grows with memory.Pay per request and per GB-second of run time; nothing when idle.A function runs once per event, and the number running at once is requests a second times duration: here 100.There is no server to size: each event gets an instance, and the provider adds instances as events arrive. That makesconcurrency the number to watch. A slower function needs more at once for the same traffic, and the account limitis shared by every function in the region. AWS Lambda, Azure Functions, Google Cloud Run functions.

Concurrency = requests a second × duration: 400 × 0.25 s = 100 instances at once, within a default limit of 1,000.

Cold starts · Going deeper · 1 of 2

A new instance pays for starting up; warm ones do not

Cold startdownload codestart runtimeyour init codehandler600 msWarm instancehandler60 msIllustrative durations; real cold starts range from about 100 ms to several seconds by runtime and package size.The first request to a new instance pays for starting it. Later requests reuse the warm instance.A cold start happens when traffic rises or after a quiet period. It matters for user-facing APIs with strict p99targets, and hardly at all for queues and batch work. Reduce it: smaller packages, less work at start-up, a lighterruntime. Remove it: provisioned concurrency keeps instances warm (and is billed while it does); SnapStart restoresJava and other runtimes from a snapshot. Put connections and clients outside the handler so warm calls reuse them.

A cold start adds start-up time to the first request on an instance; provisioned concurrency keeps instances warm.

Concurrency controls · Going deeper · 2 of 2

Reserved concurrency caps a function; provisioned keeps it warm

Account concurrency limit in one Region: 1,000, to scalecheckout: 300 reserved, 100 of them provisioned (dark)reports: 50 reservedunreserved pool: 650, shared by every other functionReserved concurrencyfree; a guarantee and a capcheckout always has 300, never moreset it to 0 to switch a function offProvisioned concurrencybilled while it is on100 instances initialised in advanceno cold start up to that numberWhen the limit is hitdirect call: 429 TooManyRequestsExceptionasync event: retried for up to 6 hoursqueue source: messages stay in the queueThe account limit is one shared pool. Reserve part of it to protect a function, or to protect what it calls.Lambda always keeps 100 unreserved, so at most 900 of 1,000 can be reserved. Here 350 are, and a runaway function can no longerstarve checkout. A cap is a shield as well: a database that accepts 200 connections is safe behind a function reservedat 200 or fewer. Growth has a speed limit too: each function adds at most 1,000 instances every 10 seconds.

Reserved concurrency guarantees and caps a function’s share of the 1,000; provisioned concurrency keeps instances initialised.

Serverless cost

Functions cost nothing idle; steady heavy traffic is cheaper on servers

0M50M100M150M200M$0$200$400requests a monthfunctions: $1.87 per milliontwo servers, always on: $147 a monthequal at 79M a month (about 30 a second)Functions cost nothing when idle and grow with use. Steady, heavy traffic is cheaper on servers.A 500 MB function running 200 ms costs about $1.87 per million requests; two small servers cost $147 a month whether busy or idle.Below the crossing, functions win, often by a lot; above it, servers or containers do, more so with Savings Plans.Count the operations work too: functions have no patching or scaling to run. Example list prices, us-east-1, 2025.

Functions cost per use; servers cost per hour. Here they are equal at about 79 million requests a month.

API gateways

A gateway does what every API needs before your code runs

clientsAuthenticatekeys, tokens, IAM,custom authorizersThrottle10,000 req/s default;limits per clientValidatereject bad requestsearly and cheaplyRouteto a function,container or serviceCachecache responses;reshape requestsAn API gateway does the work every API needs before your code runs: identity, limits, validation, routing.It is the front door for functions and microservices. Requests that fail sign-in, exceed a client’s limit or are malformedare rejected at the gateway, cheaply. Its limits shape a design: a 29-second integration timeout by default (long jobsneed a queue and a status check) and per-account throttling. Amazon API Gateway, Azure API Management, Google API Gateway.

An API gateway authenticates, throttles, validates, routes and caches; bad requests are rejected before they cost compute.

REST and HTTP APIs · Going deeper

REST API or HTTP API: pay for the features you use

Amazon API GatewayREST APIHTTP APIEndpoint typesedge-optimised, regional, privateregionalAuthorisersIAM, Cognito, LambdaIAM, Lambda, JWT (which covers Cognito)API keys and usage plansyes: limits and quotas per clientnoResponse cachingyes: 300 s by default, up to 3,600 snoAWS WAF, resource policiesyesnoValidation, body mappingyesno; parameter mapping onlyCanary stages, X-RayyesnoIntegration timeout29 s; can be raised on regional and private30 s, fixedPrice per million requests$3.50$1.00An HTTP API costs 71% less and does less. Choose REST only for a feature in its column.Both take payloads up to 10 MB and share the account limit of 10,000 requests a second. A third type, the WebSocketAPI, holds a two-way connection open for chat and live updates. Work slower than the timeout needs the asynchronouspattern: accept, queue, return 202, and let the client poll. Example list prices, us-east-1, first tier, 2025.

An HTTP API costs 71% less; a REST API adds caching, usage plans, WAF, validation and private endpoints.

Managed containers

Managed containers remove the servers but keep the container

Your codeContainer imageScaling and placementServers: patching, sizingCluster control planeContainers on EC2(ECS/EKS)Fargate(ECS or EKS)App Runner, Cloud Run(Container Apps)Functions(Lambda)purple: you run it · light: the provider runs itManaged containers remove the servers but keep the container: your image, any language, no time limit.Choose functions for short, event-driven work. Choose containers when a task runs longer than 15 minutes, needs asteady load, a specific runtime, or must move between clouds. Fargate runs each task without servers to manage; ECSor EKS on EC2 gives the most control and the lowest price at scale, with the patching that goes with it.

Fargate and similar services run containers without servers to manage; choose containers over functions for long, steady or custom work.

Compute on three clouds · Going deeper

Functions, containers and Kubernetes, named on three clouds

AWSAzureGoogle CloudFunctionsLambdaAzure FunctionsCloud Run functionsContainers, no serversECS or EKS on FargateContainer Apps; Container InstancesCloud RunManaged KubernetesEKSAKSGKE (Autopilot runs the nodes too)Web app platformElastic BeanstalkApp ServiceApp EngineImage registryECRContainer RegistryArtifact RegistryAPI front doorAPI GatewayAPI ManagementAPI Gateway; ApigeeWorkflowsStep FunctionsLogic Apps; Durable FunctionsWorkflowsBatch jobsAWS BatchAzure BatchBatch; Cloud Run jobsThe same ladder on every cloud: functions, serverless containers, Kubernetes. The time limits differ.A Lambda function stops at 15 minutes. Azure Functions stop at 10 on the Consumption plan and have no cap on FlexConsumption or Premium (30 by default), though an HTTP reply must come within 230 seconds. A Cloud Run request may run60 minutes. Cloud Run and Container Apps scale a container to zero between requests; a Fargate service does not by itself.

Fargate, Container Apps and Cloud Run run a container without servers; the time limits and scaling to zero differ.

Service boundaries

Draw boundaries around business capabilities, each with its own data

Shared database: services in name onlyorderscartbillingchange a table and three services break;they must be deployed togetherEach service owns its dataorderscartbillingothers ask through its API or its eventseach one deploys, scales and changes itsstorage without asking the othersDraw service boundaries around business capabilities, and give each service its own data.A service is independent only if nothing else reaches into its database. Split along what the business does (orders,billing, catalogue), so one team owns one capability end to end. Data that others need is offered through an API orpublished as events (lesson 7). Splitting along technical layers (a “database service”) recreates the monolith.

A service is independent only if it owns its data; others reach it through its API or events, never its tables.

Monolith first

Microservices trade an organisation problem for a distributed one

A monolith fits whenMicroservices fit whenTeamone or a few teamsmany teams needing to ship aloneDomainstill being discoveredwell understood, stable boundariesScalingthe whole app scales together fineparts need very different scaleOperationslittle platform experienceCI/CD, tracing and on-call in placeFailurein-process calls cannot time outevery call can fail: lesson 9 neededMicroservices solve an organisation problem and cost a distributed-systems problem. Start with a modular monolith.Every function call that becomes a network call can be slow, fail or arrive twice, and needs tracing to debug. That costis worth paying when many teams must ship independently or one part needs very different scale. Until then a monolithwith clean internal modules is simpler, faster and cheaper, and its modules are the natural services to split out later.

Start with a modular monolith; split out services when teams or scaling needs demand it.

Lesson complete

You finished “Monoliths, microservices and serverless”

Nicely done.

Open in a new tab