Data and databases¶
The backend, warehouse-, payment-, notification- and delivery-service use one PostgreSQL 19 server and one database, but each owns a separate schema and connects as its own role (why: ADR 4).
flowchart TB
B[backend] --> PUB[(schema public)]
W[warehouse-service] --> WH[(schema warehouse)]
P[payment-service] --> PAY[(schema payment)]
N[notification-service] --> NOT[(schema notification)]
D[delivery-service] --> DEL[(schema delivery)]
llm-service has no database: it reads what it needs through the backend's internal API.
Roles and isolation¶
The one-shot postgres-roles container runs postgres/service-roles.sh
before every warehouse-, payment-, notification- and delivery-service start. For each of
warehouse, payment, notification and delivery it (delivery only when
DELIVERY_DB_PASSWORD is set, as in every profile except the course
compatibility stack):
- creates the role if missing, sets
LOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATIONand the password fromWAREHOUSE_DB_PASSWORD/PAYMENT_DB_PASSWORD/NOTIFICATION_DB_PASSWORD/DELIVERY_DB_PASSWORD; - grants
CONNECTon the database; - creates the schema with that role as owner, and transfers ownership of any tables, views and sequences left in it by an earlier superuser-owned deployment or a restore.
The roles cannot read the backend's public tables; the production verify
role checks exactly that after every deploy. The services connect with
?currentSchema=<schema> (delivery-service: DATABASE_SCHEMA) and run their
own migrations inside it. The Rust services keep the Flyway history tables and
file names of the services they replaced, so they took over the existing
databases unchanged.
Migrations¶
| Service | Flyway location | Migrations |
|---|---|---|
| backend | public schema |
V1 baseline … V7 commerce, V8 order fulfilment state, V9 email retry and order refunds, V10 commerce foundation, V11 payments, V12 loyalty and gift cards, V13 VAT and currency, V14 webhooks, V15 product search indexes, V16 domain event feed (domain_events, card_refund_requests; drops payment_refund_outbox) |
| warehouse-service | warehouse |
V1 schema, V2 notification outbox and order locks, V3 shipment tracking (shipments.simulated, tracking_events), V4 event feed consumer (event_cursors, processed_events) |
| payment-service | payment |
V1 baseline, V2 order payment locks, V3 event feed consumer (event_cursors, processed_events) |
| notification-service | notification |
webhook subscriptions, deliveries and inboxes (imported once from the backend), notification_emails, event feed consumer (event_cursors, processed_events) |
| delivery-service | delivery |
0001 (deliveries, delivery_events, processed_events, event_cursors) |
The table shows the early migrations. Later ones include backend V23
(orders.reservation_expires_at) and V24 (domain_events.span_id) up to
V29 (event feed position), and warehouse-service V6 (warehouse locations,
location_products, one shipment per order and location, shipment_lines)
and V7 (stock ledger). The services' repositories hold the full lists.
Main tables¶
| Area | Tables |
|---|---|
| Users and security | app_user, user_entity_roles, refresh_token, password_reset_token, mfa_credential, mfa_challenge, mfa_recovery_code |
| Catalog and stock | products (stock_quantity is a projection of warehouse-service's ledger), stock_command_outbox, product_reviews, wishlist_items |
| Cart | cart_items, cart_coupons, cart_tenders (gift card and points) |
| Orders | orders (incl. fulfilment_state, tax and tender columns), order_items, order_idempotency_keys, order_refunds |
| Coupons | coupons, coupon_redemptions |
| Gift cards and loyalty | gift_cards, gift_card_transactions, loyalty_accounts, loyalty_transactions |
| Payments (backend side) | order_payments, payment_notifications, card_refund_requests |
| Event feed | domain_events (every domain event, kept 30 days) |
| Tax and money | vat_rates, currency_rates |
| Messaging | email_event |
| Webhooks | webhook_subscriptions, webhook_deliveries, webhook_inboxes, webhook_inbox_requests |
| Diagnostics | traffic_log |
shipments, tracking_events, return_requests, return_items,
suppliers, purchase_orders, purchase_order_lines,
purchase_receipts, notification_outbox, order_locks,
event_cursors, processed_events.
warehouse-service stores snapshots (order id, owner, unit prices, totals) instead of foreign keys into the backend: it never joins across schemas.
payments, payment_idempotency_keys, payment_outbox, refunds,
order_payment_locks, event_cursors, processed_events.
Only the card brand and the last four digits are stored. The idempotency fingerprint is an HMAC of the request, never the card number.
Connection pools¶
warehouse-, payment- and notification-service keep small connection pools of
3 connections (delivery-service: 4). The lightweight PostgreSQL runs
with max_connections=40 and shared_buffers=32MB inside a 384 MiB limit.
Data lifetime per environment¶
| Environment | Persistence | Reset |
|---|---|---|
| lightweight | tmpfs | every docker compose ... up that recreates postgres |
| full | named volume postgres19-data (the PostgreSQL 16 volume postgres-data of older checkouts is no longer used; remove it with docker volume rm awesome-full-native_postgres-data) |
docker compose down -v |
| awesome.byst.re | named volume, encrypted daily backups | make ansible-reset-demo-state (destructive) |
| aitesters.byst.re | aitesters-postgres volume |
nightly aitesters-reset timer, or make ansible-reset-aitesters-state |
Database access on the local profiles: pgweb at http://localhost:8081/db/
(read-only), or a client on 127.0.0.1:15432 (lightweight) or localhost:5432
(full), database testdb, with the read-only tester / tester or the superuser
postgres / postgres. How to connect, diagrams and sample queries:
Database for testers; every table and column:
Table reference.