Architecture

5 min read

November 22, 2026

Node.js microservices architecture: a practical guide

How to structure Node.js microservices that stay independent: boundaries around data, sync calls versus events, idempotent consumers, Express vs NestJS vs Fastify, failure handling and operations.

By Parth Patel

Node.js is a natural fit for microservices: it starts fast, handles many concurrent I/O-bound requests well, and lets a TypeScript team share types between services. It is also easy to build a distributed monolith with it: dozens of services that must be deployed together, call each other synchronously, and fail together.

This guide covers how to structure a Node.js microservices architecture so the services stay independent: where to draw boundaries, how they should communicate, which framework to use, and what operations you need on day one.

Draw boundaries around data, not code

The most important microservice decision is where one service ends and the next begins. Good boundaries follow business capabilities and data ownership:

  • Orders owns orders and their state transitions.
  • Inventory owns stock levels and reservations.
  • Billing owns invoices and payments.

Each service has its own database (or at least its own schema that no other service touches). If two services need to write the same table, they are one service.

A useful test: can you describe what the service does in one sentence without the word "and"? "Manages user notifications" passes. "Handles users and orders and emails" does not.

Choose the communication style per interaction

Services talk in two ways, and most systems need both.

Synchronous (HTTP or gRPC) when the caller needs an answer now: "is this coupon valid?" Keep these calls few and shallow. A request that fans out through four services is four times as likely to fail and as slow as the slowest one.

Asynchronous (events or messages) when the caller only needs to announce that something happened: "order placed". Other services react in their own time. This removes temporal coupling: Billing can be down for a minute without blocking checkout.

A rule of thumb: commands that need a result go synchronously; facts about what already happened go as events. For choosing the broker, see Kafka vs RabbitMQ.

Make every consumer idempotent

Message brokers deliver at least once. Networks retry. Users double-click. Every handler that changes state must be safe to run twice.

The simplest approach is to record which messages you have processed, in the same transaction as the change:

TypeScriptTypeScript
async function handleOrderPlaced(event: OrderPlaced, db: Db) {
  await db.transaction(async (tx) => {
    const inserted = await tx.query(
      `INSERT INTO processed_messages (id) VALUES ($1) ON CONFLICT DO NOTHING`,
      [event.id],
    );
    if (inserted.rowCount === 0) return; // already handled

    await tx.query(
      `UPDATE inventory SET reserved = reserved + $2 WHERE sku = $1`,
      [event.sku, event.quantity],
    );
  });
}

Pair this with a transactional outbox on the producer side: write the business change and the outgoing event in one database transaction, and publish from the outbox table with a separate relay. Then a crash can never leave the database updated but the event unsent.

Express, NestJS or Fastify?

All three run well in production. The choice is about your team and codebase:

  • Express is minimal and familiar. Good for small services, but you assemble structure yourself.
  • NestJS adds modules, dependency injection and conventions. It pays off in larger codebases and teams, where consistency across services matters.
  • Fastify is fast and has first-class JSON schema validation, which doubles as documentation.

Whichever you pick, use it consistently across services, and share a small internal package for logging, configuration, error handling and tracing, so every service behaves the same way in production.

Handle failure explicitly

In a distributed system, partial failure is normal. Design for it:

  • Timeouts on every outbound call. A call without a timeout can hold a request open indefinitely.
  • Retries with backoff and jitter, only for idempotent operations.
  • Circuit breakers around flaky dependencies, so a slow downstream service doesn't exhaust your connection pool.
  • Dead-letter queues for messages that keep failing, with an alert and a way to replay them after a fix.

For workflows that span services, such as order, payment and shipment, use a saga: a sequence of local transactions with compensating actions when a later step fails (release the reservation, refund the payment).

Contracts and versioning

Services evolve independently only if their contracts are explicit:

  • Publish OpenAPI or JSON schemas for HTTP APIs and event payloads.
  • Make additive changes (new optional fields) without a new version; never rename or remove a field that consumers use.
  • When a breaking change is unavoidable, run both versions side by side until every consumer has moved.

Consumer-driven contract tests catch breaking changes in CI, before they reach production.

Operations from day one

Microservices multiply operational surface. Before the second service ships, have:

  • Structured logs with a correlation ID passed through every call and message.
  • Distributed tracing (OpenTelemetry), so a slow request shows which service and query cost the time.
  • Health checks and readiness probes for orchestration.
  • One pipeline per service: build, test, container image and deploy, independently.
  • Per-service dashboards for error rate, latency and queue lag.

Containers and a managed orchestrator (Kubernetes, ECS or similar) handle deployment and scaling; the important part is that each service can be released on its own.

When not to use microservices

If you have one team, one product and an uncertain domain, start with a modular monolith in Node.js: the same module boundaries, one deployable. You keep the discipline without paying the distributed-systems tax, and you can extract services later along boundaries that have proven themselves. The SaaS architecture guide describes that path.

Summary

A healthy Node.js microservices architecture comes down to a few habits:

  1. Boundaries around business capabilities, each service owning its data.
  2. Synchronous calls for answers, events for facts.
  3. Idempotent consumers and a transactional outbox.
  4. Timeouts, retries, circuit breakers and dead-letter queues.
  5. Explicit, versioned contracts.
  6. Tracing, logging and independent pipelines before the system grows.

Next step

Working on something like this? Let’s talk it through.

Send a short brief. You’ll get a written reply from me within two business days — either a few clarifying questions, a suggested first step, or an honest “I’m not the right fit” with a pointer elsewhere.

Parth Patel

Senior full-stack engineer