Persistence
Relational first. The database is the last line of defense for the rules: keys, unique, check and foreign key. One schema per service and queries designed not to grow with the table. Every structural change is a new migration, versioned and additive only, because during a deploy the new and the previous version use the same database.
Decisions and why
- PostgreSQL with constraints
- Two simultaneous requests get past any if. A unique (organization_id, user_id) does not let them.
- Schema per service, one instance
- Each service only sees its own schema, yet operations stay cheap: one instance, one backup.
- Cursor pagination, no COUNT
- OFFSET and COUNT get more expensive with every row. A cursor on a composite index costs the same on page 1 and page 10,000.
- No N+1, one transaction per use case
- fetch joins and deliberate queries; the use case is the transaction boundary.
- Every change is a new migration
- Once applied it is never edited, renamed or deleted; Liquibase keeps the checksum and refuses the change.
- Additive only: optional column or new table
- The previous version keeps serving during the rollout; renaming or dropping in one step takes it down.
- Big changes in steps (expand and contract)
- Add the new, move the code, and only in a later deploy remove the old.
- A comment and a rollback in every changeset
- Whoever reads it knows why it exists, and going back needs no improvising.
- The migration runs before the code
- On deploy a task applies the changelog and waits for exit 0; only then do the services roll out.
- The entity is checked against the table
- ddl-auto=validate in the suite: an entity without its migration is a red build, not a surprise in production.
requestresponse
Pick a scenario above to watch the message travel through the architecture.