Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP1universalStack: sql
concurrencylockingtransactionsdata-integrity
Apply the same locking strategy across all related write paths
If one write path that mutates a shared balance/aggregate takes a pessimistic lock, the sibling write paths that mutate the same data must lock too, or concurrent requests corrupt it.
PR: hegnar-user-ws · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | // createTransaction takes setLock('pessimistic_write')... |
| 2 | // ...but createDividend / updateDividend touch the same balance with no lock |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | // Every path that mutates the shared balance locks the parent row first |
| 2 | await manager.getRepository(Portfolio) |
| 3 | .createQueryBuilder('p').setLock('pessimistic_write') |
| 4 | .where('p.id = :id', { id }).getOne(); |
Explanation (EN)
Objašnjenje (HR)