@radicaltools/cli 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +353 -33
  2. package/dist/hub-catalogue/concern/concern-api-collections.radical +1136 -0
  3. package/dist/hub-catalogue/concern/concern-api-errors.radical +1180 -0
  4. package/dist/hub-catalogue/concern/concern-api-evolution.radical +1174 -0
  5. package/dist/hub-catalogue/concern/concern-api-idempotency.radical +1218 -0
  6. package/dist/hub-catalogue/concern/concern-api-resource-design.radical +1102 -0
  7. package/dist/hub-catalogue/concern/concern-api-style-guide.radical +1210 -0
  8. package/dist/hub-catalogue/concern/concern-architecture-style.radical +1268 -0
  9. package/dist/hub-catalogue/concern/concern-audit-trail.radical +1096 -0
  10. package/dist/hub-catalogue/concern/concern-authentication.radical +895 -0
  11. package/dist/hub-catalogue/concern/concern-authorization.radical +1686 -0
  12. package/dist/hub-catalogue/concern/concern-availability.radical +1028 -0
  13. package/dist/hub-catalogue/concern/concern-backend-stack.radical +1037 -0
  14. package/dist/hub-catalogue/concern/concern-backup-recovery.radical +1560 -0
  15. package/dist/hub-catalogue/concern/concern-caching.radical +1294 -0
  16. package/dist/hub-catalogue/concern/concern-capacity.radical +915 -0
  17. package/dist/hub-catalogue/concern/concern-code-documentation.radical +1397 -0
  18. package/dist/hub-catalogue/concern/concern-code-quality-gate.radical +1409 -0
  19. package/dist/hub-catalogue/concern/concern-code-review-branching.radical +1416 -0
  20. package/dist/hub-catalogue/concern/concern-code-style.radical +1058 -0
  21. package/dist/hub-catalogue/concern/concern-communication-style.radical +1508 -0
  22. package/dist/hub-catalogue/concern/concern-data-classification.radical +970 -0
  23. package/dist/hub-catalogue/concern/concern-data-consistency.radical +1112 -0
  24. package/dist/hub-catalogue/concern/concern-data-store.radical +1282 -0
  25. package/dist/hub-catalogue/concern/concern-decomposition.radical +1318 -0
  26. package/dist/hub-catalogue/concern/concern-definition-of-done.radical +1214 -0
  27. package/dist/hub-catalogue/concern/concern-delivery-metrics.radical +966 -0
  28. package/dist/hub-catalogue/concern/concern-dependency-hygiene.radical +1345 -0
  29. package/dist/hub-catalogue/concern/concern-deployment.radical +1203 -0
  30. package/dist/hub-catalogue/concern/concern-encryption.radical +1318 -0
  31. package/dist/hub-catalogue/concern/concern-error-handling-logging.radical +1197 -0
  32. package/dist/hub-catalogue/concern/concern-eu-dora.radical +1321 -0
  33. package/dist/hub-catalogue/concern/concern-frontend-stack.radical +1647 -0
  34. package/dist/hub-catalogue/concern/concern-incident-management.radical +1204 -0
  35. package/dist/hub-catalogue/concern/concern-infrastructure.radical +2183 -0
  36. package/dist/hub-catalogue/concern/concern-integration-resilience.radical +1116 -0
  37. package/dist/hub-catalogue/concern/concern-messaging.radical +973 -0
  38. package/dist/hub-catalogue/concern/concern-module-boundaries.radical +867 -0
  39. package/dist/hub-catalogue/concern/concern-observability.radical +997 -0
  40. package/dist/hub-catalogue/concern/concern-operational-readiness.radical +1249 -0
  41. package/dist/hub-catalogue/concern/concern-personal-data.radical +1949 -0
  42. package/dist/hub-catalogue/concern/concern-quality-priorities.radical +1091 -0
  43. package/dist/hub-catalogue/concern/concern-rate-limiting.radical +1445 -0
  44. package/dist/hub-catalogue/concern/concern-release-versioning.radical +1358 -0
  45. package/dist/hub-catalogue/concern/concern-retention.radical +1399 -0
  46. package/dist/hub-catalogue/concern/concern-secrets.radical +1284 -0
  47. package/dist/hub-catalogue/concern/concern-secure-coding.radical +1379 -0
  48. package/dist/hub-catalogue/concern/concern-secure-development.radical +1245 -0
  49. package/dist/hub-catalogue/concern/concern-security-detection.radical +1153 -0
  50. package/dist/hub-catalogue/concern/concern-supply-chain.radical +1386 -0
  51. package/dist/hub-catalogue/concern/concern-technical-debt.radical +1450 -0
  52. package/dist/hub-catalogue/concern/concern-technology-lifecycle.radical +1145 -0
  53. package/dist/hub-catalogue/concern/concern-tenant-isolation.radical +1440 -0
  54. package/dist/hub-catalogue/concern/concern-test-strategy.radical +1212 -0
  55. package/dist/hub-catalogue/concern/concern-threat-modelling.radical +1143 -0
  56. package/dist/index.js +12712 -7144
  57. package/package.json +5 -3
@@ -0,0 +1,1112 @@
1
+ {
2
+ "hub": {
3
+ "id": "concern-data-consistency",
4
+ "category": "concern",
5
+ "name": "Data consistency",
6
+ "description": "How one business operation stays all-or-nothing across records, stores and services: transactions, isolation, events, sagas, and what readers may see. Which element writes each table is decided in the Decomposition pack; how consumers absorb duplicates in the Messaging pack.",
7
+ "tags": [
8
+ "consistency",
9
+ "transactions",
10
+ "isolation",
11
+ "outbox",
12
+ "saga",
13
+ "replicas"
14
+ ],
15
+ "requiredMetamodel": "c4-ddd-governance-builtin",
16
+ "concern": {
17
+ "id": "data-consistency",
18
+ "trigger": "LIST RELATIONS WHERE (source.type = \"container\" OR source.type = \"component\" OR source.type = \"webapp\" OR source.type = \"system\") AND source.external != true AND (target.type = \"database\" OR target.type = \"queue\") AND target.external != true",
19
+ "applyTo": "source",
20
+ "why": "these elements write to stores or queues, so how an operation that changes several records stays consistent, and what readers may see meanwhile, has to be decided.",
21
+ "group": "architecture"
22
+ },
23
+ "sources": [
24
+ {
25
+ "title": "microservices.io: Pattern: Saga",
26
+ "url": "https://microservices.io/patterns/data/saga.html"
27
+ },
28
+ {
29
+ "title": "microservices.io: Pattern: Transactional outbox",
30
+ "url": "https://microservices.io/patterns/data/transactional-outbox.html"
31
+ },
32
+ {
33
+ "title": "PostgreSQL documentation: Transaction Isolation",
34
+ "url": "https://www.postgresql.org/docs/current/transaction-iso.html"
35
+ },
36
+ {
37
+ "title": "Jepsen: Consistency Models",
38
+ "url": "https://jepsen.io/consistency"
39
+ },
40
+ {
41
+ "title": "Garcia-Molina and Salem, Sagas (SIGMOD 1987)",
42
+ "url": "https://dl.acm.org/doi/10.1145/38713.38742"
43
+ },
44
+ {
45
+ "title": "Terry et al., Session Guarantees for Weakly Consistent Replicated Data (1994)",
46
+ "url": "https://ieeexplore.ieee.org/document/331722"
47
+ }
48
+ ],
49
+ "templateParams": [
50
+ {
51
+ "key": "MODEL",
52
+ "title": "Transactions",
53
+ "label": "How does an operation that changes several records stay all-or-nothing?",
54
+ "hint": "Decided by where the records live: one database can do it in one transaction; a database plus a queue needs an outbox; several services' databases need a saga.",
55
+ "defaultValue": "outbox",
56
+ "options": [
57
+ {
58
+ "value": "acid",
59
+ "label": "one ACID transaction",
60
+ "description": "Every record the operation changes is in one database this element owns, and nothing outside it must learn of the change atomically. Pick it for a monolith or a modular monolith on one database."
61
+ },
62
+ {
63
+ "value": "outbox",
64
+ "label": "a local transaction with a transactional outbox",
65
+ "description": "The change is in one database, and others learn of it through a queue: the event is written in the same transaction and published afterwards. Pick it when the element writes a database and publishes events, as an order service does."
66
+ },
67
+ {
68
+ "value": "saga",
69
+ "label": "a saga with compensating steps",
70
+ "description": "One business operation changes data owned by several services or an external system, each with its own transaction; a failed step undoes the earlier ones. Pick it when no single database holds everything the operation changes."
71
+ }
72
+ ]
73
+ },
74
+ {
75
+ "key": "ISOLATION",
76
+ "title": "Isolation",
77
+ "label": "At what isolation level do transactions run?",
78
+ "hint": "The level decides which anomalies concurrent transactions can produce: lost updates at Read Committed, write skew at snapshot isolation, none at Serializable, which in turn aborts transactions that must be retried.",
79
+ "defaultValue": "read-committed",
80
+ "options": [
81
+ {
82
+ "value": "read-committed",
83
+ "label": "Read Committed with version checks",
84
+ "description": "The default of PostgreSQL, SQL Server and Oracle; read-modify-write is protected by a version column or SELECT ... FOR UPDATE. Pick it when invariants are on single rows and contention is low or moderate."
85
+ },
86
+ {
87
+ "value": "snapshot",
88
+ "label": "Repeatable Read (snapshot isolation)",
89
+ "description": "Each transaction sees one snapshot; concurrent updates of the same row abort one of them, but write skew across rows remains. Pick it for reports and multi-row reads that must be consistent, with constraints for cross-row rules."
90
+ },
91
+ {
92
+ "value": "serializable",
93
+ "label": "Serializable",
94
+ "description": "The database guarantees the result of some serial order (PostgreSQL SSI, CockroachDB, Spanner); conflicting transactions abort and are retried. Pick it when invariants span rows (no double booking, balances never negative) and you can retry."
95
+ }
96
+ ]
97
+ },
98
+ {
99
+ "key": "READS",
100
+ "title": "Reads",
101
+ "label": "Where are reads served from?",
102
+ "hint": "Replicas take load off the primary, but lag behind it: a user may not see what they just saved, or two pages may disagree. A cache in front of the store is decided in the Caching pack.",
103
+ "defaultValue": "primary",
104
+ "options": [
105
+ {
106
+ "value": "primary",
107
+ "label": "the primary only",
108
+ "description": "Every read sees every committed write. Pick it while the primary can carry the reads, which is longer than most expect."
109
+ },
110
+ {
111
+ "value": "ryw",
112
+ "label": "replicas with read-your-writes",
113
+ "description": "Reads go to replicas, but a user who has just written reads from the primary or from a replica that has caught up with their write. Pick it when reads must scale and users must see their own changes at once."
114
+ },
115
+ {
116
+ "value": "bounded",
117
+ "label": "replicas with bounded staleness",
118
+ "description": "Reads may be a few seconds old, never more than a stated bound, and decisions that write are taken on the primary. Pick it for catalogues, dashboards and feeds where a few seconds do not matter."
119
+ }
120
+ ]
121
+ },
122
+ {
123
+ "key": "PROPAGATION_SECONDS",
124
+ "label": "How many seconds may others see the old state after a commit? (the outbox relay's lag and a replica's staleness alike)",
125
+ "defaultValue": "5",
126
+ "type": "number"
127
+ },
128
+ {
129
+ "key": "SAGA_MINUTES",
130
+ "label": "Within how many minutes must a saga complete or be compensated? (sagas only)",
131
+ "defaultValue": "15",
132
+ "type": "number"
133
+ }
134
+ ]
135
+ },
136
+ "nodes": [
137
+ {
138
+ "id": "need",
139
+ "type": "need",
140
+ "label": "Operations all-or-nothing",
141
+ "x": 0,
142
+ "y": 0,
143
+ "kind": "brief",
144
+ "source": "Hub concern pack: Data consistency",
145
+ "description": "A business operation (placing an order, booking a slot, moving money) changes several records, often in more than one store or service. Whatever fails, and however many requests run at once, it must happen entirely or not at all, the rules that span records must hold, nothing may be told to others that did not happen (or be left untold), and people must see what they have just done. The snippets assume the application under src/ (src/orders the operations, src/db the transaction helper and data sources, src/outbox the relay, src/workflows the sagas) and the tests under tests/ with their fixtures beside them."
146
+ },
147
+ {
148
+ "id": "req-atomic",
149
+ "type": "requirement",
150
+ "label": "One transaction per operation",
151
+ "x": 260,
152
+ "y": 0,
153
+ "ears_type": "ubiquitous",
154
+ "action": "change every record of one business operation in a single database transaction, so that after a crash at any point either all of its changes are visible or none",
155
+ "rationale": "Atomicity of a single transaction is the simplest guarantee there is; it holds only while every record is in one database (PostgreSQL docs, Transaction Isolation; Jepsen consistency models).",
156
+ "hubWhen": {
157
+ "MODEL": [
158
+ "acid"
159
+ ]
160
+ }
161
+ },
162
+ {
163
+ "id": "req-outbox",
164
+ "type": "requirement",
165
+ "label": "Events published with the change",
166
+ "x": 260,
167
+ "y": 130,
168
+ "ears_type": "event-driven",
169
+ "trigger": "a transaction changes state that other elements must learn about",
170
+ "action": "write the event to an outbox table in the same transaction, publish it to the queue within {{PROPAGATION_SECONDS}} seconds of the commit, and publish no event whose transaction rolled back",
171
+ "rationale": "A dual write to a database and a broker loses or invents events when either fails; the transactional outbox makes the event part of the commit (microservices.io, Transactional outbox).",
172
+ "hubWhen": {
173
+ "MODEL": [
174
+ "outbox",
175
+ "saga"
176
+ ]
177
+ }
178
+ },
179
+ {
180
+ "id": "req-saga",
181
+ "type": "requirement",
182
+ "label": "Failed sagas compensated",
183
+ "x": 260,
184
+ "y": 260,
185
+ "ears_type": "unwanted-behaviour",
186
+ "unwanted_condition": "a step of a saga fails for good, or the saga has not completed within {{SAGA_MINUTES}} minutes",
187
+ "action": "run the compensating step of every completed step in reverse order, record the saga's outcome, and alert the owner when a compensation itself fails",
188
+ "rationale": "A saga has no rollback: each step commits locally, so a failure is undone by compensating transactions (microservices.io, Saga; Garcia-Molina and Salem, Sagas, 1987).",
189
+ "hubWhen": {
190
+ "MODEL": [
191
+ "saga"
192
+ ]
193
+ }
194
+ },
195
+ {
196
+ "id": "req-saga-state",
197
+ "type": "requirement",
198
+ "label": "Saga state durable and visible",
199
+ "x": 260,
200
+ "y": 390,
201
+ "ears_type": "ubiquitous",
202
+ "action": "keep each saga's step and outcome in durable storage so that a restart resumes it, and mark the records it changes as pending until it completes, so that no other operation acts on a half-done state",
203
+ "rationale": "Sagas lack isolation: other transactions see intermediate states; a semantic lock (a pending state) is the usual countermeasure (microservices.io, Saga, countermeasures).",
204
+ "hubWhen": {
205
+ "MODEL": [
206
+ "saga"
207
+ ]
208
+ }
209
+ },
210
+ {
211
+ "id": "req-lost-update",
212
+ "type": "requirement",
213
+ "label": "No lost updates",
214
+ "x": 260,
215
+ "y": 520,
216
+ "ears_type": "unwanted-behaviour",
217
+ "unwanted_condition": "two transactions update the same record from the same version",
218
+ "action": "commit the first and reject the second with a conflict, by checking a version column in the UPDATE's WHERE clause or locking the row with SELECT ... FOR UPDATE",
219
+ "rationale": "At Read Committed a read-modify-write cycle loses one of two concurrent updates (PostgreSQL docs, Transaction Isolation, Read Committed; Jepsen: lost update).",
220
+ "hubWhen": {
221
+ "ISOLATION": [
222
+ "read-committed"
223
+ ]
224
+ }
225
+ },
226
+ {
227
+ "id": "req-write-skew",
228
+ "type": "requirement",
229
+ "label": "No write skew",
230
+ "x": 260,
231
+ "y": 650,
232
+ "ears_type": "unwanted-behaviour",
233
+ "unwanted_condition": "two concurrent transactions each read a set of rows and then write different rows of it, breaking a rule over the set",
234
+ "action": "enforce that rule with a database constraint (unique, exclusion or check) or by locking the rows read with SELECT ... FOR UPDATE, and retry a transaction aborted by a serialization failure up to 3 times",
235
+ "rationale": "Snapshot isolation (PostgreSQL Repeatable Read) prevents lost updates but allows write skew across rows (PostgreSQL docs, Transaction Isolation; Jepsen: snapshot isolation, G2-item).",
236
+ "hubWhen": {
237
+ "ISOLATION": [
238
+ "snapshot"
239
+ ]
240
+ }
241
+ },
242
+ {
243
+ "id": "req-serializable",
244
+ "type": "requirement",
245
+ "label": "Serialization failures retried",
246
+ "x": 260,
247
+ "y": 780,
248
+ "ears_type": "unwanted-behaviour",
249
+ "unwanted_condition": "a transaction fails with a serialization failure (SQLSTATE 40001) or a deadlock (40P01)",
250
+ "action": "retry it from the start up to 3 times with jittered backoff, and report a conflict to the caller only after the last attempt fails",
251
+ "rationale": "Serializable isolation guarantees the effect of some serial order by aborting conflicting transactions; applications must be prepared to retry them (PostgreSQL docs, Transaction Isolation, Serializable).",
252
+ "hubWhen": {
253
+ "ISOLATION": [
254
+ "serializable"
255
+ ]
256
+ }
257
+ },
258
+ {
259
+ "id": "req-read-primary",
260
+ "type": "requirement",
261
+ "label": "Reads see every commit",
262
+ "x": 260,
263
+ "y": 910,
264
+ "ears_type": "ubiquitous",
265
+ "action": "serve every read from the primary, so that a read started after a commit returns that commit",
266
+ "rationale": "Reading from the primary gives linearizable reads for a single-leader database without further design (Jepsen: consistency models).",
267
+ "hubWhen": {
268
+ "READS": [
269
+ "primary"
270
+ ]
271
+ }
272
+ },
273
+ {
274
+ "id": "req-ryw",
275
+ "type": "requirement",
276
+ "label": "Users see their own writes",
277
+ "x": 260,
278
+ "y": 1040,
279
+ "ears_type": "event-driven",
280
+ "trigger": "a user who has written within the last {{PROPAGATION_SECONDS}} seconds reads",
281
+ "action": "serve the read from the primary, or from a replica that has replayed at least the position of the user's last commit (LSN or GTID)",
282
+ "rationale": "Read-your-writes is the session guarantee users notice when it is missing (Jepsen: read your writes; Terry et al., Session Guarantees, 1994).",
283
+ "hubWhen": {
284
+ "READS": [
285
+ "ryw"
286
+ ]
287
+ }
288
+ },
289
+ {
290
+ "id": "req-bounded",
291
+ "type": "requirement",
292
+ "label": "Staleness bounded",
293
+ "x": 260,
294
+ "y": 1170,
295
+ "ears_type": "state-driven",
296
+ "precondition": "a read is served from a replica or a cache",
297
+ "action": "return data no older than {{PROPAGATION_SECONDS}} seconds, stop routing reads to a replica that lags more, and take every decision that writes on the primary",
298
+ "rationale": "Bounded staleness keeps the gain of replicas while capping how wrong a reader can be (Jepsen: consistency models); decisions on stale data cause lost updates.",
299
+ "hubWhen": {
300
+ "READS": [
301
+ "bounded"
302
+ ]
303
+ }
304
+ },
305
+ {
306
+ "id": "sc-atomic",
307
+ "type": "scenario",
308
+ "label": "Crash mid-operation",
309
+ "x": 520,
310
+ "y": 0,
311
+ "given": "an order that reserves stock and creates an invoice",
312
+ "when": "the process is killed after the reservation and before the invoice",
313
+ "then": "neither the reservation nor the invoice exists after restart",
314
+ "hubWhen": {
315
+ "MODEL": [
316
+ "acid"
317
+ ]
318
+ }
319
+ },
320
+ {
321
+ "id": "sc-outbox",
322
+ "type": "scenario",
323
+ "label": "Event follows commit",
324
+ "x": 520,
325
+ "y": 130,
326
+ "given": "an order placed while the broker is down",
327
+ "when": "the broker comes back, and another order's transaction rolls back",
328
+ "then": "the first order's event is published within {{PROPAGATION_SECONDS}} seconds of the broker's return; the second has no event",
329
+ "hubWhen": {
330
+ "MODEL": [
331
+ "outbox",
332
+ "saga"
333
+ ]
334
+ }
335
+ },
336
+ {
337
+ "id": "sc-saga",
338
+ "type": "scenario",
339
+ "label": "Payment fails, stock released",
340
+ "x": 520,
341
+ "y": 260,
342
+ "given": "a saga that reserved stock and then fails to charge the card",
343
+ "when": "the payment step fails for good",
344
+ "then": "the stock is released, the order is marked failed, and nothing remains reserved after {{SAGA_MINUTES}} minutes",
345
+ "hubWhen": {
346
+ "MODEL": [
347
+ "saga"
348
+ ]
349
+ }
350
+ },
351
+ {
352
+ "id": "sc-saga-state",
353
+ "type": "scenario",
354
+ "label": "Saga resumes",
355
+ "x": 520,
356
+ "y": 390,
357
+ "given": "a saga stopped by a deployment after its second of four steps",
358
+ "when": "the service starts again",
359
+ "then": "the saga continues from its third step, and the order stays pending until it completes",
360
+ "hubWhen": {
361
+ "MODEL": [
362
+ "saga"
363
+ ]
364
+ }
365
+ },
366
+ {
367
+ "id": "sc-lost-update",
368
+ "type": "scenario",
369
+ "label": "Concurrent edits",
370
+ "x": 520,
371
+ "y": 520,
372
+ "given": "two users editing the same order at version 7",
373
+ "when": "both save",
374
+ "then": "one save succeeds and the other gets a conflict with the current version",
375
+ "hubWhen": {
376
+ "ISOLATION": [
377
+ "read-committed"
378
+ ]
379
+ }
380
+ },
381
+ {
382
+ "id": "sc-write-skew",
383
+ "type": "scenario",
384
+ "label": "Double booking prevented",
385
+ "x": 520,
386
+ "y": 650,
387
+ "given": "one free slot",
388
+ "when": "two customers book it at the same moment",
389
+ "then": "exactly one booking is stored",
390
+ "hubWhen": {
391
+ "ISOLATION": [
392
+ "snapshot"
393
+ ]
394
+ }
395
+ },
396
+ {
397
+ "id": "sc-serializable",
398
+ "type": "scenario",
399
+ "label": "Conflict retried",
400
+ "x": 520,
401
+ "y": 780,
402
+ "given": "two transfers from the same account running at once",
403
+ "when": "one is aborted with SQLSTATE 40001",
404
+ "then": "it is retried and succeeds, and the balance is never negative",
405
+ "hubWhen": {
406
+ "ISOLATION": [
407
+ "serializable"
408
+ ]
409
+ }
410
+ },
411
+ {
412
+ "id": "sc-read-primary",
413
+ "type": "scenario",
414
+ "label": "Saved and seen",
415
+ "x": 520,
416
+ "y": 910,
417
+ "given": "a user who has just saved an address",
418
+ "when": "the next page loads",
419
+ "then": "it shows the new address",
420
+ "hubWhen": {
421
+ "READS": [
422
+ "primary"
423
+ ]
424
+ }
425
+ },
426
+ {
427
+ "id": "sc-ryw",
428
+ "type": "scenario",
429
+ "label": "Own change visible",
430
+ "x": 520,
431
+ "y": 1040,
432
+ "given": "replicas lagging 3 seconds behind",
433
+ "when": "a user saves an address and reloads at once",
434
+ "then": "the reload shows the new address",
435
+ "hubWhen": {
436
+ "READS": [
437
+ "ryw"
438
+ ]
439
+ }
440
+ },
441
+ {
442
+ "id": "sc-bounded",
443
+ "type": "scenario",
444
+ "label": "Lagging replica dropped",
445
+ "x": 520,
446
+ "y": 1170,
447
+ "given": "a replica whose lag grows past {{PROPAGATION_SECONDS}} seconds",
448
+ "when": "reads arrive",
449
+ "then": "they go to the primary or another replica until it catches up",
450
+ "hubWhen": {
451
+ "READS": [
452
+ "bounded"
453
+ ]
454
+ }
455
+ },
456
+ {
457
+ "id": "adr-acid",
458
+ "type": "adr",
459
+ "label": "One database transaction per operation",
460
+ "x": 780,
461
+ "y": 0,
462
+ "concern": "data-consistency",
463
+ "status": "accepted",
464
+ "date": "",
465
+ "context": "This element writes to stores and queues, and one business operation often changes several records, sometimes in several stores or services. The forces: a crash between two writes leaves half an operation behind; writing to a database and then to a broker (a dual write) loses or invents events when either fails; concurrent transactions at the default isolation level lose updates and break invariants that span rows; brokers deliver at least once, so every message may come twice; replicas and caches lag, so a user may not see what they just saved; and when several elements write the same data, nobody knows which copy is the truth.",
466
+ "decision": "Each business operation runs in one database transaction (PostgreSQL, MySQL InnoDB or SQL Server), opened and committed by one unit of work at the application's edge: Spring @Transactional, EF Core SaveChanges, Prisma $transaction or a hand-written withTransaction. No call to another service or broker happens inside it. Isolation: {{ISOLATION}}. Reads: {{READS}}. Which element writes each table is decided in the Decomposition pack. Rules that span rows are database constraints where SQL can state them.",
467
+ "consequences": "• All-or-nothing comes from the database, with no extra machinery.\n• Every record the operation changes must stay in that database: splitting it into services later means revisiting this decision.\n• Long transactions hold locks: work that is slow or calls out happens before or after, not inside.\n• Nothing outside the database learns of the change atomically; once events are needed, an outbox is.",
468
+ "alternatives": "1. A transactional outbox: the same transaction plus reliable events for others.\n2. A saga: when the data is spread over services.\n3. Distributed transactions (XA, two-phase commit): atomic across stores, but blocking, rarely supported by brokers and cloud services.",
469
+ "hubWhen": {
470
+ "MODEL": [
471
+ "acid"
472
+ ]
473
+ }
474
+ },
475
+ {
476
+ "id": "adr-outbox",
477
+ "type": "adr",
478
+ "label": "Transactional outbox",
479
+ "x": 780,
480
+ "y": 130,
481
+ "concern": "data-consistency",
482
+ "status": "accepted",
483
+ "date": "",
484
+ "context": "This element writes to stores and queues, and one business operation often changes several records, sometimes in several stores or services. The forces: a crash between two writes leaves half an operation behind; writing to a database and then to a broker (a dual write) loses or invents events when either fails; concurrent transactions at the default isolation level lose updates and break invariants that span rows; brokers deliver at least once, so every message may come twice; replicas and caches lag, so a user may not see what they just saved; and when several elements write the same data, nobody knows which copy is the truth.",
485
+ "decision": "State changes and the events that announce them are written in one local transaction: the event goes to an outbox table, and a relay publishes it to the broker within {{PROPAGATION_SECONDS}} seconds, then marks it sent. The relay is change data capture with Debezium (its outbox event router) when Kafka Connect is already run, otherwise a polling publisher, or the framework's outbox (Spring Modulith event publication registry, MassTransit or NServiceBus outbox). Nothing publishes to the broker directly. Delivery is at least once; consumers absorb duplicates as decided in the Messaging pack. Isolation: {{ISOLATION}}. Reads: {{READS}}. Which element writes each table is decided in the Decomposition pack.",
486
+ "consequences": "• No lost or invented events: an event exists if and only if its change committed.\n• Delivery is at least once, so every consumer must be idempotent (the Messaging pack decides how).\n• Others see the change up to {{PROPAGATION_SECONDS}} seconds later; the relay's lag must be watched.\n• The outbox table needs cleaning up, and event order holds only per aggregate key.",
487
+ "alternatives": "1. Publish after commit (dual write): simpler, but a crash between commit and publish loses the event.\n2. Event sourcing: the events are the state, which removes the dual write but changes the whole persistence model.\n3. Two-phase commit between database and broker: blocking and seldom supported.",
488
+ "hubWhen": {
489
+ "MODEL": [
490
+ "outbox"
491
+ ]
492
+ }
493
+ },
494
+ {
495
+ "id": "adr-saga",
496
+ "type": "adr",
497
+ "label": "Sagas with compensation",
498
+ "x": 780,
499
+ "y": 260,
500
+ "concern": "data-consistency",
501
+ "status": "accepted",
502
+ "date": "",
503
+ "context": "This element writes to stores and queues, and one business operation often changes several records, sometimes in several stores or services. The forces: a crash between two writes leaves half an operation behind; writing to a database and then to a broker (a dual write) loses or invents events when either fails; concurrent transactions at the default isolation level lose updates and break invariants that span rows; brokers deliver at least once, so every message may come twice; replicas and caches lag, so a user may not see what they just saved; and when several elements write the same data, nobody knows which copy is the truth.",
504
+ "decision": "An operation that changes data in several services runs as an orchestrated saga: each step a local transaction in its own service, each with a compensating step, the saga's state durable so it resumes after a restart. The orchestrator is Temporal, AWS Step Functions, Camunda 8 or MassTransit state machines: Temporal when the team writes workflows in code and runs it itself or on Temporal Cloud, Step Functions on AWS for few steps and managed operation, Camunda when business owners read and change BPMN. Choreography by events only for two or three steps. Records the saga changes stay pending until it completes; a saga not done within {{SAGA_MINUTES}} minutes is compensated. The orchestrator calls each step over its own durable queue; each step's own state change and the events it emits go through that service's transactional outbox, and consumers absorb duplicates as decided in the Messaging pack. Isolation of each local transaction: {{ISOLATION}}. Reads: {{READS}}. Which element writes each table is decided in the Decomposition pack.",
505
+ "consequences": "• Each service keeps its own database and its own transactions.\n• No isolation between sagas: others see pending states, and the design has to say what they may do with them.\n• Every step needs a compensating step that cannot fail for good, which is real design work (refunds, releases, cancellation notices).\n• An orchestrator is one more system to run and to keep available.",
506
+ "alternatives": "1. Put the data in one database and use one transaction: simpler, if the service boundaries allow.\n2. Distributed transactions (XA, two-phase commit): atomic but blocking, and rarely available across services and SaaS APIs.\n3. Choreography without an orchestrator: no central component, but the flow is hard to see and to change past three steps.",
507
+ "hubWhen": {
508
+ "MODEL": [
509
+ "saga"
510
+ ]
511
+ }
512
+ },
513
+ {
514
+ "id": "adr-read-committed",
515
+ "type": "adr",
516
+ "label": "Read Committed with version checks",
517
+ "x": 780,
518
+ "y": 390,
519
+ "concern": "data-consistency",
520
+ "status": "accepted",
521
+ "date": "",
522
+ "context": "This element writes to stores and queues, and one business operation often changes several records, sometimes in several stores or services. The forces: a crash between two writes leaves half an operation behind; writing to a database and then to a broker (a dual write) loses or invents events when either fails; concurrent transactions at the default isolation level lose updates and break invariants that span rows; brokers deliver at least once, so every message may come twice; replicas and caches lag, so a user may not see what they just saved; and when several elements write the same data, nobody knows which copy is the truth.",
523
+ "decision": "Transactions run at Read Committed, the database's default. Every read-modify-write carries a version column checked in the UPDATE's WHERE clause (optimistic locking: JPA @Version, EF Core concurrency tokens, Prisma or a hand-written version = $expected), or locks the row with SELECT ... FOR UPDATE where the write always follows the read; a conflict is reported to the caller with the current version. Rules over several rows are database constraints.",
524
+ "consequences": "• The cheapest level: no serialization aborts, no retry loop in every transaction.\n• Every read-modify-write must remember its version or lock: one forgotten is a lost update.\n• Rules that span rows cannot be enforced by the level and need a constraint or an explicit lock.",
525
+ "alternatives": "1. Repeatable Read (snapshot isolation): consistent multi-row reads, write skew remains.\n2. Serializable: no anomalies, at the cost of aborts and retries.",
526
+ "hubWhen": {
527
+ "ISOLATION": [
528
+ "read-committed"
529
+ ]
530
+ }
531
+ },
532
+ {
533
+ "id": "adr-snapshot",
534
+ "type": "adr",
535
+ "label": "Repeatable Read (snapshot isolation)",
536
+ "x": 780,
537
+ "y": 520,
538
+ "concern": "data-consistency",
539
+ "status": "accepted",
540
+ "date": "",
541
+ "context": "This element writes to stores and queues, and one business operation often changes several records, sometimes in several stores or services. The forces: a crash between two writes leaves half an operation behind; writing to a database and then to a broker (a dual write) loses or invents events when either fails; concurrent transactions at the default isolation level lose updates and break invariants that span rows; brokers deliver at least once, so every message may come twice; replicas and caches lag, so a user may not see what they just saved; and when several elements write the same data, nobody knows which copy is the truth.",
542
+ "decision": "Transactions run at Repeatable Read (PostgreSQL snapshot isolation, SQL Server SNAPSHOT), so each sees one consistent snapshot and a concurrent update of the same row aborts one of them, which is retried up to 3 times. Rules over a set of rows (one booking per slot, a balance never negative) are enforced with a unique, exclusion or check constraint, or by locking the rows read with SELECT ... FOR UPDATE, because snapshot isolation allows write skew.",
543
+ "consequences": "• Reports and multi-row reads are consistent without locks.\n• Every cross-row rule needs a constraint or a lock: the level does not protect it.\n• Concurrent updates of the same row abort: a retry loop is needed where that is common.\n• Long snapshots hold back vacuum in PostgreSQL: keep transactions short.",
544
+ "alternatives": "1. Read Committed with version checks: cheaper, no consistent multi-row reads.\n2. Serializable: write skew is caught by the database, with more aborts.",
545
+ "hubWhen": {
546
+ "ISOLATION": [
547
+ "snapshot"
548
+ ]
549
+ }
550
+ },
551
+ {
552
+ "id": "adr-serializable",
553
+ "type": "adr",
554
+ "label": "Serializable",
555
+ "x": 780,
556
+ "y": 650,
557
+ "concern": "data-consistency",
558
+ "status": "accepted",
559
+ "date": "",
560
+ "context": "This element writes to stores and queues, and one business operation often changes several records, sometimes in several stores or services. The forces: a crash between two writes leaves half an operation behind; writing to a database and then to a broker (a dual write) loses or invents events when either fails; concurrent transactions at the default isolation level lose updates and break invariants that span rows; brokers deliver at least once, so every message may come twice; replicas and caches lag, so a user may not see what they just saved; and when several elements write the same data, nobody knows which copy is the truth.",
561
+ "decision": "Transactions run at Serializable (PostgreSQL SSI, CockroachDB, Spanner), so the database guarantees the effect of some serial order and aborts a transaction that would break it. Every transaction is wrapped in one retry helper that retries a serialization failure (SQLSTATE 40001) or deadlock (40P01) up to 3 times with jittered backoff and reports a conflict only after the last attempt; the helper is the only way to open a transaction. Transactions stay short and touch few rows, so aborts stay rare.",
562
+ "consequences": "• Invariants that span rows hold without a constraint or lock for each.\n• A retry rate to watch: above a few percent, p99 latency rises and the hot rows need redesign.\n• Every transaction must be safe to run again from the start: no side effects before the commit.\n• PostgreSQL SSI costs memory for predicate locks on large scans.",
563
+ "alternatives": "1. Repeatable Read with constraints: fewer aborts, every cross-row rule stated by hand.\n2. Read Committed with version checks: cheapest, protects single rows only.",
564
+ "hubWhen": {
565
+ "ISOLATION": [
566
+ "serializable"
567
+ ]
568
+ }
569
+ },
570
+ {
571
+ "id": "adr-reads-primary",
572
+ "type": "adr",
573
+ "label": "Reads from the primary only",
574
+ "x": 780,
575
+ "y": 780,
576
+ "concern": "data-consistency",
577
+ "status": "accepted",
578
+ "date": "",
579
+ "context": "This element writes to stores and queues, and one business operation often changes several records, sometimes in several stores or services. The forces: a crash between two writes leaves half an operation behind; writing to a database and then to a broker (a dual write) loses or invents events when either fails; concurrent transactions at the default isolation level lose updates and break invariants that span rows; brokers deliver at least once, so every message may come twice; replicas and caches lag, so a user may not see what they just saved; and when several elements write the same data, nobody knows which copy is the truth.",
580
+ "decision": "Every read is served from the primary; no read replica stands between the application and committed data; a cache in front of the store is decided in the Caching pack and, with this decision, removes an entry when its data changes (deletion by the writer or by change events). The application configures one connection pool and no read-only data source. Replicas, if any exist, serve backups and analytics only. Revisit when the primary's read load passes 60% of its capacity for a week.",
581
+ "consequences": "• A read after a commit always returns it: no session guarantees to build.\n• The primary carries every read: vertical scaling and query tuning are the levers.\n• No replica routing to get wrong.",
582
+ "alternatives": "1. Replicas with read-your-writes: reads scale, users still see their own changes.\n2. Replicas with bounded staleness: the most scale, a stated staleness for everyone.",
583
+ "hubWhen": {
584
+ "READS": [
585
+ "primary"
586
+ ]
587
+ }
588
+ },
589
+ {
590
+ "id": "adr-ryw",
591
+ "type": "adr",
592
+ "label": "Replicas with read-your-writes",
593
+ "x": 780,
594
+ "y": 910,
595
+ "concern": "data-consistency",
596
+ "status": "accepted",
597
+ "date": "",
598
+ "context": "This element writes to stores and queues, and one business operation often changes several records, sometimes in several stores or services. The forces: a crash between two writes leaves half an operation behind; writing to a database and then to a broker (a dual write) loses or invents events when either fails; concurrent transactions at the default isolation level lose updates and break invariants that span rows; brokers deliver at least once, so every message may come twice; replicas and caches lag, so a user may not see what they just saved; and when several elements write the same data, nobody knows which copy is the truth.",
599
+ "decision": "Reads go to replicas through a router (the framework's read/write splitting, pgpool, ProxySQL or application code) that keeps, per user session, the position of their last commit (PostgreSQL LSN, MySQL GTID); a read within {{PROPAGATION_SECONDS}} seconds of that commit goes to the primary, or to a replica that has replayed past the position. A replica lagging more than {{PROPAGATION_SECONDS}} seconds is taken out of rotation.",
600
+ "consequences": "• Reads scale with replicas and users see what they just saved.\n• The router is on every request and has to carry the session's position (a cookie or token claim).\n• Other users still see changes late, up to the replica lag.\n• A replica's lag is an alert and a routing signal at once.",
601
+ "alternatives": "1. The primary only: no router, no lag, less scale.\n2. Bounded staleness for everyone: simpler router, and a user may miss their own write for a few seconds.",
602
+ "hubWhen": {
603
+ "READS": [
604
+ "ryw"
605
+ ]
606
+ }
607
+ },
608
+ {
609
+ "id": "adr-bounded",
610
+ "type": "adr",
611
+ "label": "Replicas with bounded staleness",
612
+ "x": 780,
613
+ "y": 1040,
614
+ "concern": "data-consistency",
615
+ "status": "accepted",
616
+ "date": "",
617
+ "context": "This element writes to stores and queues, and one business operation often changes several records, sometimes in several stores or services. The forces: a crash between two writes leaves half an operation behind; writing to a database and then to a broker (a dual write) loses or invents events when either fails; concurrent transactions at the default isolation level lose updates and break invariants that span rows; brokers deliver at least once, so every message may come twice; replicas and caches lag, so a user may not see what they just saved; and when several elements write the same data, nobody knows which copy is the truth.",
618
+ "decision": "Reads are served from replicas and caches and may be up to {{PROPAGATION_SECONDS}} seconds old; the router takes a replica out of rotation when its lag passes that bound, and cache entries are removed or expire within it, as the Caching pack decides. Every decision that writes (a stock check before a reservation, a balance before a transfer) is taken on the primary inside the writing transaction, never on a replica or cache read.",
619
+ "consequences": "• The most read scale, with a staleness the product can state.\n• A user may not see their own change for a few seconds: the interface has to cope (optimistic updates, a \"saving\" state).\n• Any write that trusts a replica read is a lost update waiting to happen: the primary-only rule for decisions needs a review check.\n• A cache entry is wrong until it is removed or expires; which of the two bounds it is the Caching pack's decision, and its expiry must fit within the same bound.",
620
+ "alternatives": "1. Replicas with read-your-writes: users see their own changes, at the cost of a session-aware router.\n2. The primary only: no staleness, no scale from replicas.",
621
+ "hubWhen": {
622
+ "READS": [
623
+ "bounded"
624
+ ]
625
+ }
626
+ },
627
+ {
628
+ "id": "ff-concurrency",
629
+ "type": "fitness-fn",
630
+ "label": "Invariants hold under concurrency",
631
+ "x": 1040,
632
+ "y": 0,
633
+ "characteristic": "functional-suitability",
634
+ "scope": "atomic",
635
+ "cadence": "triggered",
636
+ "trigger": "pull-request",
637
+ "invocation": "automated",
638
+ "description": "An integration test runs many concurrent operations that compete for the same records against the real database engine (not an in-memory fake), at the isolation level and with the retries of the decision, and checks the invariant afterwards.\n\nThreshold: 0 lost updates or broken invariants in 1,000 concurrent attempts against a real database at the chosen isolation level\n\nTool: Vitest with Testcontainers (PostgreSQL)\n\n```ts\nimport { db } from './db'\nimport { placeOrder } from '../src/orders/placeOrder'\n\nit('never sells more than is in stock', async () => {\n await db.query(\"update stock set available = 10 where sku = 'A'\")\n const attempts = Array.from({ length: 1000 }, () => placeOrder({ sku: 'A', quantity: 1 }).then(() => 1, () => 0))\n const sold = (await Promise.all(attempts)).reduce((a, b) => a + b, 0)\n const { rows } = await db.query(\"select available from stock where sku = 'A'\")\n expect(sold).toBe(10)\n expect(rows[0].available).toBe(0)\n})\n```"
639
+ },
640
+ {
641
+ "id": "ff-lost-update",
642
+ "type": "fitness-fn",
643
+ "label": "Second writer gets a conflict",
644
+ "x": 1040,
645
+ "y": 130,
646
+ "characteristic": "functional-suitability",
647
+ "scope": "atomic",
648
+ "cadence": "triggered",
649
+ "trigger": "pull-request",
650
+ "invocation": "automated",
651
+ "description": "An integration test reads one order at version 7 in two sessions, saves from both, and expects one success and one conflict that carries the current version; it runs against the real database.\n\nThreshold: Of two updates from the same version, exactly 1 commits and 1 is refused with a conflict naming the current version\n\nTool: Vitest with Testcontainers (PostgreSQL)\n\n```ts\nimport { orders } from '../src/orders/repository'\nimport { seedOrder } from './db'\n\nit('refuses the second update from the same version', async () => {\n const id = await seedOrder({ version: 7 })\n const [first, second] = await Promise.allSettled([\n orders.update(id, { note: 'first' }, { expectedVersion: 7 }),\n orders.update(id, { note: 'second' }, { expectedVersion: 7 }),\n ])\n const outcomes = [first, second].map((r) => r.status).sort()\n expect(outcomes).toEqual(['fulfilled', 'rejected'])\n const rejected = [first, second].find((r) => r.status === 'rejected') as PromiseRejectedResult\n expect(rejected.reason).toMatchObject({ name: 'ConflictError', currentVersion: 8 })\n})\n```",
652
+ "hubWhen": {
653
+ "ISOLATION": [
654
+ "read-committed"
655
+ ]
656
+ }
657
+ },
658
+ {
659
+ "id": "ff-serialization-retry",
660
+ "type": "fitness-fn",
661
+ "label": "Serialization failures retried",
662
+ "x": 1040,
663
+ "y": 260,
664
+ "characteristic": "reliability",
665
+ "scope": "atomic",
666
+ "cadence": "triggered",
667
+ "trigger": "pull-request",
668
+ "invocation": "automated",
669
+ "description": "A unit test gives the retry helper a transaction body that fails with 40001 twice and then succeeds, expects 3 attempts, then one that always fails and expects a conflict after 4 attempts. The helper is the only way to open a transaction, which code review keeps.\n\nThreshold: The transaction helper retries SQLSTATE 40001 and 40P01 up to 3 times and reports a conflict after the 4th failure\n\nTool: Vitest\n\n```ts\nimport { withSerializableRetry } from '../src/db/transaction'\n\nconst serializationFailure = () => Object.assign(new Error('could not serialize access'), { code: '40001' })\n\nit('retries a serialization failure and gives up after the third retry', async () => {\n let attempts = 0\n const flaky = async () => { attempts++; if (attempts < 3) throw serializationFailure(); return 'ok' }\n await expect(withSerializableRetry(flaky)).resolves.toBe('ok')\n expect(attempts).toBe(3)\n\n attempts = 0\n const hopeless = async () => { attempts++; throw serializationFailure() }\n await expect(withSerializableRetry(hopeless)).rejects.toMatchObject({ name: 'ConflictError' })\n expect(attempts).toBe(4)\n})\n```",
670
+ "hubWhen": {
671
+ "ISOLATION": [
672
+ "serializable"
673
+ ]
674
+ }
675
+ },
676
+ {
677
+ "id": "ff-atomic",
678
+ "type": "fitness-fn",
679
+ "label": "No half operations",
680
+ "x": 1040,
681
+ "y": 390,
682
+ "characteristic": "functional-suitability",
683
+ "scope": "atomic",
684
+ "cadence": "triggered",
685
+ "trigger": "pull-request",
686
+ "invocation": "automated",
687
+ "description": "An integration test makes the operation fail after each of its writes in turn and checks that none of its records exist afterwards.\n\nThreshold: 0 records left behind when an operation fails at any of its steps\n\nTool: Vitest with Testcontainers (PostgreSQL)\n\n```ts\nimport { placeOrder } from '../src/orders/placeOrder'\nimport { count } from './db'\n\nit.each(['afterReservation', 'afterInvoice', 'beforeCommit'])('leaves nothing when it fails %s', async (step) => {\n const failAt = { [step]: () => { throw new Error('injected') } }\n await expect(placeOrder({ sku: 'A', quantity: 1 }, { hooks: failAt })).rejects.toThrow('injected')\n expect(await count('reservations')).toBe(0)\n expect(await count('invoices')).toBe(0)\n})\n```",
688
+ "hubWhen": {
689
+ "MODEL": [
690
+ "acid"
691
+ ]
692
+ }
693
+ },
694
+ {
695
+ "id": "ff-no-dual-write",
696
+ "type": "fitness-fn",
697
+ "label": "Only the relay publishes",
698
+ "x": 1040,
699
+ "y": 520,
700
+ "characteristic": "reliability",
701
+ "scope": "atomic",
702
+ "cadence": "triggered",
703
+ "trigger": "pull-request",
704
+ "invocation": "automated",
705
+ "description": "A dependency rule fails the build when code outside the relay imports a broker client, which would be a dual write that can lose or invent events.\n\nThreshold: 0 modules outside the outbox relay that import a broker client\n\nTool: dependency-cruiser (or the equivalent for your stack: ArchUnit, NetArchTest)\n\n```js\n// .dependency-cruiser.cjs\nmodule.exports = {\n forbidden: [{\n name: 'publish-through-outbox',\n comment: 'ADR Transactional outbox: write to the outbox table; only the relay talks to the broker',\n severity: 'error',\n from: { pathNot: '^src/outbox/relay' },\n to: { path: 'node_modules/(kafkajs|amqplib|@aws-sdk/client-sqs|@aws-sdk/client-sns|@azure/service-bus|@google-cloud/pubsub)' },\n }],\n}\n```",
706
+ "hubWhen": {
707
+ "MODEL": [
708
+ "outbox",
709
+ "saga"
710
+ ]
711
+ }
712
+ },
713
+ {
714
+ "id": "ff-outbox-test",
715
+ "type": "fitness-fn",
716
+ "label": "Events follow commits only",
717
+ "x": 1040,
718
+ "y": 650,
719
+ "characteristic": "reliability",
720
+ "scope": "atomic",
721
+ "cadence": "triggered",
722
+ "trigger": "pull-request",
723
+ "invocation": "automated",
724
+ "description": "An integration test stops the broker, places an order (committed) and makes a second one roll back, restarts the broker and reads the topic: the first order's event arrives within the bound, the second never.\n\nThreshold: A committed change has its event on the broker within {{PROPAGATION_SECONDS}} seconds of the broker's return; a rolled-back change has 0 events\n\nTool: Vitest with Testcontainers (PostgreSQL and the broker)\n\n```ts\nimport { placeOrder } from '../src/orders/placeOrder'\nimport { broker, topic } from './broker' // the broker container and a consumer of the events topic\n\nit('publishes committed changes only, once the broker is back', async () => {\n await broker.stop()\n const committed = await placeOrder({ sku: 'A', quantity: 1 })\n await expect(placeOrder({ sku: 'A', quantity: 1 }, { hooks: { beforeCommit: () => { throw new Error('injected') } } })).rejects.toThrow()\n await broker.start()\n const events = await topic.collect({ seconds: {{PROPAGATION_SECONDS}} })\n expect(events.map((e) => e.orderId)).toEqual([committed.id])\n})\n```",
725
+ "hubWhen": {
726
+ "MODEL": [
727
+ "outbox",
728
+ "saga"
729
+ ]
730
+ }
731
+ },
732
+ {
733
+ "id": "ff-outbox-lag",
734
+ "type": "fitness-fn",
735
+ "label": "Outbox drained in time",
736
+ "x": 1040,
737
+ "y": 780,
738
+ "characteristic": "reliability",
739
+ "scope": "atomic",
740
+ "cadence": "continual",
741
+ "invocation": "automated",
742
+ "description": "The database exporter reports the age of the oldest unpublished outbox row; Prometheus pages when the relay falls behind, before consumers notice.\n\nThreshold: The oldest unpublished outbox row is never older than {{PROPAGATION_SECONDS}} seconds for more than 2 minutes\n\nTool: Prometheus with sql_exporter\n\n```yaml\n# sql_exporter collector\ncollector_name: outbox\nmetrics:\n - metric_name: outbox_oldest_unpublished_seconds\n type: gauge\n help: 'Age of the oldest event not yet published'\n values: [age]\n query: |\n SELECT coalesce(extract(epoch FROM now() - min(created_at)), 0) AS age FROM outbox WHERE published_at IS NULL\n---\n# Prometheus alerting rule\ngroups:\n - name: data-consistency\n rules:\n - alert: OutboxBehind\n expr: outbox_oldest_unpublished_seconds > {{PROPAGATION_SECONDS}}\n for: 2m\n labels: { severity: page }\n```",
743
+ "hubWhen": {
744
+ "MODEL": [
745
+ "outbox",
746
+ "saga"
747
+ ]
748
+ }
749
+ },
750
+ {
751
+ "id": "ff-saga",
752
+ "type": "fitness-fn",
753
+ "label": "Sagas compensate",
754
+ "x": 1040,
755
+ "y": 910,
756
+ "characteristic": "reliability",
757
+ "scope": "atomic",
758
+ "cadence": "triggered",
759
+ "trigger": "pull-request",
760
+ "invocation": "automated",
761
+ "description": "A workflow test makes each step fail in turn on a time-skipping test server and checks that the completed steps were compensated in reverse order. The Temporal form is below; the same test is written with Step Functions Local, Camunda zeebe-process-test or the MassTransit test harness.\n\nThreshold: For every step of every saga, a failure there runs the compensations of all earlier steps in reverse order, and 0 steps without a compensation test\n\nTool: Temporal TypeScript SDK (@temporalio/testing); for Step Functions: Step Functions Local with mocked service integrations; for Camunda 8: zeebe-process-test; for MassTransit: the in-memory test harness\n\n```ts\nimport { fileURLToPath } from 'node:url'\nimport { TestWorkflowEnvironment } from '@temporalio/testing'\nimport { Worker } from '@temporalio/worker'\nimport { placeOrder } from '../src/workflows'\n\nconst steps = [\n { name: 'reserveStock', compensations: [] },\n { name: 'chargePayment', compensations: ['releaseStock'] },\n { name: 'shipOrder', compensations: ['refundPayment', 'releaseStock'] },\n]\n\nit.each(steps)('compensates everything before $name in reverse order', async (failing) => {\n const env = await TestWorkflowEnvironment.createTimeSkipping()\n const done: string[] = []\n const record = (name: string) => async () => { if (name === failing.name) throw new Error('fails for good'); done.push(name) }\n const worker = await Worker.create({\n connection: env.nativeConnection, taskQueue: 'test',\n workflowsPath: fileURLToPath(new URL('../src/workflows', import.meta.url)),\n activities: Object.fromEntries(['reserveStock', 'chargePayment', 'shipOrder', 'releaseStock', 'refundPayment'].map((n) => [n, record(n)])),\n })\n await worker.runUntil(env.client.workflow.execute(placeOrder, { taskQueue: 'test', workflowId: `order-${failing.name}`, args: [{ sku: 'A' }] }).catch(() => undefined))\n expect(done.filter((n) => failing.compensations.includes(n))).toEqual(failing.compensations)\n await env.teardown()\n})\n```",
762
+ "hubWhen": {
763
+ "MODEL": [
764
+ "saga"
765
+ ]
766
+ }
767
+ },
768
+ {
769
+ "id": "ff-saga-resume",
770
+ "type": "fitness-fn",
771
+ "label": "Sagas resume after a restart",
772
+ "x": 1040,
773
+ "y": 1040,
774
+ "characteristic": "reliability",
775
+ "scope": "atomic",
776
+ "cadence": "triggered",
777
+ "trigger": "pull-request",
778
+ "invocation": "automated",
779
+ "description": "A workflow test stops the worker once the second activity has completed, starts a new worker, and checks that the saga finishes with each step run exactly once and that the order's status was pending until the end.\n\nThreshold: A saga stopped after its second step continues from the third on a new worker, with 0 steps repeated, and the order stays pending until the saga completes\n\nTool: Temporal TypeScript SDK (@temporalio/testing); for other orchestrators, the equivalent restart of the engine or harness mid-flow\n\n```ts\nimport { fileURLToPath } from 'node:url'\nimport { TestWorkflowEnvironment } from '@temporalio/testing'\nimport { Worker } from '@temporalio/worker'\nimport { placeOrder } from '../src/workflows'\nimport { orders } from '../src/orders/repository'\n\nit('continues from the third step on a new worker', async () => {\n const env = await TestWorkflowEnvironment.createTimeSkipping()\n const done: string[] = []\n let secondDone!: () => void\n const afterSecond = new Promise<void>((r) => { secondDone = r })\n const activities = {\n reserveStock: async () => { done.push('reserve') },\n chargePayment: async () => { done.push('charge'); secondDone() },\n shipOrder: async () => { done.push('ship'); expect((await orders.get('order-1')).status).toBe('pending') },\n notify: async () => { done.push('notify') },\n }\n const options = { connection: env.nativeConnection, taskQueue: 'test', workflowsPath: fileURLToPath(new URL('../src/workflows', import.meta.url)), activities }\n const first = await Worker.create(options)\n const handle = await env.client.workflow.start(placeOrder, { taskQueue: 'test', workflowId: 'order-1', args: [{ sku: 'A' }] })\n const run = first.run()\n await afterSecond\n first.shutdown()\n await run\n const second = await Worker.create(options)\n await second.runUntil(handle.result())\n expect(done).toEqual(['reserve', 'charge', 'ship', 'notify'])\n expect((await orders.get('order-1')).status).toBe('completed')\n await env.teardown()\n})\n```",
780
+ "hubWhen": {
781
+ "MODEL": [
782
+ "saga"
783
+ ]
784
+ }
785
+ },
786
+ {
787
+ "id": "ff-stuck-sagas",
788
+ "type": "fitness-fn",
789
+ "label": "No stuck sagas",
790
+ "x": 1040,
791
+ "y": 1170,
792
+ "characteristic": "reliability",
793
+ "scope": "atomic",
794
+ "cadence": "continual",
795
+ "invocation": "automated",
796
+ "description": "The database exporter counts sagas neither completed nor compensated after the limit; Prometheus pages when there is one, since the records it holds stay pending.\n\nThreshold: 0 sagas open for more than {{SAGA_MINUTES}} minutes\n\nTool: Prometheus with sql_exporter\n\n```yaml\n# sql_exporter collector\ncollector_name: sagas\nmetrics:\n - metric_name: sagas_overdue\n type: gauge\n help: 'Sagas open longer than allowed'\n values: [n]\n query: |\n SELECT count(*) AS n FROM saga_instance\n WHERE status NOT IN ('completed', 'compensated') AND started_at < now() - interval '{{SAGA_MINUTES}} minutes'\n---\ngroups:\n - name: data-consistency\n rules:\n - alert: SagaStuck\n expr: sagas_overdue > 0\n for: 5m\n labels: { severity: page }\n```",
797
+ "hubWhen": {
798
+ "MODEL": [
799
+ "saga"
800
+ ]
801
+ }
802
+ },
803
+ {
804
+ "id": "ff-reads-primary",
805
+ "type": "fitness-fn",
806
+ "label": "Reads hit the primary",
807
+ "x": 1040,
808
+ "y": 1300,
809
+ "characteristic": "functional-suitability",
810
+ "scope": "atomic",
811
+ "cadence": "triggered",
812
+ "trigger": "pull-request",
813
+ "invocation": "automated",
814
+ "description": "A test starts the application's data access with its production configuration shape, asks every pool it opened whether it is on a replica, and checks that no read-only data source is configured.\n\nThreshold: Every connection pool the application opens reports pg_is_in_recovery() = false; 0 read-only data sources configured\n\nTool: Vitest with Testcontainers (PostgreSQL primary and a replica, to make the check meaningful)\n\n```ts\nimport { dataSources } from '../src/db/dataSources' // every pool the application opens, by name\n\nit('serves every read from the primary', async () => {\n expect(Object.keys(dataSources.readOnly ?? {})).toEqual([])\n for (const [name, pool] of Object.entries(dataSources.all())) {\n const { rows } = await pool.query('select pg_is_in_recovery() as replica')\n expect(rows[0].replica, `pool ${name} points at a replica`).toBe(false)\n }\n})\n```",
815
+ "hubWhen": {
816
+ "READS": [
817
+ "primary"
818
+ ]
819
+ }
820
+ },
821
+ {
822
+ "id": "ff-ryw",
823
+ "type": "fitness-fn",
824
+ "label": "Own writes read back",
825
+ "x": 1040,
826
+ "y": 1430,
827
+ "characteristic": "functional-suitability",
828
+ "scope": "atomic",
829
+ "cadence": "triggered",
830
+ "trigger": "pull-request",
831
+ "invocation": "automated",
832
+ "description": "An integration test delays replication on purpose (a paused WAL replay on the replica) and checks that a user's read straight after their write still returns it.\n\nThreshold: 0 of 100 write-then-read pairs return the old value while replicas lag\n\nTool: Vitest with Testcontainers (PostgreSQL primary and replica)\n\n```ts\nimport { api, replica, user } from './replicas'\n\nit('shows a user their own write while the replica lags', async () => {\n await replica.query('select pg_wal_replay_pause()')\n for (let i = 0; i < 100; i++) {\n await api.as(user).put('/me/address', { street: `Street ${i}` })\n const { body } = await api.as(user).get('/me/address')\n expect(body.street).toBe(`Street ${i}`)\n }\n await replica.query('select pg_wal_replay_resume()')\n})\n```",
833
+ "hubWhen": {
834
+ "READS": [
835
+ "ryw"
836
+ ]
837
+ }
838
+ },
839
+ {
840
+ "id": "ff-staleness",
841
+ "type": "fitness-fn",
842
+ "label": "Replica lag bounded and routed",
843
+ "x": 1040,
844
+ "y": 1560,
845
+ "characteristic": "functional-suitability",
846
+ "scope": "atomic",
847
+ "cadence": "continual",
848
+ "invocation": "automated",
849
+ "description": "The PostgreSQL exporter reports each replica's lag, and the read router exports replica_in_rotation (1 while it sends reads to the replica); Prometheus alerts when the lag passes the bound, and pages when a lagging replica is still in rotation.\n\nThreshold: Replica lag above {{PROPAGATION_SECONDS}} seconds for no more than 1 minute; a replica lagging more than that receives no reads for more than 1 minute\n\nTool: Prometheus with postgres_exporter (pg_replication_lag_seconds) and the router's own replica_in_rotation gauge\n\n```yaml\ngroups:\n - name: data-consistency\n rules:\n - alert: ReplicaTooStale\n expr: pg_replication_lag_seconds > {{PROPAGATION_SECONDS}}\n for: 1m\n labels: { severity: ticket }\n annotations:\n summary: 'Replica {{ $labels.instance }} is more than {{PROPAGATION_SECONDS}} s behind'\n - alert: StaleReplicaStillServingReads\n expr: (pg_replication_lag_seconds > {{PROPAGATION_SECONDS}}) and on (instance) (replica_in_rotation == 1)\n for: 1m\n labels: { severity: page }\n annotations:\n summary: 'Replica {{ $labels.instance }} lags past the bound and still receives reads'\n```",
850
+ "hubWhen": {
851
+ "READS": [
852
+ "ryw",
853
+ "bounded"
854
+ ]
855
+ }
856
+ }
857
+ ],
858
+ "relations": [
859
+ {
860
+ "id": "req-atomic--derives--need",
861
+ "sourceId": "req-atomic",
862
+ "targetId": "need",
863
+ "relationType": "derives"
864
+ },
865
+ {
866
+ "id": "req-outbox--derives--need",
867
+ "sourceId": "req-outbox",
868
+ "targetId": "need",
869
+ "relationType": "derives"
870
+ },
871
+ {
872
+ "id": "req-saga--derives--need",
873
+ "sourceId": "req-saga",
874
+ "targetId": "need",
875
+ "relationType": "derives"
876
+ },
877
+ {
878
+ "id": "req-saga-state--derives--need",
879
+ "sourceId": "req-saga-state",
880
+ "targetId": "need",
881
+ "relationType": "derives"
882
+ },
883
+ {
884
+ "id": "req-lost-update--derives--need",
885
+ "sourceId": "req-lost-update",
886
+ "targetId": "need",
887
+ "relationType": "derives"
888
+ },
889
+ {
890
+ "id": "req-write-skew--derives--need",
891
+ "sourceId": "req-write-skew",
892
+ "targetId": "need",
893
+ "relationType": "derives"
894
+ },
895
+ {
896
+ "id": "req-serializable--derives--need",
897
+ "sourceId": "req-serializable",
898
+ "targetId": "need",
899
+ "relationType": "derives"
900
+ },
901
+ {
902
+ "id": "req-read-primary--derives--need",
903
+ "sourceId": "req-read-primary",
904
+ "targetId": "need",
905
+ "relationType": "derives"
906
+ },
907
+ {
908
+ "id": "req-ryw--derives--need",
909
+ "sourceId": "req-ryw",
910
+ "targetId": "need",
911
+ "relationType": "derives"
912
+ },
913
+ {
914
+ "id": "req-bounded--derives--need",
915
+ "sourceId": "req-bounded",
916
+ "targetId": "need",
917
+ "relationType": "derives"
918
+ },
919
+ {
920
+ "id": "sc-atomic--verifies--req-atomic",
921
+ "sourceId": "sc-atomic",
922
+ "targetId": "req-atomic",
923
+ "relationType": "verifies"
924
+ },
925
+ {
926
+ "id": "sc-outbox--verifies--req-outbox",
927
+ "sourceId": "sc-outbox",
928
+ "targetId": "req-outbox",
929
+ "relationType": "verifies"
930
+ },
931
+ {
932
+ "id": "sc-saga--verifies--req-saga",
933
+ "sourceId": "sc-saga",
934
+ "targetId": "req-saga",
935
+ "relationType": "verifies"
936
+ },
937
+ {
938
+ "id": "sc-saga-state--verifies--req-saga-state",
939
+ "sourceId": "sc-saga-state",
940
+ "targetId": "req-saga-state",
941
+ "relationType": "verifies"
942
+ },
943
+ {
944
+ "id": "sc-lost-update--verifies--req-lost-update",
945
+ "sourceId": "sc-lost-update",
946
+ "targetId": "req-lost-update",
947
+ "relationType": "verifies"
948
+ },
949
+ {
950
+ "id": "sc-write-skew--verifies--req-write-skew",
951
+ "sourceId": "sc-write-skew",
952
+ "targetId": "req-write-skew",
953
+ "relationType": "verifies"
954
+ },
955
+ {
956
+ "id": "sc-serializable--verifies--req-serializable",
957
+ "sourceId": "sc-serializable",
958
+ "targetId": "req-serializable",
959
+ "relationType": "verifies"
960
+ },
961
+ {
962
+ "id": "sc-read-primary--verifies--req-read-primary",
963
+ "sourceId": "sc-read-primary",
964
+ "targetId": "req-read-primary",
965
+ "relationType": "verifies"
966
+ },
967
+ {
968
+ "id": "sc-ryw--verifies--req-ryw",
969
+ "sourceId": "sc-ryw",
970
+ "targetId": "req-ryw",
971
+ "relationType": "verifies"
972
+ },
973
+ {
974
+ "id": "sc-bounded--verifies--req-bounded",
975
+ "sourceId": "sc-bounded",
976
+ "targetId": "req-bounded",
977
+ "relationType": "verifies"
978
+ },
979
+ {
980
+ "id": "ff-concurrency--implements--adr-acid",
981
+ "sourceId": "ff-concurrency",
982
+ "targetId": "adr-acid",
983
+ "relationType": "implements"
984
+ },
985
+ {
986
+ "id": "ff-concurrency--implements--adr-outbox",
987
+ "sourceId": "ff-concurrency",
988
+ "targetId": "adr-outbox",
989
+ "relationType": "implements"
990
+ },
991
+ {
992
+ "id": "ff-concurrency--implements--adr-saga",
993
+ "sourceId": "ff-concurrency",
994
+ "targetId": "adr-saga",
995
+ "relationType": "implements"
996
+ },
997
+ {
998
+ "id": "ff-concurrency--implements--adr-read-committed",
999
+ "sourceId": "ff-concurrency",
1000
+ "targetId": "adr-read-committed",
1001
+ "relationType": "implements"
1002
+ },
1003
+ {
1004
+ "id": "ff-concurrency--implements--adr-snapshot",
1005
+ "sourceId": "ff-concurrency",
1006
+ "targetId": "adr-snapshot",
1007
+ "relationType": "implements"
1008
+ },
1009
+ {
1010
+ "id": "ff-concurrency--implements--adr-serializable",
1011
+ "sourceId": "ff-concurrency",
1012
+ "targetId": "adr-serializable",
1013
+ "relationType": "implements"
1014
+ },
1015
+ {
1016
+ "id": "ff-lost-update--implements--adr-read-committed",
1017
+ "sourceId": "ff-lost-update",
1018
+ "targetId": "adr-read-committed",
1019
+ "relationType": "implements"
1020
+ },
1021
+ {
1022
+ "id": "ff-serialization-retry--implements--adr-serializable",
1023
+ "sourceId": "ff-serialization-retry",
1024
+ "targetId": "adr-serializable",
1025
+ "relationType": "implements"
1026
+ },
1027
+ {
1028
+ "id": "ff-atomic--implements--adr-acid",
1029
+ "sourceId": "ff-atomic",
1030
+ "targetId": "adr-acid",
1031
+ "relationType": "implements"
1032
+ },
1033
+ {
1034
+ "id": "ff-no-dual-write--implements--adr-outbox",
1035
+ "sourceId": "ff-no-dual-write",
1036
+ "targetId": "adr-outbox",
1037
+ "relationType": "implements"
1038
+ },
1039
+ {
1040
+ "id": "ff-no-dual-write--implements--adr-saga",
1041
+ "sourceId": "ff-no-dual-write",
1042
+ "targetId": "adr-saga",
1043
+ "relationType": "implements"
1044
+ },
1045
+ {
1046
+ "id": "ff-outbox-test--implements--adr-outbox",
1047
+ "sourceId": "ff-outbox-test",
1048
+ "targetId": "adr-outbox",
1049
+ "relationType": "implements"
1050
+ },
1051
+ {
1052
+ "id": "ff-outbox-test--implements--adr-saga",
1053
+ "sourceId": "ff-outbox-test",
1054
+ "targetId": "adr-saga",
1055
+ "relationType": "implements"
1056
+ },
1057
+ {
1058
+ "id": "ff-outbox-lag--implements--adr-outbox",
1059
+ "sourceId": "ff-outbox-lag",
1060
+ "targetId": "adr-outbox",
1061
+ "relationType": "implements"
1062
+ },
1063
+ {
1064
+ "id": "ff-outbox-lag--implements--adr-saga",
1065
+ "sourceId": "ff-outbox-lag",
1066
+ "targetId": "adr-saga",
1067
+ "relationType": "implements"
1068
+ },
1069
+ {
1070
+ "id": "ff-saga--implements--adr-saga",
1071
+ "sourceId": "ff-saga",
1072
+ "targetId": "adr-saga",
1073
+ "relationType": "implements"
1074
+ },
1075
+ {
1076
+ "id": "ff-saga-resume--implements--adr-saga",
1077
+ "sourceId": "ff-saga-resume",
1078
+ "targetId": "adr-saga",
1079
+ "relationType": "implements"
1080
+ },
1081
+ {
1082
+ "id": "ff-stuck-sagas--implements--adr-saga",
1083
+ "sourceId": "ff-stuck-sagas",
1084
+ "targetId": "adr-saga",
1085
+ "relationType": "implements"
1086
+ },
1087
+ {
1088
+ "id": "ff-reads-primary--implements--adr-reads-primary",
1089
+ "sourceId": "ff-reads-primary",
1090
+ "targetId": "adr-reads-primary",
1091
+ "relationType": "implements"
1092
+ },
1093
+ {
1094
+ "id": "ff-ryw--implements--adr-ryw",
1095
+ "sourceId": "ff-ryw",
1096
+ "targetId": "adr-ryw",
1097
+ "relationType": "implements"
1098
+ },
1099
+ {
1100
+ "id": "ff-staleness--implements--adr-ryw",
1101
+ "sourceId": "ff-staleness",
1102
+ "targetId": "adr-ryw",
1103
+ "relationType": "implements"
1104
+ },
1105
+ {
1106
+ "id": "ff-staleness--implements--adr-bounded",
1107
+ "sourceId": "ff-staleness",
1108
+ "targetId": "adr-bounded",
1109
+ "relationType": "implements"
1110
+ }
1111
+ ]
1112
+ }