Part 9 of 10
Microservices and serverless
- The most common way to split work across machines is clients and servers: clients send requests, usually over HTTP, and servers answer. One process can be a server for some calls and a client for others.
- This style was once called service-oriented architecture (SOA); microservices are a refined form of it.
- A microservice has one clear job (an object store, for example, only stores files), an API others call over the network, and one team that owns it. A complex app is broken into many such services, each with its own team. Microservices are used both in the cloud and on premises.
- Gains:
- each team can update its service without much coordination with other teams; - each service can get the hardware it needs; - the inner workings stay hidden behind the API, so the owners can change them freely.
- Each service usually keeps its own database instead of sharing one. A shared database would make its whole structure part of the API, so it could never change easily. And one service's heavy queries could slow down the others.
- Costs:
- many services add complexity; - testing one service needs all the services it depends on running too; - every service needs its own deployment, resource sizing, logging, monitoring, alerts, and on-call support. Orchestration tools such as Kubernetes give a common base for this work.
- Microservice APIs are hard to change. Clients expect certain fields; adding or removing a field can break them, and this often shows up late, in staging or production. Tools for describing APIs, such as OpenAPI and gRPC, help manage these contracts (a later chapter covers this).
- Microservices mainly fix a people problem: letting many teams move without waiting on each other. That is worth it in a big company. In a small company it is mostly overhead, and the simplest design is better.
- Serverless, or function as a service (FaaS), hands even more infrastructure work to the cloud vendor. Instead of you starting and stopping VMs, the provider assigns and frees hardware automatically as requests arrive.
- Serverless brings usage billing to running code: you pay only while your code runs and do not reserve machines ahead of time. This mirrors how cloud storage replaced planning disk space.
- Limits: caps on how long code may run, restricted runtimes, and slow cold starts the first time a function is called.
- The name misleads: your code still runs on servers, just possibly a different one each time. Some data products, such as cloud warehouses and hosted message logs, use "serverless" to mean they scale on their own and bill by use.
Cloud computing versus supercomputing
HPC (high-performance computing, or supercomputing) is another way to build large systems, with different goals:
| Supercomputer | Cloud | |
|---|---|---|
| Main use | Heavy science and maths jobs, like weather and climate models, molecule simulations, or solving equations | Always-on online services and business data that must stay available |
| When a node fails | The job saves checkpoints to disk; on a failure, stop the whole cluster, fix the node, and restart from the last checkpoint | Keep serving; stopping is not an option |
| Trust and links | Users trust each other, and nodes share memory over very fast direct links (RDMA) | Strangers share hardware, so it needs isolation (VMs), encryption, and logins |
| Network | Special layouts, like multi-dimensional meshes, tuned to known traffic patterns | IP and Ethernet in layouts built for high total bandwidth between all parts |
| Location | Nodes sit close together | Can span many regions |