Production quality starts with boundaries

A production-grade backend is a system whose behavior remains understandable under invalid input, concurrent requests, dependency failures, migrations, and operational pressure. Framework choice matters less than explicit contracts, controlled state transitions, durable persistence, and observable failure paths.

Layers with a job to do

  • Transport code parses HTTP; it should not own business policy.
  • Application services coordinate use cases and transactions, while domain code protects invariants.
  • Repositories hide persistence details without becoming a dumping ground for business rules.
  • Adapters isolate email, payment, core-system, and storage contracts from the application.
  • Structured logs, metrics, traces, health checks, and audit events are part of the implementation.

A write request through the backend

Each boundary narrows responsibility: validate transport, authorize the use case, enforce domain rules, persist atomically, then trigger controlled side effects.

Diagram

Write request with explicit responsibilities

Each boundary narrows responsibility: validate transport, authorize the use case, enforce domain rules, persist atomically, then trigger controlled side effects.

Designing an account update safely

Let one application service own the transaction

The use case coordinates authorization-independent business work and leaves transport mapping outside.

change-risk.tstypescript
await db.transaction(async (tx) => {
  const customer = await customers.getForUpdate(tx, customerId);
  customer.changeRiskLevel(nextLevel);
  await customers.save(tx, customer);
  await audit.append(tx, { action: 'customer.risk.changed', customerId });
});

Backend smells that predict incidents

Release-readiness checklist

  • Define use-case boundaries and transaction ownership.
  • Keep domain invariants independent from HTTP and ORM details.
  • Classify business, validation, authorization, dependency, and internal errors.
  • Make external side effects resilient and idempotent.
  • Ship logs, metrics, migrations, health checks, and runbooks with the feature.