Architecture
Monolithic Architecture for Startups: A Practical Playbook
Most startups do not fail because their architecture could not scale. They fail because they shipped too slowly to find customers. Architecture choices that slow a five-person team down are a real business risk, even when they look impressive on a diagram.
A monolith is the architecture that lets a small team move fastest. This post is a practical playbook for building one that stays pleasant to work in as you grow, from day one through your first few million users.
If you are still deciding between a monolith and microservices, start with Monolith vs Microservices. This post assumes you have picked the monolith and want to do it well.
What a monolith actually is
A monolithic application is one codebase, built and deployed as a single unit. Every feature (sign-up, payments, dashboards, emails) lives in the same repository and ships in the same release. It usually talks to one primary database.
That does not mean one giant file or a single server forever. A good monolith has clear internal structure, can run on several machines behind a load balancer, and can have separate processes for web traffic and background jobs. What makes it a monolith is that it is built and released as one thing.
Plenty of well-known products have run on monoliths for years. Basecamp's founders have written publicly in defence of what they call the "majestic monolith", and Stack Overflow's engineering team has described serving huge traffic from a largely monolithic .NET application. It is a deliberate choice, not a beginner's mistake.
Why it fits a startup
Speed of change. Early product work cuts across features. Adding "team accounts" touches sign-up, billing, permissions and emails. In a monolith that is one branch, one pull request, one deploy.
Real transactions. Creating an order and recording the payment happens in one database transaction. Either both succeed or neither does. No sagas, no reconciliation jobs.
One thing to run. One pipeline, one set of logs, one dashboard, one on-call runbook. A two-person team can genuinely own production.
Lower cloud bills. A monolith on two modest servers plus a managed database is often a fraction of the cost of a cluster of services, each with its own instances, load balancer and data store.
Easier hiring and onboarding. A new engineer clones one repo, runs one command and has the whole product on their laptop.
Easy refactoring. Your IDE can rename a function across the whole product, and the compiler tells you what broke. Across service boundaries, you find out in production.
The real risk: the big ball of mud
The monolith's reputation problem is not the architecture. It is what happens without rules: every file imports every other file, every table is queried from everywhere, and nobody dares change anything. The fix is a handful of ground rules, applied from the first week.
Rule 1: Organise by feature, not by layer
The default structure many frameworks generate groups code by technical layer: all controllers together, all services together, all models together. That works for ten files and falls apart at five hundred.
Group by business capability instead. Here is a NestJS layout we use often:
src/
modules/
accounts/
accounts.module.ts
accounts.controller.ts
accounts.service.ts
entities/
billing/
billing.module.ts
billing.service.ts
stripe.client.ts
orders/
notifications/
shared/ # logging, config, db connection, auth guards
main.ts # web entrypoint
worker.ts # background job entrypoint
When someone asks "where is the billing logic?", there is one answer. Each module exports only what other modules need and keeps the rest private.
Rule 2: One database, clear ownership
Keep one database. It is one of the biggest advantages you have. But give every table an owner.
In Postgres, a simple way to make ownership visible is a schema per module:
CREATE SCHEMA accounts;
CREATE SCHEMA billing;
CREATE SCHEMA orders;
CREATE TABLE billing.invoices (
id uuid PRIMARY KEY,
account_id uuid NOT NULL,
amount_cents integer NOT NULL,
created_at timestamptz NOT NULL DEFAULT now()
);
The rule: only billing code reads or writes billing.*. If orders needs an invoice, it calls the billing service, not the table. In MongoDB, the same idea applies with collection prefixes or one repository class per module.
You still get joins and transactions when you genuinely need them. You just stop every corner of the codebase from depending on every table's exact shape.
Rule 3: Use in-process events for side effects
When an order is placed, you might send an email, update analytics and notify the warehouse. If the orders module calls all of those directly, it ends up knowing about everything.
Publish an event instead and let other modules react. In NestJS, @nestjs/event-emitter does this in-process with no infrastructure:
// orders/orders.service.ts
import { Injectable } from "@nestjs/common";
import { EventEmitter2 } from "@nestjs/event-emitter";
export class OrderPlacedEvent {
constructor(public readonly orderId: string, public readonly accountId: string) {}
}
@Injectable()
export class OrdersService {
constructor(private readonly events: EventEmitter2) {}
async placeOrder(accountId: string, items: string[]) {
const order = await this.saveOrder(accountId, items);
this.events.emit("order.placed", new OrderPlacedEvent(order.id, accountId));
return order;
}
private async saveOrder(accountId: string, items: string[]) {
// persist to orders.* tables
return { id: crypto.randomUUID(), accountId, items };
}
}
// notifications/order-placed.listener.ts
import { Injectable } from "@nestjs/common";
import { OnEvent } from "@nestjs/event-emitter";
import { OrderPlacedEvent } from "../orders/orders.service";
@Injectable()
export class OrderPlacedListener {
@OnEvent("order.placed")
async handle(event: OrderPlacedEvent) {
// queue the confirmation email
}
}
Register EventEmitterModule.forRoot() once in your root module. Orders no longer knows that notifications exist. If you later move notifications into its own service, you swap the in-process event for a message on a queue and the orders code barely changes.
Rule 4: One codebase, more than one process
A monolith does not mean everything runs inside the web server. Slow work (emails, PDF generation, imports, AI calls) belongs in background jobs so web requests stay fast.
Keep the job code in the same repository and start it with a different entrypoint:
node dist/main.js # serves HTTP traffic
node dist/worker.js # processes jobs from the queue (e.g. BullMQ on Redis)
Same code, same models, same tests, deployed together. You can scale web and worker processes independently, which solves most of the "different load" problems people reach for microservices to fix.
Rule 5: Make deploys boring
Because everything ships together, a bad deploy affects everything. Make releasing small and frequent rather than big and scary:
- Deploy on every merge to main through CI, with automated tests as the gate.
- Use feature flags to merge unfinished work safely and switch features on per customer.
- Run database migrations that are backward compatible: add the new column, deploy code that writes to both, then remove the old column in a later release.
- Roll out with zero downtime using rolling or blue-green deploys across two or more instances.
Rule 6: Enforce boundaries with tools
Good intentions erode under deadlines. Add a lint rule (ESLint's no-restricted-imports or dependency-cruiser) that fails the build when one module imports another module's internal files. It costs an hour to set up and saves months of untangling.
How far can a monolith scale?
Much further than most startups will need. The usual progression:
| Stage | What the setup looks like |
|---|---|
| Launch | One app server, one managed database, daily backups |
| First traction | Two app instances behind a load balancer, a worker process, Redis for cache and queues |
| Growing fast | Autoscaled app and worker instances, read replicas, CDN for static assets |
| Large scale | Bigger database instances, heavier caching, and extracting a service only where one part clearly needs it |
Each step is covered in more depth in Vertical vs Horizontal Scaling and Why Your App Needs Caching. Notice that none of them require breaking the monolith apart.
Signs you have outgrown parts of it
Watch for concrete pain, not theoretical future scale:
- Several teams constantly block each other's releases.
- One feature needs very different hardware, such as GPUs for model inference.
- One area needs stricter isolation for compliance, such as card payments.
- Build and test times have grown so long that engineers wait more than they code, even after optimising the pipeline.
When one of these appears, extract that one module into a service. Thanks to the boundaries above, it is a contained project rather than a rewrite.
The takeaway
For a startup, a monolith is not a compromise. It is the fastest, cheapest, most reliable way to ship and learn. The trick is discipline: organise by feature, give every table an owner, use events for side effects, run background work in separate processes, and enforce boundaries with tooling. Do that, and your monolith will carry you a long way, and give you clean seams to split along if you ever need to.
Starting a new product or untangling a monolith that has grown messy? Talk to us about setting up an architecture your team can move fast in.