Home / Insights / Architecture and Modernization
Architecture and Modernization
Node.js Backend Architecture for Growing Products: Monolith, Modules and Queues
Most Node.js products start as a single Express or NestJS app and work well until they do not: slow endpoints, tangled code and risky deployments. This guide explains how to grow the architecture in stages, using modules and queues before reaching for microservices.
TopicsArchitecture and ModernizationWeb and SaaS Development
Key takeaways
- Most growing Node.js products are better served by a well-structured modular monolith than by an early move to microservices.
- Module boundaries only work if they are enforced: public interfaces, owned data and automated dependency checks.
- Node.js runs your JavaScript on a single event loop, so CPU-heavy and slow work belongs in queues and workers, not in request handlers.
- Extract a service only when a module has a clear reason: different scaling, release cadence, team ownership or security boundary.
- Run production on Active or Maintenance LTS Node.js releases, and invest in tracing and queue monitoring before splitting anything.
On this page
- What actually goes wrong as a Node.js backend grows
- Three shapes for a Node.js backend
- Building a modular monolith in Node.js
- Keeping the event loop free: queues and workers
- When to extract a service, and how
- Operating a growing Node.js backend
- A staged roadmap, costs and checklist
- Frequently asked questions
- Sources and methodology
A typical story: a startup ships its first product on a single Node.js application, often Express or NestJS with PostgreSQL. Two years later it has more customers, more developers and more features. Endpoints that once returned in milliseconds now time out when someone runs an export. A change to billing breaks notifications. Every deployment feels risky. Someone suggests microservices.
This article is for CTOs, technical founders and engineering leads deciding how to evolve a Node.js backend without stopping feature work. I will argue for a staged approach: structure the monolith into modules, move slow work onto queues, and extract services only when there is a specific reason. If you need extra hands for that work, our Node.js developers work in TypeScript with Express or NestJS, PostgreSQL, Redis and Kafka, and join your repositories and review process rather than working in isolation.
What actually goes wrong as a Node.js backend grows
Before choosing an architecture, be precise about the problem. In our experience, growing Node.js backends hit four distinct issues, and each has a different fix.
- Latency spikes and timeouts. Usually caused by CPU-heavy work or long-running operations inside request handlers: PDF generation, large JSON transforms, image processing, report exports or synchronous calls to slow third-party APIs.
- Tangled code. Any file can import any other, so a change in one area has unexpected effects elsewhere. Tests become slow and brittle.
- Risky deployments. Every change ships the whole application, and there is no way to release one area without retesting everything.
- Team friction. Several developers or squads edit the same files, causing merge conflicts and unclear ownership.
Only the last two are partly solved by splitting into services, and even then only if the boundaries are right. Latency problems are usually solved by queues and workers. Tangled code is solved by modular structure. Moving tangled code into separate services without fixing the boundaries simply gives you a distributed tangle, with network calls where function calls used to be.
Action: list your top five production pain points from the last quarter and label each as latency, coupling, deployment risk or ownership. The labels tell you which section of this article matters most.
Three shapes for a Node.js backend
There is a spectrum, not a binary choice. Martin Fowler’s well-known MonolithFirst essay argues that most new systems should start as a monolith because good service boundaries are hard to draw before you understand the domain. That still matches what we see in practice.
| Shape | What it looks like | Strengths | Costs and risks |
|---|---|---|---|
| Unstructured monolith | One app, folders by technical layer (routes, controllers, models), any file imports any other | Fast to start, simple to deploy | Coupling grows with every feature; hard to change safely |
| Modular monolith | One deployable app, code organised by business module with enforced public interfaces and owned data | Clear boundaries, one deployment, easy refactoring, simple local development | Needs discipline and tooling to keep boundaries intact |
| Services | Several deployable apps communicating via HTTP, gRPC or messages | Independent scaling and releases, team autonomy, isolation | Network failures, distributed data, more infrastructure, harder debugging and testing |
For most products with one to four backend teams, the modular monolith offers the best balance. It addresses coupling and ownership without the operational cost of distributed systems, and it keeps the option to extract services later along boundaries that have already proved themselves.
Action: record your decision and the reasons in an architecture decision record, including what would make you revisit it.
Building a modular monolith in Node.js
A modular monolith is not just a folder structure. It is a set of rules about what each module owns and how others may use it.
Organise by business capability
Group code by domain (accounts, billing, catalogue, orders, notifications) rather than by technical layer. Each module contains its own routes or controllers, services, data access and tests. NestJS supports this directly: its module system lets a feature module encapsulate its providers and expose only what it lists in its exports. In Express, the same can be achieved with a folder per module and an explicit index file that defines the public interface.
Define public interfaces
- Other modules call a module only through its exported service functions or classes, never by reaching into its internals.
- Pass plain data objects across module boundaries, not ORM entities that drag internal structure along.
- Prefer a small number of coarse operations (‘place order’) over many fine-grained ones that leak internal steps.
Own your data
Each module owns its tables. Other modules do not query them directly; they ask the owning module or listen to its events. You can keep one PostgreSQL database, ideally with a schema per module, which makes later extraction much easier.
Enforce boundaries automatically
Rules that rely on code review alone erode within months. Add dependency checks in CI (for example, lint rules or a dependency-graph tool) that fail the build when one module imports another’s internals. In a TypeScript monorepo, separate packages with explicit dependencies achieve the same effect.
Use in-process events for side effects
When an order is placed, billing and notifications may need to react. Rather than the orders module calling each directly, publish a domain event that subscribers handle. Start with an in-process event bus; move to a durable queue when the side effect is slow or must survive a crash.
Action: pick the module causing the most cross-team conflicts, define its public interface and data ownership, and add a CI rule that enforces it. Use that as the template for the rest.
Keeping the event loop free: queues and workers
The Node.js documentation on not blocking the event loop explains the core constraint: JavaScript callbacks run on a single event loop thread, so while one request does heavy work, others wait. It warns against synchronous file, crypto and compression APIs in servers, vulnerable regular expressions, and very large JSON parsing, and it recommends either partitioning work into small chunks or offloading it to worker threads or separate processes. It also notes that if a server is dominated by heavy computation, Node.js may not be the right tool for that part.
What to move off the request path
- Report and export generation, PDF and image processing.
- Sending emails, SMS and push notifications.
- Calls to slow or rate-limited third-party APIs, such as payment reconciliation or CRM sync.
- Webhook processing that triggers further work.
- AI or document-processing calls that can take seconds.
How a queue-based flow works
- The API validates the request, records the intent in the database and enqueues a job with a unique ID.
- It returns quickly with a status, for example 202 Accepted and a job reference.
- A worker process picks up the job, performs the work and records the result.
- The client polls, receives a webhook or gets a push notification when the job completes.
In the Node.js ecosystem, BullMQ is a common Redis-backed choice, supporting retries with backoff, delayed jobs, rate limiting, per-worker concurrency and parent-child job flows. Cloud-managed queues such as Amazon SQS or Google Cloud Pub/Sub are alternatives that remove the need to operate Redis yourself. For high-volume event streams shared across many consumers, Kafka is a different tool with a different operating cost.
Design jobs to be safe to retry
BullMQ’s documentation is explicit that delivery is at-least-once, so a job can run more than once after a crash. Make every job idempotent: check whether the work was already done, use idempotency keys with external APIs, and store results in a way that tolerates duplicates.
Action: instrument event loop lag and endpoint latency, identify the three slowest operations on the request path, and move them to a queue first.
When to extract a service, and how
With a modular monolith and queues in place, many teams find they no longer need microservices. Some modules, though, do benefit from becoming separate deployables. Extract only when at least one of these is true:
- Different scaling profile: the module needs far more compute or memory than the rest, or scales on a different signal (queue depth instead of request rate).
- Different release cadence: it changes much more or less often than the rest, and coupling the releases slows one side down.
- Clear team ownership: a dedicated team owns it end to end and is blocked by shared releases.
- Security or compliance boundary: it handles payment, health or identity data that benefits from isolated access and audit.
- Different technology need: the work suits another runtime, for example CPU-heavy processing in Go or Python machine learning.
How to extract safely
- Confirm the module already has a clean public interface and owns its data inside the monolith.
- Move its schema to a separate database or instance, keeping data synchronised during the transition if needed.
- Deploy the module as a separate service behind the same interface, initially called from the monolith through an adapter.
- Route traffic gradually, with monitoring and a rollback path.
- Remove the old in-process code once the new service is stable.
This is a small-scale version of the approach described in our article on modernising a monolith with the strangler fig pattern, including the cost of running old and new paths side by side for a period.
Action: for any proposed extraction, write down which of the reasons above applies and what measurable outcome you expect. If you cannot, keep it in the monolith.
Operating a growing Node.js backend
Architecture choices fail without operational basics. Three areas matter most.
Runtime versions
The Node.js project states on its releases page that production applications should only use Active LTS or Maintenance LTS releases. At the time of writing, Node.js 22 is the Active LTS line, Node.js 20 is in maintenance, and Node.js 24, first released in May 2025, is a Current release that is not yet LTS. Plan upgrades as routine work every year rather than as a crisis when a version reaches end of life.
Observability
- Distributed tracing across API, queue and worker, so a slow job can be traced back to the request that created it. Our guide to observability with OpenTelemetry covers a vendor-neutral approach.
- Metrics for event loop lag, memory, queue depth, job duration and failure rates.
- Structured logs with request and job IDs.
- Alerts on queue backlogs and dead-letter growth, not just HTTP errors.
Deployment
Run API and worker processes as separate deployments from the same codebase, so they can scale independently. This alone gives much of the scaling benefit people expect from microservices. Use containers and infrastructure as code so environments are reproducible, and keep database migrations backward-compatible so you can deploy without downtime.
Action: check which Node.js version each environment runs today and schedule any upgrade off a non-LTS or soon-to-expire line.
A staged roadmap, costs and checklist
The staged approach lets you keep shipping features while improving structure. As an illustrative sequence for a product with a single Node.js app and growing pains:
- Stabilise (weeks 1 to 4): add tracing, event loop and latency metrics; move the worst slow operations onto a queue with separate worker processes.
- Modularise (months 2 to 4): define business modules, public interfaces and data ownership; add CI boundary checks; refactor the most conflicted areas first.
- Harden (ongoing): idempotent jobs, dead-letter handling, backward-compatible migrations, LTS upgrades.
- Extract selectively (when justified): move a module to its own service only when one of the extraction reasons clearly applies.
Timelines depend on codebase size and team capacity; treat these as planning assumptions, not estimates.
Costs and risks
- Refactoring competes with feature work. Reserve a fixed share of each sprint rather than pausing the roadmap.
- Queues add infrastructure (Redis or a managed queue) and new failure modes that need monitoring.
- Premature extraction multiplies hosting, CI and on-call costs. Each service needs its own pipeline, monitoring and security review.
Architecture checklist
- Production pain points labelled as latency, coupling, deployment or ownership.
- Code organised by business module with explicit public interfaces.
- Each module owns its tables; no cross-module queries.
- Boundary rules enforced automatically in CI.
- No synchronous heavy work on the request path; slow work queued.
- Jobs idempotent, with retries, backoff and dead-letter handling.
- API and workers deployed and scaled separately.
- Tracing across API, queue and workers; alerts on queue backlog.
- Node.js on an Active or Maintenance LTS release.
- Service extractions justified in writing with expected outcomes.
Frequently asked questions
Should a startup begin with microservices in Node.js?
Usually not. A single, well-structured application is faster to build and change while you learn the domain. Design it as a modular monolith so you can extract services later along proven boundaries.
Is NestJS required for a modular monolith?
No. NestJS has a built-in module system that makes boundaries explicit, but the same structure works in Express or Fastify with clear folder conventions, explicit index files and automated dependency checks.
When should we use worker threads instead of a queue?
Worker threads suit CPU-heavy work that must finish within the same request and can run on the same machine. Queues suit work that can complete later, needs retries, or should scale on separate infrastructure.
Do we need Kafka for background jobs?
Rarely for ordinary background jobs. A Redis-backed queue or a managed cloud queue is simpler for task processing. Kafka fits high-volume event streams consumed by many independent systems.
How do we know when the monolith is too big?
Look for symptoms rather than size: teams blocked by each other’s releases, a module with a very different scaling or security profile, or deployment risk that modular structure has not reduced.
Sources and methodology
Guidance reflects PoliteTech delivery experience. The external references below informed specific points in this article.
- Node.js: Don’t Block the Event Loop (or the Worker Pool) — accessed 9 November 2026. Single event loop constraint, APIs to avoid in servers, partitioning versus offloading.
- Node.js: Previous releases — accessed 9 November 2026. Production guidance to use Active or Maintenance LTS, and release dates for Node.js 20, 22 and 24.
- Martin Fowler: MonolithFirst (2015) — accessed 9 November 2026. Argument for starting with a monolith before drawing service boundaries.
- NestJS documentation: Modules — accessed 9 November 2026. Feature modules, encapsulation and exports as public interfaces.
- BullMQ documentation — accessed 9 November 2026. Redis-backed queue features and at-least-once delivery requiring idempotent jobs.
- PoliteTech: Hire Node.js Developers — accessed 9 November 2026. PoliteTech’s Node.js skills and engagement models.
Related reading
Continue your research
Is your Node.js backend ready for the next stage of growth?
Tell us where your backend hurts today. We can review the structure, suggest a staged plan and provide Node.js engineers to carry it out alongside your team.
