Architecture style
Monolith vs microservices vs serverless
A comparison of three approaches by cost, team size, deploys, scaling, data consistency, debugging and latency. Plus a simple decision path.
Cost and team size
A monolith is the cheapest to start: a few VPS or containers and one database, all run by one or two engineers. Microservices are almost always more expensive: each service has its own copies, database and monitoring, plus you need Kubernetes, a broker and tracing. Serverless costs nearly nothing at low traffic, but under steady high load it often becomes the most expensive.
For team size, a rough guide: a monolith is comfortable up to 10 or 15 engineers, a modular monolith up to a few dozen, and microservices pay off when there are many teams, each owning its domain. Serverless is especially good for small teams without DevOps.
Deploys and scaling
A monolith deploys as a whole: a simple pipeline, but all releases go in one stream. Microservices deploy independently, dozens of times a day, but need CI/CD per service and contract tests between them. In serverless, deploying one function takes seconds.
A monolith scales by copying the whole application. Microservices scale only the hot services. Serverless scales automatically per invocation, from zero to thousands of parallel executions, but with concurrency limits and cold starts.
Data consistency, debugging and latency
A monolith has one database and ACID transactions. In microservices and serverless data is spread across stores, so consistency becomes eventual, with sagas and idempotency.
Debugging a monolith: one process, one call stack, a breakpoint in the IDE. In microservices, without distributed tracing, finding the cause of an error is very hard. Serverless adds the difficulty of reproducing events locally.
Latency: a call inside a process costs nanoseconds, a network call between services about 1 ms within a data center, a function cold start from tens of milliseconds to a second. A chain of 5 network calls easily adds 10 to 30 ms to a response.
Decision path
Start with a modular monolith: one deploy, clear modules, separate data schemas. It is the cheapest way to learn where the real domain boundaries are.
Extract a module into a service when there is a concrete reason: a separate team keeps getting blocked by the shared release, the module has very different load or availability needs, or it needs a different technology. Do not split «for future growth».
Use serverless selectively for spiky and event workloads: processing uploaded files, webhooks, cron, uneven APIs. This way ShortLesson can keep its main app in a container and hand video transcoding to functions.
Pros
- Monolith: the cheapest, easiest to debug, ACID transactions.
- Microservices: independent teams and deploys, targeted scaling.
- Serverless: zero idle cost, autoscaling without DevOps.
Cons
- Monolith: large teams get in each other's way, scales only as a whole.
- Microservices: expensive operations, eventual consistency, hard debugging.
- Serverless: cold starts, limits, vendor lock-in, more expensive under steady load.
When to choose it
- Start with a modular monolith unless you have a very strong reason not to.
- Extract a service when a separate team or a separate load profile truly requires it.
- Move to microservices when there are many teams and the platform for them exists.
- Use serverless for spiky, event driven and background work.
- Go back to a simpler setup if the complexity does not pay off (as Segment and Prime Video did).
Where it is used
- Shopify: a modular monolith instead of splitting into services.
- Netflix: microservices on AWS for hundreds of independent teams.
- Segment (2018) and Amazon Prime Video (2023): public examples of moving back to a simpler architecture.
Tools
- DockerDocker packages an application with its dependencies into a container that runs the same on a laptop, a server and the cloud.
- KubernetesKubernetes is a container orchestration system that deploys, scales and heals applications across a cluster of servers.
- AWS LambdaAn AWS service that runs functions in response to events and bills only for execution time.
- Cloudflare WorkersA serverless platform on Cloudflare's edge: V8 isolate code starts almost instantly worldwide.
- Google Cloud RunManaged container hosting that autoscales to zero and bills per use.
- Apache KafkaKafka is a distributed event log for high-throughput data streaming with durable storage.
Related topics
Sources
Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).