Microservices & Containers in the Cloud
Split applications into independently deployable services and run them in containers on managed platforms. Learn the trade-offs and a practical Node.js service example.
Monolith vs Microservices
A monolith ships as a single deployable unit — simple to build and debug at first, but harder to scale teams and releases as it grows.
Microservices split the system into small services that each own one capability and their own data, communicating over HTTP or messages. Teams can deploy and scale services independently.
A Small Node.js Service
Each service exposes a focused API plus a health endpoint that the platform uses to know when it is ready:
import express from "express";
const app = express();
app.use(express.json());
const orders = new Map();
app.get("/health", (_req, res) => res.json({ status: "ok" }));
app.post("/orders", (req, res) => {
const id = String(orders.size + 1);
const order = { id, items: req.body.items ?? [], status: "created" };
orders.set(id, order);
res.status(201).json(order);
});
app.get("/orders/:id", (req, res) => {
const order = orders.get(req.params.id);
if (!order) return res.status(404).json({ error: "Not found" });
res.json(order);
});
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`orders-service on ${port}`));Containerizing the Service
A multi-stage Dockerfile produces a small, reproducible image that runs the same on a laptop and in the cloud:
FROM node:20-alpine AS deps
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
FROM node:20-alpine
WORKDIR /app
ENV NODE_ENV=production
COPY --from=deps /app/node_modules ./node_modules
COPY . .
USER node
EXPOSE 3000
HEALTHCHECK CMD wget -qO- http://localhost:3000/health || exit 1
CMD ["node", "server.js"]Where to Run Containers
Managed platforms handle scheduling, scaling and recovery for you:
- AWS ECS / Fargate — Run containers without managing servers.
- Kubernetes (EKS, AKS, GKE) — Maximum flexibility and ecosystem.
- Cloud Run / App Runner — Deploy a container image and get an HTTPS endpoint.
Operating Microservices Well
Distributed systems add complexity. Plan for it from the start:
- Give each service its own data store; avoid shared databases.
- Add timeouts, retries and circuit breakers on every network call.
- Centralize logs, metrics and distributed traces.
- Automate builds and deployments with CI/CD.
- Start with a well-structured monolith unless you truly need independent scaling.
Key Takeaways
- Microservices trade simplicity for independent deployment and scaling.
- Containers package services so they run identically everywhere.
- Managed platforms like Fargate and Cloud Run remove cluster operations.
- Observability and resilience patterns are essential in distributed systems.
Contact Us
Have a question or feedback? Fill out the form below or reach us directly at support@nvaitraining.com