Application shapes
Monolith, microservices or serverless: where the boundaries fall
A monolith deploys as one unit; microservices deploy and scale separately; serverless leaves the machines to the provider.
The same shop can be built three ways. As a monolith: catalogue, cart, orders and payments are modules of one program, built and deployed together, calling each other in memory, sharing one database. As microservices: each is a separate service with its own database, deployed and scaled on its own, talking over the network. Or serverless: an API gateway routes each request to a small function, and the data lives in managed services. No machines to run, and nothing to pay when no one is shopping. Each fits a different team and load, and most real systems mix them.
Functions
A function runs once per event; concurrency is requests times duration
Concurrency = requests a second × duration: 400 × 0.25 s = 100 instances at once, within a default limit of 1,000.
A function is code the provider runs for you, once for each event. The event can be an HTTP request, a file landing in a bucket, a message on a queue, or a timer. The function keeps nothing between calls and can run for up to fifteen minutes. There is no server to size, but there is a number to watch: how many run at once. It is requests a second times the seconds each takes. Four hundred a second at a quarter of a second is a hundred at once. The account has a default limit of a thousand per region, shared by every function, so a slow function can starve the others.
Cold starts · Going deeper · 1 of 2
A new instance pays for starting up; warm ones do not
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
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
Functions cost per use; servers cost per hour. Here they are equal at about 79 million requests a month.
Is serverless cheaper? It depends on traffic. A small function costs about 1.87 dollars per million requests. Its cost rises in a straight line from zero. Two small servers, enough for availability, cost about 147 dollars a month whether anyone uses them or not. The lines cross at about 79 million requests a month, around 30 a second on average. Below that, functions are cheaper, often much cheaper. Above it, servers or containers win. And remember the work you do not do: no patching, no scaling, no capacity planning.
API gateways
A gateway does what every API needs before your code runs
An API gateway authenticates, throttles, validates, routes and caches; bad requests are rejected before they cost compute.
Every API needs the same chores done. An API gateway does them in front of your code. It checks who is calling: an API key, a token, or signed credentials. It limits how fast each client may call, so one client cannot take everything. It rejects malformed requests. It routes each path and method to a function, a container or any web service. And it can cache responses and reshape them. Know its limits as well: by default a request must be answered within twenty-nine seconds, so long work goes through a queue.
REST and HTTP APIs · Going deeper
REST API or HTTP API: pay for the features you use
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
Fargate and similar services run containers without servers to manage; choose containers over functions for long, steady or custom work.
Between your own servers and functions lies a range of choices. Containers on your own instances: you run the servers, their patching and sizing. Fargate: you hand over the servers; you still choose how tasks are placed and scaled. Services like App Runner, Cloud Run and Container Apps also handle the scaling: give them an image and they serve it. Functions take everything but the code. Containers keep what functions cannot offer: any language, any library, and no fifteen-minute limit.
Compute on three clouds · Going deeper
Functions, containers and Kubernetes, named on three clouds
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
A service is independent only if it owns its data; others reach it through its API or events, never its tables.
Splitting into services only helps if the services are truly separate. Here three services share one database. Change a table for orders, and cart and billing break too. They must be released together, which is a monolith with extra network calls. Instead, each service owns its data. Others ask through its API, or listen to its events. Now each can deploy, scale and even change its database without asking. Split along what the business does, so one team owns one capability end to end.
Monolith first
Microservices trade an organisation problem for a distributed one
Start with a modular monolith; split out services when teams or scaling needs demand it.
So when is a monolith the right answer? Often. With one or a few teams, a domain still being discovered, little platform experience, and parts that scale together, a well-structured monolith is simpler, faster to change and cheaper to run. Microservices pay off when many teams must ship without waiting for each other, or one part needs very different scale. The price is that every call becomes a network call that can be slow, fail or happen twice. Build clean modules first, and they become the services to split out when the time comes.
Lesson complete
You finished “Monoliths, microservices and serverless”
Nicely done.