A Production MVP Architecture Explained
A production MVP needs six parts: a client with no authority, one API that enforces every rule, an auth provider, a database with constraints, a worker for slow jobs, and alerts with backups.
5 min read / Updated / Last checked
- Format
- Diagram · Beginner
- Who it is for
- Non-technical founders
- You leave with
- Read an MVP architecture diagram, name what each component owns, and ask where each business rule is enforced.
The problem
The 2023 edition of the OWASP API Security Top 10 puts broken object level authorization first: an endpoint accepts an object ID and does not check that the caller may access that object [1]. It is a coding bug, and also an architecture gap. It appears when nobody decided which component is responsible for the check.
AI builders often generate apps where the browser talks to the database directly, protected by row-level security policies. That can work. Supabase's documentation is explicit about the conditions: enable row-level security on every table in an exposed schema, and keep the secret key, which bypasses those policies, off the client [2]. Trouble starts when the product grows a payment, a confirmation email or a write that spans three tables. Rules spread across browser code, database policies and third-party dashboards, and nobody can say where a given rule lives.
A founder does not need to design the system. A founder needs to read the diagram and ask one question of every box: which business rules does this enforce, and what happens if it fails?
How it works
Six components, deployed as one service with one database to start.
- Client. The browser or mobile app. It shows data and collects input. It holds no secrets and enforces nothing, because a user controls everything that runs on it.
- API. The only path that changes business state. It verifies the session, checks that the caller may act on this record, validates input, applies business rules and writes in a transaction.
- Auth provider. Issues and verifies identity: passwords, magic links, social login. It answers who is calling. The API answers whether they may do this.
- Database. The source of truth. Unique constraints, foreign keys and transactions make some rules impossible to break, even by buggy code. Row-level security adds a second wall if any client reaches tables directly. PostgreSQL is a common default: 55.6% of respondents to Stack Overflow's 2025 survey used it [3].
- Worker and queue. Sends email, calls AI models, generates reports and retries failures, outside the user's request. The API records each job in an outbox table in the same transaction as the business write, and the worker picks it up later. AWS describes this transactional outbox pattern as the fix for dual writes, where the database write succeeds and the notification fails, or the reverse [4]. A worker can deliver a message twice, so consumers must be idempotent: running them twice has the same effect as once [4]. Calls to providers such as Stripe carry an idempotency key so a retry cannot charge twice [5].
- Observability and recovery. Error alerts that reach a person, logs without secrets, backups restored at least once and a rollback path for deploys.
Ship all of it as one service. Martin Fowler observed in 2015 that almost all successful microservice stories started with a monolith that grew too big and was split later [6]. Clear internal modules keep the code organized without the operating cost of separate services. See Single Service vs. Microservices for when a split pays off.
Production MVP: six components, one deployable
Fig. 01- Clientno secrets, no authority
- APIsession, ownership, rules
- Auth provideridentity only
- Databaseconstraints, transactions, RLS
- Worker and queueoutbox, retries, email, AI
By the numbers
- broken object level authorization, first in the OWASP API Security Top 10 2023 [1]
- API1
- of Stack Overflow's 2025 respondents used PostgreSQL [3]
- 55.6%
- maximum characters in a Stripe idempotency key [5]
- 255
- minimum age before Stripe may prune an idempotency key, after which a reused key is a new request [5]
- 24 h
| Concern | Browser talks to the database | API in the middle |
|---|---|---|
| Where authorization lives | SQL policies on each table | API code, plus database constraints |
| Keys in the client | Publishable key only, secret key server-side | None |
| Multi-step write (booking, payment, email) | Client coordinates the steps | One transaction plus an outbox row |
| Main test | Policy tests for every table | Route tests with two users |
| Good fit | Per-user records, simple screens | Money, workflows, third-party calls |
The OWASP ranking says where the first failure usually lands: the check between a logged-in user and a record. The table says where that check can live. Both designs are valid. The browser-to-database design puts every rule in SQL policies, which is clean for per-user records and hard for a booking that must also charge a card and send an email. The API design keeps those steps in one place.
The Stripe figures show what a retry-safe design depends on. A key up to 255 characters identifies one logical request, and Stripe compares the parameters of a retry with the original and errors if they differ [5]. Keys may be pruned after 24 hours, so a job that retries days later must not count on the provider to deduplicate. Your own database has to remember.
Implementation
The booking flow below shows the API, the database and the outbox working together. The schema puts two business rules in the database, where buggy code cannot break them: one booking per slot, and one booking per retried request.
create table slots (
id uuid primary key default gen_random_uuid(),
starts_at timestamptz not null
);
create table bookings (
id uuid primary key default gen_random_uuid(),
owner_id uuid not null, -- set from the verified session only
slot_id uuid not null references slots(id),
idempotency_key text not null,
created_at timestamptz not null default now(),
unique (slot_id), -- one booking per slot
unique (owner_id, idempotency_key) -- a retried request cannot book twice
);
create table outbox (
id bigserial primary key,
topic text not null,
payload jsonb not null,
created_at timestamptz not null default now(),
sent_at timestamptz -- null until the worker delivers it
);import { Pool } from "pg";
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
// userId comes from the verified session, never from the request body.
export async function createBooking(userId: string, slotId: string, idempotencyKey: string) {
const client = await pool.connect();
try {
await client.query("BEGIN");
const inserted = await client.query(
`insert into bookings (owner_id, slot_id, idempotency_key)
values ($1, $2, $3)
on conflict (owner_id, idempotency_key) do nothing
returning id`,
[userId, slotId, idempotencyKey],
);
if (inserted.rowCount === 0) {
// Seen this request before: return the original booking, do nothing new.
const prior = await client.query(
"select id from bookings where owner_id = $1 and idempotency_key = $2",
[userId, idempotencyKey],
);
await client.query("COMMIT");
return { id: prior.rows[0].id as string, replayed: true };
}
const id = inserted.rows[0].id as string;
// The confirmation email is recorded in the same transaction, sent later by the worker.
await client.query("insert into outbox (topic, payload) values ($1, $2)", [
"booking.confirmed",
{ bookingId: id, userId },
]);
await client.query("COMMIT");
return { id, replayed: false };
} catch (err) {
await client.query("ROLLBACK");
throw err; // error code 23505 on slot_id means the slot is taken: answer 409
} finally {
client.release();
}
}The client sends a fresh idempotency key, such as a UUID, with each booking attempt and reuses it on retry. The route handler that calls this function reads userId from the session, never from the body, and maps a unique violation to a 409 response. A worker polls the outbox for rows where sent_at is null, sends the email, then sets sent_at. If the email provider is down, the booking still exists and the row waits for the next attempt. For retry timing and dead-letter handling, see Design for Failure: Retries, Queues and Idempotency.
Test it
Two rules in the schema deserve tests that run on every change: a retry returns the same booking, and two people racing for one slot cannot both win. Run them against a disposable test database seeded with two users and two free slots.
import { describe, it, expect } from "vitest";
import { randomUUID } from "node:crypto";
import { createBooking } from "./createBooking";
const ALICE = process.env.TEST_USER_A!;
const BOB = process.env.TEST_USER_B!;
const SLOT_RETRY = process.env.TEST_SLOT_1!;
const SLOT_RACE = process.env.TEST_SLOT_2!;
describe("booking rules hold under retries and races", () => {
it("a retried request returns the original booking", async () => {
const key = randomUUID();
const first = await createBooking(ALICE, SLOT_RETRY, key);
const retry = await createBooking(ALICE, SLOT_RETRY, key);
expect(retry.id).toBe(first.id);
expect(retry.replayed).toBe(true);
});
it("two users racing for one slot: exactly one wins", async () => {
const results = await Promise.allSettled([
createBooking(ALICE, SLOT_RACE, randomUUID()),
createBooking(BOB, SLOT_RACE, randomUUID()),
]);
expect(results.filter((r) => r.status === "fulfilled")).toHaveLength(1);
const lost = results.find((r) => r.status === "rejected") as PromiseRejectedResult;
expect(lost.reason.code).toBe("23505"); // unique_violation on slot_id
});
});Expected result: both tests pass. Then run three manual checks against a staging copy:
- Stop the worker and create a booking. Expected: the booking exists and one outbox row waits with
sent_atempty. Start the worker. Expected: one email, andsent_atfilled. - Point the email provider at an invalid key. Expected: bookings still succeed, and outbox rows stay pending with an alert.
- Ask for user A's booking with user B's session. Expected: 403 or 404 from the API.
Decision
Build the six components as one service with one PostgreSQL database, and decide in writing which component enforces each business rule.
- Put rules that must never break in the database: unique constraints, foreign keys, transactions.
- Route every state change through the API, even if the client also reads tables directly.
- Send anything slow or retryable through an outbox and a worker, with idempotent consumers.
- Skip Kubernetes, service meshes and extra services until a measured need appears.
- Ask the builder for a one-page diagram that marks data stores, external services, secrets and the place each permission check runs. If they cannot draw it, the system is not ready to operate.
Sources
- [1]OWASP Top 10 API Security Risks, 2023 (opens in a new tab)OWASP, 2023
- [2]Row Level Security (opens in a new tab)Supabase, November 2026
- [3]2025 Developer Survey: Technology (opens in a new tab)Stack Overflow, July 2025
- [4]Transactional outbox pattern (opens in a new tab)AWS Prescriptive Guidance, November 2026
- [5]Idempotent requests (opens in a new tab)Stripe API Reference, November 2026
- [6]MonolithFirst (opens in a new tab)Martin Fowler, June 2015
Technical guidance, not legal or security certification.
Related resources
Need a technical review of an AI-built MVP?
Discuss your build