@wazir-dev/cli 1.0.0

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 (629) hide show
  1. package/AGENTS.md +111 -0
  2. package/CHANGELOG.md +14 -0
  3. package/CONTRIBUTING.md +101 -0
  4. package/LICENSE +21 -0
  5. package/README.md +314 -0
  6. package/assets/composition-engine.mmd +34 -0
  7. package/assets/demo-script.sh +17 -0
  8. package/assets/logo-dark.svg +14 -0
  9. package/assets/logo.svg +14 -0
  10. package/assets/pipeline.mmd +39 -0
  11. package/assets/record-demo.sh +51 -0
  12. package/docs/README.md +51 -0
  13. package/docs/adapters/context-mode.md +60 -0
  14. package/docs/concepts/architecture.md +87 -0
  15. package/docs/concepts/artifact-model.md +60 -0
  16. package/docs/concepts/composition-engine.md +36 -0
  17. package/docs/concepts/indexing-and-recall.md +160 -0
  18. package/docs/concepts/observability.md +41 -0
  19. package/docs/concepts/roles-and-workflows.md +59 -0
  20. package/docs/concepts/terminology-policy.md +27 -0
  21. package/docs/getting-started/01-installation.md +78 -0
  22. package/docs/getting-started/02-first-run.md +102 -0
  23. package/docs/getting-started/03-adding-to-project.md +15 -0
  24. package/docs/getting-started/04-host-setup.md +15 -0
  25. package/docs/guides/ci-integration.md +15 -0
  26. package/docs/guides/creating-skills.md +15 -0
  27. package/docs/guides/expertise-module-authoring.md +15 -0
  28. package/docs/guides/hook-development.md +15 -0
  29. package/docs/guides/memory-and-learnings.md +34 -0
  30. package/docs/guides/multi-host-export.md +15 -0
  31. package/docs/guides/troubleshooting.md +101 -0
  32. package/docs/guides/writing-custom-roles.md +15 -0
  33. package/docs/plans/2026-03-15-cli-pipeline-integration-design.md +592 -0
  34. package/docs/plans/2026-03-15-cli-pipeline-integration-plan.md +598 -0
  35. package/docs/plans/2026-03-15-docs-enforcement-plan.md +238 -0
  36. package/docs/readmes/INDEX.md +99 -0
  37. package/docs/readmes/features/expertise/README.md +171 -0
  38. package/docs/readmes/features/exports/README.md +222 -0
  39. package/docs/readmes/features/hooks/README.md +103 -0
  40. package/docs/readmes/features/hooks/loop-cap-guard.md +133 -0
  41. package/docs/readmes/features/hooks/post-tool-capture.md +121 -0
  42. package/docs/readmes/features/hooks/post-tool-lint.md +130 -0
  43. package/docs/readmes/features/hooks/pre-compact-summary.md +122 -0
  44. package/docs/readmes/features/hooks/pre-tool-capture-route.md +100 -0
  45. package/docs/readmes/features/hooks/protected-path-write-guard.md +128 -0
  46. package/docs/readmes/features/hooks/session-start.md +119 -0
  47. package/docs/readmes/features/hooks/stop-handoff-harvest.md +125 -0
  48. package/docs/readmes/features/roles/README.md +157 -0
  49. package/docs/readmes/features/roles/clarifier.md +152 -0
  50. package/docs/readmes/features/roles/content-author.md +190 -0
  51. package/docs/readmes/features/roles/designer.md +193 -0
  52. package/docs/readmes/features/roles/executor.md +184 -0
  53. package/docs/readmes/features/roles/learner.md +210 -0
  54. package/docs/readmes/features/roles/planner.md +182 -0
  55. package/docs/readmes/features/roles/researcher.md +164 -0
  56. package/docs/readmes/features/roles/reviewer.md +184 -0
  57. package/docs/readmes/features/roles/specifier.md +162 -0
  58. package/docs/readmes/features/roles/verifier.md +215 -0
  59. package/docs/readmes/features/schemas/README.md +178 -0
  60. package/docs/readmes/features/skills/README.md +63 -0
  61. package/docs/readmes/features/skills/brainstorming.md +96 -0
  62. package/docs/readmes/features/skills/debugging.md +148 -0
  63. package/docs/readmes/features/skills/design.md +120 -0
  64. package/docs/readmes/features/skills/prepare-next.md +109 -0
  65. package/docs/readmes/features/skills/run-audit.md +159 -0
  66. package/docs/readmes/features/skills/scan-project.md +109 -0
  67. package/docs/readmes/features/skills/self-audit.md +176 -0
  68. package/docs/readmes/features/skills/tdd.md +137 -0
  69. package/docs/readmes/features/skills/using-skills.md +92 -0
  70. package/docs/readmes/features/skills/verification.md +120 -0
  71. package/docs/readmes/features/skills/writing-plans.md +104 -0
  72. package/docs/readmes/features/tooling/README.md +320 -0
  73. package/docs/readmes/features/workflows/README.md +186 -0
  74. package/docs/readmes/features/workflows/author.md +181 -0
  75. package/docs/readmes/features/workflows/clarify.md +154 -0
  76. package/docs/readmes/features/workflows/design-review.md +171 -0
  77. package/docs/readmes/features/workflows/design.md +169 -0
  78. package/docs/readmes/features/workflows/discover.md +162 -0
  79. package/docs/readmes/features/workflows/execute.md +173 -0
  80. package/docs/readmes/features/workflows/learn.md +167 -0
  81. package/docs/readmes/features/workflows/plan-review.md +165 -0
  82. package/docs/readmes/features/workflows/plan.md +170 -0
  83. package/docs/readmes/features/workflows/prepare-next.md +167 -0
  84. package/docs/readmes/features/workflows/review.md +169 -0
  85. package/docs/readmes/features/workflows/run-audit.md +191 -0
  86. package/docs/readmes/features/workflows/spec-challenge.md +159 -0
  87. package/docs/readmes/features/workflows/specify.md +160 -0
  88. package/docs/readmes/features/workflows/verify.md +177 -0
  89. package/docs/readmes/packages/README.md +50 -0
  90. package/docs/readmes/packages/ajv.md +117 -0
  91. package/docs/readmes/packages/context-mode.md +118 -0
  92. package/docs/readmes/packages/gray-matter.md +116 -0
  93. package/docs/readmes/packages/node-test.md +137 -0
  94. package/docs/readmes/packages/yaml.md +112 -0
  95. package/docs/reference/configuration-reference.md +159 -0
  96. package/docs/reference/expertise-index.md +52 -0
  97. package/docs/reference/git-flow.md +43 -0
  98. package/docs/reference/hooks.md +87 -0
  99. package/docs/reference/host-exports.md +50 -0
  100. package/docs/reference/launch-checklist.md +172 -0
  101. package/docs/reference/marketplace-listings.md +76 -0
  102. package/docs/reference/release-process.md +34 -0
  103. package/docs/reference/roles-reference.md +77 -0
  104. package/docs/reference/skills.md +33 -0
  105. package/docs/reference/templates.md +29 -0
  106. package/docs/reference/tooling-cli.md +94 -0
  107. package/docs/truth-claims.yaml +222 -0
  108. package/expertise/PROGRESS.md +63 -0
  109. package/expertise/README.md +18 -0
  110. package/expertise/antipatterns/PROGRESS.md +56 -0
  111. package/expertise/antipatterns/backend/api-design-antipatterns.md +1271 -0
  112. package/expertise/antipatterns/backend/auth-antipatterns.md +1195 -0
  113. package/expertise/antipatterns/backend/caching-antipatterns.md +622 -0
  114. package/expertise/antipatterns/backend/database-antipatterns.md +1038 -0
  115. package/expertise/antipatterns/backend/index.md +24 -0
  116. package/expertise/antipatterns/backend/microservices-antipatterns.md +850 -0
  117. package/expertise/antipatterns/code/architecture-antipatterns.md +919 -0
  118. package/expertise/antipatterns/code/async-antipatterns.md +622 -0
  119. package/expertise/antipatterns/code/code-smells.md +1186 -0
  120. package/expertise/antipatterns/code/dependency-antipatterns.md +1209 -0
  121. package/expertise/antipatterns/code/error-handling-antipatterns.md +1360 -0
  122. package/expertise/antipatterns/code/index.md +27 -0
  123. package/expertise/antipatterns/code/naming-and-abstraction.md +1118 -0
  124. package/expertise/antipatterns/code/state-management-antipatterns.md +1076 -0
  125. package/expertise/antipatterns/code/testing-antipatterns.md +1053 -0
  126. package/expertise/antipatterns/design/accessibility-antipatterns.md +1136 -0
  127. package/expertise/antipatterns/design/dark-patterns.md +1121 -0
  128. package/expertise/antipatterns/design/index.md +22 -0
  129. package/expertise/antipatterns/design/ui-antipatterns.md +1202 -0
  130. package/expertise/antipatterns/design/ux-antipatterns.md +680 -0
  131. package/expertise/antipatterns/frontend/css-layout-antipatterns.md +691 -0
  132. package/expertise/antipatterns/frontend/flutter-antipatterns.md +1827 -0
  133. package/expertise/antipatterns/frontend/index.md +23 -0
  134. package/expertise/antipatterns/frontend/mobile-antipatterns.md +573 -0
  135. package/expertise/antipatterns/frontend/react-antipatterns.md +1128 -0
  136. package/expertise/antipatterns/frontend/spa-antipatterns.md +1235 -0
  137. package/expertise/antipatterns/index.md +31 -0
  138. package/expertise/antipatterns/performance/index.md +20 -0
  139. package/expertise/antipatterns/performance/performance-antipatterns.md +1013 -0
  140. package/expertise/antipatterns/performance/premature-optimization.md +623 -0
  141. package/expertise/antipatterns/performance/scaling-antipatterns.md +785 -0
  142. package/expertise/antipatterns/process/ai-coding-antipatterns.md +853 -0
  143. package/expertise/antipatterns/process/code-review-antipatterns.md +656 -0
  144. package/expertise/antipatterns/process/deployment-antipatterns.md +920 -0
  145. package/expertise/antipatterns/process/index.md +23 -0
  146. package/expertise/antipatterns/process/technical-debt-antipatterns.md +647 -0
  147. package/expertise/antipatterns/security/index.md +20 -0
  148. package/expertise/antipatterns/security/secrets-antipatterns.md +849 -0
  149. package/expertise/antipatterns/security/security-theater.md +843 -0
  150. package/expertise/antipatterns/security/vulnerability-patterns.md +801 -0
  151. package/expertise/architecture/PROGRESS.md +70 -0
  152. package/expertise/architecture/data/caching-architecture.md +671 -0
  153. package/expertise/architecture/data/data-consistency.md +574 -0
  154. package/expertise/architecture/data/data-modeling.md +536 -0
  155. package/expertise/architecture/data/event-streams-and-queues.md +634 -0
  156. package/expertise/architecture/data/index.md +25 -0
  157. package/expertise/architecture/data/search-architecture.md +663 -0
  158. package/expertise/architecture/data/sql-vs-nosql.md +708 -0
  159. package/expertise/architecture/decisions/architecture-decision-records.md +640 -0
  160. package/expertise/architecture/decisions/build-vs-buy.md +616 -0
  161. package/expertise/architecture/decisions/index.md +23 -0
  162. package/expertise/architecture/decisions/monolith-to-microservices.md +790 -0
  163. package/expertise/architecture/decisions/technology-selection.md +616 -0
  164. package/expertise/architecture/distributed/cap-theorem-and-tradeoffs.md +800 -0
  165. package/expertise/architecture/distributed/circuit-breaker-bulkhead.md +741 -0
  166. package/expertise/architecture/distributed/consensus-and-coordination.md +796 -0
  167. package/expertise/architecture/distributed/distributed-systems-fundamentals.md +564 -0
  168. package/expertise/architecture/distributed/idempotency-and-retry.md +796 -0
  169. package/expertise/architecture/distributed/index.md +25 -0
  170. package/expertise/architecture/distributed/saga-pattern.md +797 -0
  171. package/expertise/architecture/foundations/architectural-thinking.md +460 -0
  172. package/expertise/architecture/foundations/coupling-and-cohesion.md +770 -0
  173. package/expertise/architecture/foundations/design-principles-solid.md +649 -0
  174. package/expertise/architecture/foundations/domain-driven-design.md +719 -0
  175. package/expertise/architecture/foundations/index.md +25 -0
  176. package/expertise/architecture/foundations/separation-of-concerns.md +472 -0
  177. package/expertise/architecture/foundations/twelve-factor-app.md +797 -0
  178. package/expertise/architecture/index.md +34 -0
  179. package/expertise/architecture/integration/api-design-graphql.md +638 -0
  180. package/expertise/architecture/integration/api-design-grpc.md +804 -0
  181. package/expertise/architecture/integration/api-design-rest.md +892 -0
  182. package/expertise/architecture/integration/index.md +25 -0
  183. package/expertise/architecture/integration/third-party-integration.md +795 -0
  184. package/expertise/architecture/integration/webhooks-and-callbacks.md +1152 -0
  185. package/expertise/architecture/integration/websockets-realtime.md +791 -0
  186. package/expertise/architecture/mobile-architecture/index.md +22 -0
  187. package/expertise/architecture/mobile-architecture/mobile-app-architecture.md +780 -0
  188. package/expertise/architecture/mobile-architecture/mobile-backend-for-frontend.md +670 -0
  189. package/expertise/architecture/mobile-architecture/offline-first.md +719 -0
  190. package/expertise/architecture/mobile-architecture/push-and-sync.md +782 -0
  191. package/expertise/architecture/patterns/cqrs-event-sourcing.md +717 -0
  192. package/expertise/architecture/patterns/event-driven.md +797 -0
  193. package/expertise/architecture/patterns/hexagonal-clean-architecture.md +870 -0
  194. package/expertise/architecture/patterns/index.md +27 -0
  195. package/expertise/architecture/patterns/layered-architecture.md +736 -0
  196. package/expertise/architecture/patterns/microservices.md +753 -0
  197. package/expertise/architecture/patterns/modular-monolith.md +692 -0
  198. package/expertise/architecture/patterns/monolith.md +626 -0
  199. package/expertise/architecture/patterns/plugin-architecture.md +735 -0
  200. package/expertise/architecture/patterns/serverless.md +780 -0
  201. package/expertise/architecture/scaling/database-scaling.md +615 -0
  202. package/expertise/architecture/scaling/feature-flags-and-rollouts.md +757 -0
  203. package/expertise/architecture/scaling/horizontal-vs-vertical.md +606 -0
  204. package/expertise/architecture/scaling/index.md +24 -0
  205. package/expertise/architecture/scaling/multi-tenancy.md +800 -0
  206. package/expertise/architecture/scaling/stateless-design.md +787 -0
  207. package/expertise/backend/embedded-firmware.md +625 -0
  208. package/expertise/backend/go.md +853 -0
  209. package/expertise/backend/index.md +24 -0
  210. package/expertise/backend/java-spring.md +448 -0
  211. package/expertise/backend/node-typescript.md +625 -0
  212. package/expertise/backend/python-fastapi.md +724 -0
  213. package/expertise/backend/rust.md +458 -0
  214. package/expertise/backend/solidity.md +711 -0
  215. package/expertise/composition-map.yaml +443 -0
  216. package/expertise/content/foundations/content-modeling.md +395 -0
  217. package/expertise/content/foundations/editorial-standards.md +449 -0
  218. package/expertise/content/foundations/index.md +24 -0
  219. package/expertise/content/foundations/microcopy.md +455 -0
  220. package/expertise/content/foundations/terminology-governance.md +509 -0
  221. package/expertise/content/index.md +34 -0
  222. package/expertise/content/patterns/accessibility-copy.md +518 -0
  223. package/expertise/content/patterns/index.md +24 -0
  224. package/expertise/content/patterns/notification-content.md +433 -0
  225. package/expertise/content/patterns/sample-content.md +486 -0
  226. package/expertise/content/patterns/state-copy.md +439 -0
  227. package/expertise/design/PROGRESS.md +58 -0
  228. package/expertise/design/disciplines/dark-mode-theming.md +577 -0
  229. package/expertise/design/disciplines/design-systems.md +595 -0
  230. package/expertise/design/disciplines/index.md +25 -0
  231. package/expertise/design/disciplines/information-architecture.md +800 -0
  232. package/expertise/design/disciplines/interaction-design.md +788 -0
  233. package/expertise/design/disciplines/responsive-design.md +552 -0
  234. package/expertise/design/disciplines/usability-testing.md +516 -0
  235. package/expertise/design/disciplines/user-research.md +792 -0
  236. package/expertise/design/foundations/accessibility-design.md +796 -0
  237. package/expertise/design/foundations/color-theory.md +797 -0
  238. package/expertise/design/foundations/iconography.md +795 -0
  239. package/expertise/design/foundations/index.md +26 -0
  240. package/expertise/design/foundations/motion-and-animation.md +653 -0
  241. package/expertise/design/foundations/rtl-design.md +585 -0
  242. package/expertise/design/foundations/spacing-and-layout.md +607 -0
  243. package/expertise/design/foundations/typography.md +800 -0
  244. package/expertise/design/foundations/visual-hierarchy.md +761 -0
  245. package/expertise/design/index.md +32 -0
  246. package/expertise/design/patterns/authentication-flows.md +474 -0
  247. package/expertise/design/patterns/content-consumption.md +789 -0
  248. package/expertise/design/patterns/data-display.md +618 -0
  249. package/expertise/design/patterns/e-commerce.md +1494 -0
  250. package/expertise/design/patterns/feedback-and-states.md +642 -0
  251. package/expertise/design/patterns/forms-and-input.md +819 -0
  252. package/expertise/design/patterns/gamification.md +801 -0
  253. package/expertise/design/patterns/index.md +31 -0
  254. package/expertise/design/patterns/microinteractions.md +449 -0
  255. package/expertise/design/patterns/navigation.md +800 -0
  256. package/expertise/design/patterns/notifications.md +705 -0
  257. package/expertise/design/patterns/onboarding.md +700 -0
  258. package/expertise/design/patterns/search-and-filter.md +601 -0
  259. package/expertise/design/patterns/settings-and-preferences.md +768 -0
  260. package/expertise/design/patterns/social-and-community.md +748 -0
  261. package/expertise/design/platforms/desktop-native.md +612 -0
  262. package/expertise/design/platforms/index.md +25 -0
  263. package/expertise/design/platforms/mobile-android.md +825 -0
  264. package/expertise/design/platforms/mobile-cross-platform.md +983 -0
  265. package/expertise/design/platforms/mobile-ios.md +699 -0
  266. package/expertise/design/platforms/tablet.md +794 -0
  267. package/expertise/design/platforms/web-dashboard.md +790 -0
  268. package/expertise/design/platforms/web-responsive.md +550 -0
  269. package/expertise/design/psychology/behavioral-nudges.md +449 -0
  270. package/expertise/design/psychology/cognitive-load.md +1191 -0
  271. package/expertise/design/psychology/error-psychology.md +778 -0
  272. package/expertise/design/psychology/index.md +22 -0
  273. package/expertise/design/psychology/persuasive-design.md +736 -0
  274. package/expertise/design/psychology/user-mental-models.md +623 -0
  275. package/expertise/design/tooling/open-pencil.md +266 -0
  276. package/expertise/frontend/angular.md +1073 -0
  277. package/expertise/frontend/desktop-electron.md +546 -0
  278. package/expertise/frontend/flutter.md +782 -0
  279. package/expertise/frontend/index.md +27 -0
  280. package/expertise/frontend/native-android.md +409 -0
  281. package/expertise/frontend/native-ios.md +490 -0
  282. package/expertise/frontend/react-native.md +1160 -0
  283. package/expertise/frontend/react.md +808 -0
  284. package/expertise/frontend/vue.md +1089 -0
  285. package/expertise/humanize/domain-rules-code.md +79 -0
  286. package/expertise/humanize/domain-rules-content.md +67 -0
  287. package/expertise/humanize/domain-rules-technical-docs.md +56 -0
  288. package/expertise/humanize/index.md +35 -0
  289. package/expertise/humanize/self-audit-checklist.md +87 -0
  290. package/expertise/humanize/sentence-patterns.md +218 -0
  291. package/expertise/humanize/vocabulary-blacklist.md +105 -0
  292. package/expertise/i18n/PROGRESS.md +65 -0
  293. package/expertise/i18n/advanced/accessibility-and-i18n.md +28 -0
  294. package/expertise/i18n/advanced/bidirectional-text-algorithm.md +38 -0
  295. package/expertise/i18n/advanced/complex-scripts.md +30 -0
  296. package/expertise/i18n/advanced/performance-and-i18n.md +27 -0
  297. package/expertise/i18n/advanced/testing-i18n.md +28 -0
  298. package/expertise/i18n/content/content-adaptation.md +23 -0
  299. package/expertise/i18n/content/locale-specific-formatting.md +23 -0
  300. package/expertise/i18n/content/machine-translation-integration.md +28 -0
  301. package/expertise/i18n/content/translation-management.md +29 -0
  302. package/expertise/i18n/foundations/date-time-calendars.md +67 -0
  303. package/expertise/i18n/foundations/i18n-architecture.md +272 -0
  304. package/expertise/i18n/foundations/locale-and-language-tags.md +79 -0
  305. package/expertise/i18n/foundations/numbers-currency-units.md +61 -0
  306. package/expertise/i18n/foundations/pluralization-and-gender.md +109 -0
  307. package/expertise/i18n/foundations/string-externalization.md +236 -0
  308. package/expertise/i18n/foundations/text-direction-bidi.md +241 -0
  309. package/expertise/i18n/foundations/unicode-and-encoding.md +86 -0
  310. package/expertise/i18n/index.md +38 -0
  311. package/expertise/i18n/platform/backend-i18n.md +31 -0
  312. package/expertise/i18n/platform/flutter-i18n.md +148 -0
  313. package/expertise/i18n/platform/native-android-i18n.md +36 -0
  314. package/expertise/i18n/platform/native-ios-i18n.md +36 -0
  315. package/expertise/i18n/platform/react-i18n.md +103 -0
  316. package/expertise/i18n/platform/web-css-i18n.md +81 -0
  317. package/expertise/i18n/rtl/arabic-specific.md +175 -0
  318. package/expertise/i18n/rtl/hebrew-specific.md +149 -0
  319. package/expertise/i18n/rtl/rtl-animations-and-transitions.md +111 -0
  320. package/expertise/i18n/rtl/rtl-forms-and-input.md +161 -0
  321. package/expertise/i18n/rtl/rtl-fundamentals.md +211 -0
  322. package/expertise/i18n/rtl/rtl-icons-and-images.md +181 -0
  323. package/expertise/i18n/rtl/rtl-layout-mirroring.md +252 -0
  324. package/expertise/i18n/rtl/rtl-navigation-and-gestures.md +107 -0
  325. package/expertise/i18n/rtl/rtl-testing-and-qa.md +147 -0
  326. package/expertise/i18n/rtl/rtl-typography.md +160 -0
  327. package/expertise/index.md +113 -0
  328. package/expertise/index.yaml +216 -0
  329. package/expertise/infrastructure/cloud-aws.md +597 -0
  330. package/expertise/infrastructure/cloud-gcp.md +599 -0
  331. package/expertise/infrastructure/cybersecurity.md +816 -0
  332. package/expertise/infrastructure/database-mongodb.md +447 -0
  333. package/expertise/infrastructure/database-postgres.md +400 -0
  334. package/expertise/infrastructure/devops-cicd.md +787 -0
  335. package/expertise/infrastructure/index.md +27 -0
  336. package/expertise/performance/PROGRESS.md +50 -0
  337. package/expertise/performance/backend/api-latency.md +1204 -0
  338. package/expertise/performance/backend/background-jobs.md +506 -0
  339. package/expertise/performance/backend/connection-pooling.md +1209 -0
  340. package/expertise/performance/backend/database-query-optimization.md +515 -0
  341. package/expertise/performance/backend/index.md +23 -0
  342. package/expertise/performance/backend/rate-limiting-and-throttling.md +971 -0
  343. package/expertise/performance/foundations/algorithmic-complexity.md +954 -0
  344. package/expertise/performance/foundations/caching-strategies.md +489 -0
  345. package/expertise/performance/foundations/concurrency-and-parallelism.md +847 -0
  346. package/expertise/performance/foundations/index.md +24 -0
  347. package/expertise/performance/foundations/measuring-and-profiling.md +440 -0
  348. package/expertise/performance/foundations/memory-management.md +964 -0
  349. package/expertise/performance/foundations/performance-budgets.md +1314 -0
  350. package/expertise/performance/index.md +31 -0
  351. package/expertise/performance/infrastructure/auto-scaling.md +1059 -0
  352. package/expertise/performance/infrastructure/cdn-and-edge.md +1081 -0
  353. package/expertise/performance/infrastructure/index.md +22 -0
  354. package/expertise/performance/infrastructure/load-balancing.md +1081 -0
  355. package/expertise/performance/infrastructure/observability.md +1079 -0
  356. package/expertise/performance/mobile/index.md +23 -0
  357. package/expertise/performance/mobile/mobile-animations.md +544 -0
  358. package/expertise/performance/mobile/mobile-memory-battery.md +416 -0
  359. package/expertise/performance/mobile/mobile-network.md +452 -0
  360. package/expertise/performance/mobile/mobile-rendering.md +599 -0
  361. package/expertise/performance/mobile/mobile-startup-time.md +505 -0
  362. package/expertise/performance/platform-specific/flutter-performance.md +647 -0
  363. package/expertise/performance/platform-specific/index.md +22 -0
  364. package/expertise/performance/platform-specific/node-performance.md +1307 -0
  365. package/expertise/performance/platform-specific/postgres-performance.md +1366 -0
  366. package/expertise/performance/platform-specific/react-performance.md +1403 -0
  367. package/expertise/performance/web/bundle-optimization.md +1239 -0
  368. package/expertise/performance/web/image-and-media.md +636 -0
  369. package/expertise/performance/web/index.md +24 -0
  370. package/expertise/performance/web/network-optimization.md +1133 -0
  371. package/expertise/performance/web/rendering-performance.md +1098 -0
  372. package/expertise/performance/web/ssr-and-hydration.md +918 -0
  373. package/expertise/performance/web/web-vitals.md +1374 -0
  374. package/expertise/quality/accessibility.md +985 -0
  375. package/expertise/quality/evidence-based-verification.md +499 -0
  376. package/expertise/quality/index.md +24 -0
  377. package/expertise/quality/ml-model-audit.md +614 -0
  378. package/expertise/quality/performance.md +600 -0
  379. package/expertise/quality/testing-api.md +891 -0
  380. package/expertise/quality/testing-mobile.md +496 -0
  381. package/expertise/quality/testing-web.md +849 -0
  382. package/expertise/security/PROGRESS.md +54 -0
  383. package/expertise/security/agentic-identity.md +540 -0
  384. package/expertise/security/compliance-frameworks.md +601 -0
  385. package/expertise/security/data/data-encryption.md +364 -0
  386. package/expertise/security/data/data-privacy-gdpr.md +692 -0
  387. package/expertise/security/data/database-security.md +1171 -0
  388. package/expertise/security/data/index.md +22 -0
  389. package/expertise/security/data/pii-handling.md +531 -0
  390. package/expertise/security/foundations/authentication.md +1041 -0
  391. package/expertise/security/foundations/authorization.md +603 -0
  392. package/expertise/security/foundations/cryptography.md +1001 -0
  393. package/expertise/security/foundations/index.md +25 -0
  394. package/expertise/security/foundations/owasp-top-10.md +1354 -0
  395. package/expertise/security/foundations/secrets-management.md +1217 -0
  396. package/expertise/security/foundations/secure-sdlc.md +700 -0
  397. package/expertise/security/foundations/supply-chain-security.md +698 -0
  398. package/expertise/security/index.md +31 -0
  399. package/expertise/security/infrastructure/cloud-security-aws.md +1296 -0
  400. package/expertise/security/infrastructure/cloud-security-gcp.md +1376 -0
  401. package/expertise/security/infrastructure/container-security.md +721 -0
  402. package/expertise/security/infrastructure/incident-response.md +1295 -0
  403. package/expertise/security/infrastructure/index.md +24 -0
  404. package/expertise/security/infrastructure/logging-and-monitoring.md +1618 -0
  405. package/expertise/security/infrastructure/network-security.md +1337 -0
  406. package/expertise/security/mobile/index.md +23 -0
  407. package/expertise/security/mobile/mobile-android-security.md +1218 -0
  408. package/expertise/security/mobile/mobile-binary-protection.md +1229 -0
  409. package/expertise/security/mobile/mobile-data-storage.md +1265 -0
  410. package/expertise/security/mobile/mobile-ios-security.md +1401 -0
  411. package/expertise/security/mobile/mobile-network-security.md +1520 -0
  412. package/expertise/security/smart-contract-security.md +594 -0
  413. package/expertise/security/testing/index.md +22 -0
  414. package/expertise/security/testing/penetration-testing.md +1258 -0
  415. package/expertise/security/testing/security-code-review.md +1765 -0
  416. package/expertise/security/testing/threat-modeling.md +1074 -0
  417. package/expertise/security/testing/vulnerability-scanning.md +1062 -0
  418. package/expertise/security/web/api-security.md +586 -0
  419. package/expertise/security/web/cors-and-headers.md +433 -0
  420. package/expertise/security/web/csrf.md +562 -0
  421. package/expertise/security/web/file-upload.md +1477 -0
  422. package/expertise/security/web/index.md +25 -0
  423. package/expertise/security/web/injection.md +1375 -0
  424. package/expertise/security/web/session-management.md +1101 -0
  425. package/expertise/security/web/xss.md +1158 -0
  426. package/exports/README.md +17 -0
  427. package/exports/hosts/claude/.claude/agents/clarifier.md +42 -0
  428. package/exports/hosts/claude/.claude/agents/content-author.md +63 -0
  429. package/exports/hosts/claude/.claude/agents/designer.md +55 -0
  430. package/exports/hosts/claude/.claude/agents/executor.md +55 -0
  431. package/exports/hosts/claude/.claude/agents/learner.md +51 -0
  432. package/exports/hosts/claude/.claude/agents/planner.md +53 -0
  433. package/exports/hosts/claude/.claude/agents/researcher.md +43 -0
  434. package/exports/hosts/claude/.claude/agents/reviewer.md +54 -0
  435. package/exports/hosts/claude/.claude/agents/specifier.md +47 -0
  436. package/exports/hosts/claude/.claude/agents/verifier.md +71 -0
  437. package/exports/hosts/claude/.claude/commands/author.md +42 -0
  438. package/exports/hosts/claude/.claude/commands/clarify.md +38 -0
  439. package/exports/hosts/claude/.claude/commands/design-review.md +46 -0
  440. package/exports/hosts/claude/.claude/commands/design.md +44 -0
  441. package/exports/hosts/claude/.claude/commands/discover.md +37 -0
  442. package/exports/hosts/claude/.claude/commands/execute.md +48 -0
  443. package/exports/hosts/claude/.claude/commands/learn.md +38 -0
  444. package/exports/hosts/claude/.claude/commands/plan-review.md +42 -0
  445. package/exports/hosts/claude/.claude/commands/plan.md +39 -0
  446. package/exports/hosts/claude/.claude/commands/prepare-next.md +37 -0
  447. package/exports/hosts/claude/.claude/commands/review.md +40 -0
  448. package/exports/hosts/claude/.claude/commands/run-audit.md +41 -0
  449. package/exports/hosts/claude/.claude/commands/spec-challenge.md +41 -0
  450. package/exports/hosts/claude/.claude/commands/specify.md +38 -0
  451. package/exports/hosts/claude/.claude/commands/verify.md +37 -0
  452. package/exports/hosts/claude/.claude/settings.json +34 -0
  453. package/exports/hosts/claude/CLAUDE.md +19 -0
  454. package/exports/hosts/claude/export.manifest.json +38 -0
  455. package/exports/hosts/claude/host-package.json +67 -0
  456. package/exports/hosts/codex/AGENTS.md +19 -0
  457. package/exports/hosts/codex/export.manifest.json +38 -0
  458. package/exports/hosts/codex/host-package.json +41 -0
  459. package/exports/hosts/cursor/.cursor/hooks.json +16 -0
  460. package/exports/hosts/cursor/.cursor/rules/wazir-core.mdc +19 -0
  461. package/exports/hosts/cursor/export.manifest.json +38 -0
  462. package/exports/hosts/cursor/host-package.json +42 -0
  463. package/exports/hosts/gemini/GEMINI.md +19 -0
  464. package/exports/hosts/gemini/export.manifest.json +38 -0
  465. package/exports/hosts/gemini/host-package.json +41 -0
  466. package/hooks/README.md +18 -0
  467. package/hooks/definitions/loop_cap_guard.yaml +21 -0
  468. package/hooks/definitions/post_tool_capture.yaml +24 -0
  469. package/hooks/definitions/pre_compact_summary.yaml +19 -0
  470. package/hooks/definitions/pre_tool_capture_route.yaml +19 -0
  471. package/hooks/definitions/protected_path_write_guard.yaml +19 -0
  472. package/hooks/definitions/session_start.yaml +19 -0
  473. package/hooks/definitions/stop_handoff_harvest.yaml +20 -0
  474. package/hooks/loop-cap-guard +17 -0
  475. package/hooks/post-tool-lint +36 -0
  476. package/hooks/protected-path-write-guard +17 -0
  477. package/hooks/session-start +41 -0
  478. package/llms-full.txt +2355 -0
  479. package/llms.txt +43 -0
  480. package/package.json +79 -0
  481. package/roles/README.md +20 -0
  482. package/roles/clarifier.md +42 -0
  483. package/roles/content-author.md +63 -0
  484. package/roles/designer.md +55 -0
  485. package/roles/executor.md +55 -0
  486. package/roles/learner.md +51 -0
  487. package/roles/planner.md +53 -0
  488. package/roles/researcher.md +43 -0
  489. package/roles/reviewer.md +54 -0
  490. package/roles/specifier.md +47 -0
  491. package/roles/verifier.md +71 -0
  492. package/schemas/README.md +24 -0
  493. package/schemas/accepted-learning.schema.json +20 -0
  494. package/schemas/author-artifact.schema.json +156 -0
  495. package/schemas/clarification.schema.json +19 -0
  496. package/schemas/design-artifact.schema.json +80 -0
  497. package/schemas/docs-claim.schema.json +18 -0
  498. package/schemas/export-manifest.schema.json +20 -0
  499. package/schemas/hook.schema.json +67 -0
  500. package/schemas/host-export-package.schema.json +18 -0
  501. package/schemas/implementation-plan.schema.json +19 -0
  502. package/schemas/proposed-learning.schema.json +19 -0
  503. package/schemas/research.schema.json +18 -0
  504. package/schemas/review.schema.json +29 -0
  505. package/schemas/run-manifest.schema.json +18 -0
  506. package/schemas/spec-challenge.schema.json +18 -0
  507. package/schemas/spec.schema.json +20 -0
  508. package/schemas/usage.schema.json +102 -0
  509. package/schemas/verification-proof.schema.json +29 -0
  510. package/schemas/wazir-manifest.schema.json +173 -0
  511. package/skills/README.md +40 -0
  512. package/skills/brainstorming/SKILL.md +77 -0
  513. package/skills/debugging/SKILL.md +50 -0
  514. package/skills/design/SKILL.md +61 -0
  515. package/skills/dispatching-parallel-agents/SKILL.md +128 -0
  516. package/skills/executing-plans/SKILL.md +70 -0
  517. package/skills/finishing-a-development-branch/SKILL.md +169 -0
  518. package/skills/humanize/SKILL.md +123 -0
  519. package/skills/init-pipeline/SKILL.md +124 -0
  520. package/skills/prepare-next/SKILL.md +20 -0
  521. package/skills/receiving-code-review/SKILL.md +123 -0
  522. package/skills/requesting-code-review/SKILL.md +105 -0
  523. package/skills/requesting-code-review/code-reviewer.md +108 -0
  524. package/skills/run-audit/SKILL.md +197 -0
  525. package/skills/scan-project/SKILL.md +41 -0
  526. package/skills/self-audit/SKILL.md +153 -0
  527. package/skills/subagent-driven-development/SKILL.md +154 -0
  528. package/skills/subagent-driven-development/code-quality-reviewer-prompt.md +26 -0
  529. package/skills/subagent-driven-development/implementer-prompt.md +102 -0
  530. package/skills/subagent-driven-development/spec-reviewer-prompt.md +61 -0
  531. package/skills/tdd/SKILL.md +23 -0
  532. package/skills/using-git-worktrees/SKILL.md +163 -0
  533. package/skills/using-skills/SKILL.md +95 -0
  534. package/skills/verification/SKILL.md +22 -0
  535. package/skills/wazir/SKILL.md +463 -0
  536. package/skills/writing-plans/SKILL.md +30 -0
  537. package/skills/writing-skills/SKILL.md +157 -0
  538. package/skills/writing-skills/anthropic-best-practices.md +122 -0
  539. package/skills/writing-skills/persuasion-principles.md +50 -0
  540. package/templates/README.md +20 -0
  541. package/templates/artifacts/README.md +10 -0
  542. package/templates/artifacts/accepted-learning.md +19 -0
  543. package/templates/artifacts/accepted-learning.template.json +12 -0
  544. package/templates/artifacts/author.md +74 -0
  545. package/templates/artifacts/author.template.json +19 -0
  546. package/templates/artifacts/clarification.md +21 -0
  547. package/templates/artifacts/clarification.template.json +12 -0
  548. package/templates/artifacts/execute-notes.md +19 -0
  549. package/templates/artifacts/implementation-plan.md +21 -0
  550. package/templates/artifacts/implementation-plan.template.json +11 -0
  551. package/templates/artifacts/learning-proposal.md +19 -0
  552. package/templates/artifacts/next-run-handoff.md +21 -0
  553. package/templates/artifacts/plan-review.md +19 -0
  554. package/templates/artifacts/proposed-learning.template.json +12 -0
  555. package/templates/artifacts/research.md +21 -0
  556. package/templates/artifacts/research.template.json +12 -0
  557. package/templates/artifacts/review-findings.md +19 -0
  558. package/templates/artifacts/review.template.json +11 -0
  559. package/templates/artifacts/run-manifest.template.json +8 -0
  560. package/templates/artifacts/spec-challenge.md +19 -0
  561. package/templates/artifacts/spec-challenge.template.json +11 -0
  562. package/templates/artifacts/spec.md +21 -0
  563. package/templates/artifacts/spec.template.json +12 -0
  564. package/templates/artifacts/verification-proof.md +19 -0
  565. package/templates/artifacts/verification-proof.template.json +11 -0
  566. package/templates/examples/accepted-learning.example.json +14 -0
  567. package/templates/examples/author.example.json +152 -0
  568. package/templates/examples/clarification.example.json +15 -0
  569. package/templates/examples/docs-claim.example.json +8 -0
  570. package/templates/examples/export-manifest.example.json +7 -0
  571. package/templates/examples/host-export-package.example.json +11 -0
  572. package/templates/examples/implementation-plan.example.json +17 -0
  573. package/templates/examples/proposed-learning.example.json +13 -0
  574. package/templates/examples/research.example.json +15 -0
  575. package/templates/examples/research.example.md +6 -0
  576. package/templates/examples/review.example.json +17 -0
  577. package/templates/examples/run-manifest.example.json +9 -0
  578. package/templates/examples/spec-challenge.example.json +14 -0
  579. package/templates/examples/spec.example.json +21 -0
  580. package/templates/examples/verification-proof.example.json +21 -0
  581. package/templates/examples/wazir-manifest.example.yaml +65 -0
  582. package/templates/task-definition-schema.md +99 -0
  583. package/tooling/README.md +20 -0
  584. package/tooling/src/adapters/context-mode.js +50 -0
  585. package/tooling/src/capture/command.js +376 -0
  586. package/tooling/src/capture/store.js +99 -0
  587. package/tooling/src/capture/usage.js +270 -0
  588. package/tooling/src/checks/branches.js +50 -0
  589. package/tooling/src/checks/brand-truth.js +110 -0
  590. package/tooling/src/checks/changelog.js +231 -0
  591. package/tooling/src/checks/command-registry.js +36 -0
  592. package/tooling/src/checks/commits.js +102 -0
  593. package/tooling/src/checks/docs-drift.js +103 -0
  594. package/tooling/src/checks/docs-truth.js +201 -0
  595. package/tooling/src/checks/runtime-surface.js +156 -0
  596. package/tooling/src/cli.js +116 -0
  597. package/tooling/src/command-options.js +56 -0
  598. package/tooling/src/commands/validate.js +320 -0
  599. package/tooling/src/doctor/command.js +91 -0
  600. package/tooling/src/export/command.js +77 -0
  601. package/tooling/src/export/compiler.js +498 -0
  602. package/tooling/src/guards/loop-cap-guard.js +52 -0
  603. package/tooling/src/guards/protected-path-write-guard.js +67 -0
  604. package/tooling/src/index/command.js +152 -0
  605. package/tooling/src/index/storage.js +1061 -0
  606. package/tooling/src/index/summarizers.js +261 -0
  607. package/tooling/src/loaders.js +18 -0
  608. package/tooling/src/project-root.js +22 -0
  609. package/tooling/src/recall/command.js +225 -0
  610. package/tooling/src/schema-validator.js +30 -0
  611. package/tooling/src/state-root.js +40 -0
  612. package/tooling/src/status/command.js +71 -0
  613. package/wazir.manifest.yaml +135 -0
  614. package/workflows/README.md +19 -0
  615. package/workflows/author.md +42 -0
  616. package/workflows/clarify.md +38 -0
  617. package/workflows/design-review.md +46 -0
  618. package/workflows/design.md +44 -0
  619. package/workflows/discover.md +37 -0
  620. package/workflows/execute.md +48 -0
  621. package/workflows/learn.md +38 -0
  622. package/workflows/plan-review.md +42 -0
  623. package/workflows/plan.md +39 -0
  624. package/workflows/prepare-next.md +37 -0
  625. package/workflows/review.md +40 -0
  626. package/workflows/run-audit.md +41 -0
  627. package/workflows/spec-challenge.md +41 -0
  628. package/workflows/specify.md +38 -0
  629. package/workflows/verify.md +37 -0
@@ -0,0 +1,574 @@
1
+ # Data Consistency — Architecture Expertise Module
2
+
3
+ > Data consistency defines the guarantees about whether all parts of a system see the same data at the same time. The spectrum ranges from strong consistency (every read sees the latest write) to eventual consistency (reads may see stale data temporarily). This is the hardest trade-off in distributed systems and the source of the most subtle production bugs. Getting consistency wrong does not produce loud failures — it produces silent corruption, phantom states, and business logic that "works" until it costs you money.
4
+
5
+ > **Category:** Data
6
+ > **Complexity:** Complex
7
+ > **Applies when:** Any system with more than one data store, any distributed system, any system with concurrent writes, any system using caching, any system where two services share ownership of a business invariant
8
+
9
+ ---
10
+
11
+ ## What This Is
12
+
13
+ ### The Consistency Spectrum
14
+
15
+ Consistency is not binary. It is a spectrum of guarantees, each with different costs. Understanding the spectrum is prerequisite to making any rational architecture decision about data.
16
+
17
+ **Linearizability (Strongest).** Every operation appears to take effect instantaneously at some point between its invocation and its response. Once a write completes, every subsequent read — from any node, any client, any region — sees that write. This is the gold standard. It is also the most expensive guarantee to provide because it requires global coordination on every operation. Google Spanner achieves this using atomic clocks (TrueTime) and GPS receivers in every data center. CockroachDB approximates it using hybrid logical clocks with bounded clock skew. The cost: cross-region writes in Spanner take 10-15ms minimum due to the coordination round-trip, and CockroachDB cannot guarantee external consistency for transactions involving non-overlapping keys.
18
+
19
+ **Sequential Consistency.** All operations appear in some total order that is consistent with the program order of each individual client. The key difference from linearizability: the total order does not need to respect real-time ordering across clients. If client A writes a value and then calls client B on the phone to say "I wrote it," sequential consistency does not guarantee that client B's next read sees the write. Linearizability does. In practice, few systems explicitly offer sequential consistency as a named guarantee, but many systems behave this way under certain configurations.
20
+
21
+ **Causal Consistency.** Operations that are causally related are seen by all nodes in the same order. Operations that are not causally related (concurrent) may be seen in different orders by different nodes. "Causally related" means: if operation A could have influenced operation B (A happened before B in the same session, or B read a value written by A), then every node must see A before B. This is strictly weaker than sequential consistency but captures the ordering that humans intuitively expect. MongoDB offers causal consistency sessions. CRDT-based systems like Riak often provide causal consistency.
22
+
23
+ **Read-Your-Writes Consistency.** A client always sees its own writes. If you update your profile name and immediately reload the page, you see the new name — even if other users might briefly see the old one. This is the minimum consistency level that prevents users from thinking the system is broken. It says nothing about what other clients see. DynamoDB's strongly consistent reads provide this. Many systems implement it by routing a client's reads to the same replica that handled the write, or by tracking a write timestamp and waiting for replicas to catch up.
24
+
25
+ **Monotonic Reads.** Once a client has seen a value, it never sees an older value in subsequent reads. Without this guarantee, a user could refresh a page and see data "go backwards" — a comment appears, then disappears, then reappears. This happens in systems where reads are load-balanced across replicas with different replication lag. Session affinity (sticky sessions) is the most common way to provide monotonic reads.
26
+
27
+ **Eventual Consistency (Weakest Named Model).** If no new updates are made to a given data item, eventually all reads will return the last updated value. This is a liveness guarantee only — it says something good will eventually happen, but it provides no safety guarantees about what happens in the meantime. Any intermediate value is legal. Any ordering of intermediate values is legal. The convergence time is unbounded. DNS is the most widely deployed eventually consistent system. DynamoDB's default read mode is eventually consistent. Cassandra with quorum reads offers tunable consistency but defaults to eventual.
28
+
29
+ ### ACID vs. BASE: Two Philosophies
30
+
31
+ **ACID** (Atomicity, Consistency, Isolation, Durability) is the traditional database transaction model. Critically, "Consistency" in ACID means something different from "Consistency" in CAP theorem or in the models above. ACID consistency means that a transaction moves the database from one valid state to another — it preserves application-defined invariants (foreign keys, unique constraints, check constraints). ACID is a property of a single database. It says nothing about distributed systems.
32
+
33
+ **BASE** (Basically Available, Soft-state, Eventually consistent) is the alternative philosophy for distributed systems that prioritize availability. It accepts that the system's state may be in flux and that consistency will be achieved over time rather than per-transaction. BASE is not an acronym anyone designed carefully — it was coined as a contrast to ACID. The real content is: accept temporary inconsistency in exchange for availability and partition tolerance.
34
+
35
+ The confusion between ACID consistency and CAP consistency causes more architectural mistakes than any other terminology problem in distributed systems. ACID consistency is about invariant preservation within a single database. CAP consistency is about whether all nodes see the same data at the same time. A system can be ACID-compliant locally and eventually consistent globally.
36
+
37
+ ---
38
+
39
+ ## When to Use Strong Consistency
40
+
41
+ ### The Non-Negotiable Cases
42
+
43
+ Apply strong consistency when the cost of even temporary inconsistency exceeds the cost of reduced availability or increased latency. The test is not "would inconsistency be inconvenient?" but "would inconsistency cause irrecoverable harm?"
44
+
45
+ **Financial transactions and account balances.** A bank account with $100 receives two concurrent withdrawal requests for $80 each. Under eventual consistency, both reads see $100, both approve, and the account goes to -$60. Under strong consistency, the second transaction sees the result of the first and is rejected. This is not a theoretical concern — it is the fundamental reason banking systems have always used serializable transactions. Payment processors like Stripe use strongly consistent datastores for balance tracking and ledger writes.
46
+
47
+ **Inventory management and reservation systems.** An e-commerce platform with one unit of a limited-edition item receives two concurrent purchase requests. Under eventual consistency, both succeed, creating an oversell. One customer receives the item; the other receives an apology email and a refund. This damages trust and may violate consumer protection regulations. Amazon's inventory system uses strong consistency for stock decrement operations even though most of Amazon's infrastructure is famously eventually consistent. The consistency boundary is drawn precisely at the point where money changes hands.
48
+
49
+ **Booking and scheduling systems.** A hotel room, a flight seat, a doctor's appointment slot — these are unique resources that cannot be double-allocated. The "sorry, that slot was just taken" experience is acceptable when shown immediately. The "your booking was confirmed but actually someone else got it" experience is not. Airlines use strongly consistent systems for seat assignment even when the rest of the booking flow uses eventual consistency.
50
+
51
+ **Unique constraint enforcement.** Usernames, email addresses, phone numbers, license plates, serial numbers — anything that must be globally unique requires a single source of truth that is consulted synchronously. If two users simultaneously register with the same username under eventual consistency, both succeed, and the system must later resolve the conflict — often by locking one user out of their account.
52
+
53
+ **Distributed locking and leader election.** When exactly one node must hold a lock or be the leader, the system that manages the lock must be strongly consistent. This is why etcd, ZooKeeper, and Consul use consensus protocols (Raft, Paxos/ZAB) internally. A lock service that is eventually consistent is not a lock service — it is a suggestion service.
54
+
55
+ **Sequential processing guarantees.** When events must be processed in exact order — financial ledger entries, legal audit trails, compliance event logs — the ordering guarantee requires strong consistency at the sequencing layer. Out-of-order processing of a credit followed by a debit (seen as debit-then-credit) can trigger overdraft fees, fraud alerts, or regulatory violations.
56
+
57
+ ---
58
+
59
+ ## When to Use Eventual Consistency
60
+
61
+ ### Where Temporary Staleness Is Acceptable
62
+
63
+ Eventual consistency is not a compromise — it is a deliberate architectural choice that unlocks availability, latency, and scalability that strong consistency cannot provide.
64
+
65
+ **Social media feeds and timelines.** If a user posts a photo and their friend sees it 2 seconds later instead of immediately, no business value is lost. Twitter/X, Instagram, and Facebook all use eventually consistent feeds. The feed is a materialized view assembled from many sources — the post service, the follow graph, the ranking algorithm. Requiring strong consistency across all of these would make feeds unservably slow.
66
+
67
+ **Analytics and reporting dashboards.** A dashboard showing "orders in the last 24 hours" does not need real-time consistency. A 30-second lag is invisible to the user and allows the analytics pipeline to batch-process events efficiently. Most business intelligence systems operate on eventually consistent data warehouses (Snowflake, BigQuery, Redshift) refreshed on a schedule.
68
+
69
+ **Content delivery and caching.** CDN-cached content is inherently eventually consistent. When you update a blog post, edge nodes around the world serve the old version until their cache TTL expires. This is not a bug — it is the fundamental mechanism that makes CDNs fast. Fighting this with aggressive cache invalidation reintroduces the coordination costs that caching was meant to avoid.
70
+
71
+ **Notification systems.** Email, push notifications, SMS alerts — these are inherently asynchronous and tolerant of delay. A notification delivered 5 seconds late is indistinguishable from one delivered on time. Notification systems that try to be strongly consistent with the source event create coupling that makes both systems fragile.
72
+
73
+ **Search indexes.** When a product is added to a catalog, the search index does not need to reflect it instantly. Elasticsearch, Solr, and Algolia all operate as eventually consistent read replicas of the source of truth. A product being unsearchable for a few seconds after creation is a non-event. A search index that blocks catalog writes until the index is updated is a catastrophe waiting to happen.
74
+
75
+ **User presence and activity indicators.** "Online," "typing," "last seen 5 minutes ago" — these are inherently approximate. Showing a user as "online" for 30 seconds after they close the app is not a bug worth solving with distributed consensus.
76
+
77
+ **Recommendation engines.** Whether a recommendation algorithm uses data from 1 second ago or 10 seconds ago has negligible impact on recommendation quality. Recommendation systems process events in batch or micro-batch (Spark, Flink) and serve results from a pre-computed, eventually consistent store.
78
+
79
+ ---
80
+
81
+ ## When NOT to Use Eventual Consistency
82
+
83
+ This section is as important as the previous one. Eventual consistency is frequently chosen for systems where it creates subtle, expensive, hard-to-diagnose bugs. The failure mode is not "the system crashes" — it is "the system silently does the wrong thing 0.1% of the time, and that 0.1% costs millions."
84
+
85
+ ### The Oversell Problem
86
+
87
+ An e-commerce platform uses eventual consistency for inventory counts. Under normal load, replication lag is 50ms and no one notices. During a flash sale, lag spikes to 5 seconds. In those 5 seconds, 200 customers purchase the last 50 units of a limited item. 150 orders must be cancelled after confirmation. Customers who cleared their schedule to participate in the sale receive cancellation emails. Trust is destroyed. Social media backlash follows. This is not hypothetical — it is a recurring pattern in flash sale systems that underestimate the consistency requirements of inventory decrement under high concurrency.
88
+
89
+ ### The Double-Charge Problem
90
+
91
+ A payment service uses eventual consistency between the payment intent service and the ledger service. A customer clicks "pay" twice due to a slow page load. Both requests hit different nodes. Both nodes check the ledger — neither sees the other's pending charge because replication has not converged. The customer is charged twice. The refund process takes 5-10 business days. The customer disputes the charge with their bank, triggering a chargeback process that costs the merchant $15-25 in fees regardless of the refund.
92
+
93
+ ### The Ghost State Problem
94
+
95
+ A microservices system uses eventual consistency between the order service and the shipping service. A customer cancels an order. The order service marks it as cancelled. The shipping service, reading from a stale replica, does not see the cancellation and ships the item. The customer receives an item they cancelled, must arrange a return, and loses confidence in the system. The company pays for shipping both ways. This pattern is so common in microservice architectures that it has a name: the "ghost state" problem — an entity exists in a state that should be impossible given the current state of the system.
96
+
97
+ ### The Stale Read → Write Problem
98
+
99
+ A service reads an entity from an eventually consistent projection to perform an update. The projection is 500ms behind the source. The service reads stale data, applies a transformation to it, and writes the result back. The transformation overwrites changes that were made in the 500ms gap. This is a lost update, and it is permanent — unlike the temporary inconsistency that eventual consistency promises will resolve, this data loss is irrecoverable because the stale read was used as input to a new write.
100
+
101
+ ### The Consistency Boundary Rule
102
+
103
+ The general principle: eventual consistency is safe when the consumer of stale data is a human (who can refresh, retry, or tolerate delay). Eventual consistency is dangerous when the consumer of stale data is another service that makes automated decisions based on it. Machines act on stale data immediately and irrevocably. Humans notice and compensate.
104
+
105
+ ---
106
+
107
+ ## How It Works
108
+
109
+ ### Two-Phase Commit (2PC)
110
+
111
+ The oldest distributed transaction protocol. A coordinator asks all participants to prepare (vote yes/no), then tells them all to commit or abort based on the unanimous vote.
112
+
113
+ **Phase 1 (Prepare):** The coordinator sends a prepare request to all participants. Each participant executes the transaction locally, acquires locks, writes to a local transaction log, and votes yes or no. The locks are held until phase 2 completes.
114
+
115
+ **Phase 2 (Commit/Abort):** If all participants voted yes, the coordinator sends commit. If any voted no, the coordinator sends abort. Participants release locks after completing the commit/abort.
116
+
117
+ **The fundamental problems with 2PC:**
118
+
119
+ 1. **Blocking on coordinator failure.** If the coordinator crashes after collecting votes but before sending the commit/abort decision, all participants hold their locks indefinitely. They cannot unilaterally decide to commit (another participant might have voted no) or abort (they might have all voted yes). The system is stuck until the coordinator recovers. This is not a theoretical concern — it is the reason 2PC has been largely abandoned for cross-service transactions in microservice architectures.
120
+
121
+ 2. **Latency.** 2PC requires at minimum 2 round-trips between coordinator and every participant. In a system with 5 participants across 3 regions, this can take 200-400ms per transaction. For comparison, a local PostgreSQL transaction takes 1-5ms.
122
+
123
+ 3. **Lock duration.** Locks are held for the entire duration of both phases. In microservices, where participants include external services with unpredictable latency (payment gateways, shipping APIs), locks can be held for seconds. During that time, all other transactions touching the same data are blocked.
124
+
125
+ 4. **Homogeneity requirement.** 2PC requires all participants to implement the XA transaction protocol. This works when all participants are relational databases. It does not work when participants include a message queue, a cache, an external API, and a NoSQL store.
126
+
127
+ ### Three-Phase Commit (3PC)
128
+
129
+ 3PC adds a pre-commit phase between voting and committing to reduce the blocking window. In theory, it allows participants to make progress if the coordinator fails. In practice, 3PC is rarely implemented because it does not handle network partitions correctly — in a partition, different sides can reach different decisions (one side commits, the other aborts), producing inconsistency. 3PC solves the blocking problem of 2PC at the cost of potentially violating consistency — the opposite of the intended trade-off.
130
+
131
+ ### Consensus Protocols (Paxos, Raft)
132
+
133
+ Consensus protocols solve the problem of getting a group of nodes to agree on a value in the presence of failures. Unlike 2PC, they can make progress as long as a majority of nodes are available (they tolerate minority failures).
134
+
135
+ **Paxos** (Lamport, 1989): The foundational consensus protocol. Notoriously difficult to understand and implement correctly. Google uses Multi-Paxos internally for Spanner, Chubby, and Megastore. The key insight: a value is chosen when a majority of acceptors accept the same proposal. This guarantees safety (only one value is chosen) even under arbitrary message delays and node failures.
136
+
137
+ **Raft** (Ongaro & Ousterhout, 2014): Designed explicitly for understandability. Decomposes consensus into leader election, log replication, and safety. Used by etcd (Kubernetes), CockroachDB, TiDB, and Consul. Raft achieves the same safety guarantees as Paxos but with a clearer separation of concerns. The leader handles all client requests and replicates to followers. If the leader fails, a new election occurs. During election, the system is briefly unavailable for writes (typically <1 second).
138
+
139
+ ### The Saga Pattern
140
+
141
+ Sagas replace a single distributed transaction with a sequence of local transactions, each with a compensating transaction that undoes its effect if a later step fails.
142
+
143
+ **Orchestration-based sagas:** A central orchestrator directs the sequence. The orchestrator calls service A, waits for success, calls service B, waits for success, and so on. If service C fails, the orchestrator calls compensating transactions for B and A in reverse order. The orchestrator is a single point of coordination but not a single point of failure (it can be replicated and its state can be persisted).
144
+
145
+ **Choreography-based sagas:** Each service listens for events and acts independently. Service A completes and emits an event. Service B hears the event, does its work, and emits its own event. If service C fails, it emits a failure event, and services B and A hear it and execute their compensating transactions. No central coordinator. More decoupled. Harder to debug and reason about because the saga's state is distributed across event logs.
146
+
147
+ **The critical limitation of sagas:** Between the time a local transaction commits and the compensating transaction executes (if needed), the system is in an inconsistent state. A hotel room is booked but the flight is not yet confirmed. A payment is charged but the order is not yet created. This intermediate state is visible to other transactions and to users. Sagas provide eventual consistency, not atomicity. Designing compensating transactions that are correct, idempotent, and commutative is the hardest part of saga implementation.
148
+
149
+ ### The Transactional Outbox Pattern
150
+
151
+ The outbox pattern solves the dual-write problem: when a service needs to update its database AND publish an event, and both must happen or neither must happen.
152
+
153
+ **How it works:** Instead of publishing the event directly to a message broker, the service writes the event to an "outbox" table in the same database, within the same local transaction as the business data change. A separate process (a poller or a CDC connector) reads the outbox table and publishes events to the message broker. Because the business write and the outbox write are in the same transaction, they are atomic. The outbox reader provides at-least-once delivery.
154
+
155
+ **Implementation with Change Data Capture (CDC):** Instead of polling the outbox table, a CDC tool like Debezium reads the database's transaction log (WAL in PostgreSQL, binlog in MySQL) and streams changes to Kafka. This eliminates the polling overhead and captures changes with very low latency (sub-second). Debezium's outbox event router is purpose-built for this pattern.
156
+
157
+ **Why this matters for consistency:** The outbox pattern converts the impossible problem of distributed atomicity (database + message broker) into the solved problem of local atomicity (single database transaction) plus reliable delivery (at-least-once with idempotent consumers). It is the most practical consistency pattern for microservice event-driven architectures.
158
+
159
+ ### Read-After-Write Consistency Techniques
160
+
161
+ When a system uses eventually consistent replicas for reads but needs read-your-writes consistency:
162
+
163
+ 1. **Read from the leader after writing.** For a configurable window after a write (e.g., 5 seconds), route that client's reads to the primary/leader node. After the window, resume reading from replicas. This is a common pattern with PostgreSQL streaming replication.
164
+
165
+ 2. **Track the write position.** After a write, return the WAL position (LSN in PostgreSQL) to the client. On subsequent reads, the client passes this position and the replica waits until it has replicated past that point before serving the read. This is how Amazon Aurora provides read-after-write consistency across read replicas.
166
+
167
+ 3. **Session affinity.** Route all requests from the same session to the same replica. As long as that replica is not further behind than the write latency, the user sees their own writes. This breaks if the replica fails over.
168
+
169
+ ### Compensating Transactions
170
+
171
+ When a saga step fails and previous steps must be undone, compensating transactions reverse the effect of committed local transactions. Key design requirements:
172
+
173
+ - **Idempotency.** A compensating transaction may be retried (the message broker delivers the compensation command more than once). It must produce the same result regardless of how many times it runs.
174
+ - **Commutativity.** If multiple compensating transactions execute concurrently, the final state must be correct regardless of order.
175
+ - **Semantic reversal, not undo.** A compensating transaction for "charge $100" is "refund $100," not "delete the charge record." The original action happened and must remain in the audit trail.
176
+
177
+ ---
178
+
179
+ ## Trade-Offs Matrix
180
+
181
+ | Dimension | Strong Consistency | Eventual Consistency | Notes |
182
+ |---|---|---|---|
183
+ | **Availability** | Lower — cannot serve requests during partitions if it must guarantee consistency (CP in CAP) | Higher — can serve requests from any replica, even during partitions (AP in CAP) | CAP theorem makes this a hard physical constraint, not a design choice |
184
+ | **Latency (writes)** | Higher — writes require coordination across replicas before acknowledging (10-400ms for geo-distributed) | Lower — writes acknowledge after local commit (1-5ms), replicate asynchronously | Spanner: ~14ms global write. DynamoDB eventual: ~5ms write |
185
+ | **Latency (reads)** | Can be higher if reads must go to leader; comparable if read replicas are used with version tracking | Lower — any replica can serve reads immediately | Read-your-writes adds modest latency (~1-2ms for version check) |
186
+ | **Scalability (write)** | Limited — all writes go through consensus or coordination, creating a throughput ceiling | Higher — writes can be distributed across nodes without coordination | CockroachDB: ~7,000 writes/sec per range. Cassandra: ~50,000+ writes/sec per node |
187
+ | **Scalability (read)** | Comparable — read replicas can serve reads if staleness is acceptable for non-critical reads | Higher — more replicas = more read throughput with no consistency overhead | Many systems use strong writes + eventual reads as a hybrid |
188
+ | **Correctness guarantees** | Absolute — every read sees the latest write; invariants are always maintained | Probabilistic — most reads see the latest write; invariants may be temporarily violated | "Temporarily" can mean milliseconds or minutes depending on load |
189
+ | **Operational complexity** | Higher — consensus protocols, leader election, split-brain prevention | Lower setup, but higher debugging complexity when consistency bugs occur | Eventual consistency bugs are intermittent and hard to reproduce |
190
+ | **Data loss risk** | Lower — acknowledged writes are durable across multiple replicas | Higher — if a node fails before replication, acknowledged writes can be lost | Async replication = data loss window equal to replication lag |
191
+ | **Cost** | Higher — requires more network round-trips, more capable hardware, possibly specialized infrastructure (Spanner's TrueTime) | Lower — commodity hardware, simple replication | The cost difference narrows with managed cloud databases |
192
+ | **Developer cognitive load** | Lower — the system behaves like a single machine; reasoning about correctness is straightforward | Higher — developers must reason about stale reads, race conditions, and convergence | Most consistency bugs come from developers who think "eventual" means "fast enough" |
193
+
194
+ ---
195
+
196
+ ## Evolution Path
197
+
198
+ ### Stage 1: Single Database (Strong by Default)
199
+
200
+ Start with a single PostgreSQL or MySQL instance. All reads and writes go to one node. Consistency is trivially strong. This is correct for most applications at launch. Do not introduce distributed consistency concerns until the system genuinely needs to scale beyond what one database can handle.
201
+
202
+ **When to graduate:** When read traffic exceeds what one node can serve (typically 5,000-20,000 queries/second depending on query complexity), or when you need high availability (zero-downtime deployments, failover).
203
+
204
+ ### Stage 2: Read Replicas (Introducing Replication Lag)
205
+
206
+ Add read replicas for read-heavy workloads. Writes go to the primary; reads are distributed across replicas. Replication lag introduces eventual consistency for reads. This is the moment most teams first encounter consistency bugs.
207
+
208
+ **Key decisions at this stage:**
209
+ - Route reads to the primary for a configurable window after writes (read-after-write consistency).
210
+ - Use session affinity to ensure monotonic reads.
211
+ - Monitor replication lag and alert when it exceeds a threshold (e.g., 1 second).
212
+ - Accept that analytics queries on replicas may see slightly stale data.
213
+
214
+ ### Stage 3: Multi-Service (Distributed Consistency Required)
215
+
216
+ As the system evolves into multiple services with separate databases, cross-service consistency becomes the central challenge. Each service owns its data and controls its consistency model.
217
+
218
+ **Key decisions at this stage:**
219
+ - Identify which operations require cross-service consistency (usually: anything involving money, inventory, or unique resources).
220
+ - Implement the outbox pattern for reliable event publishing.
221
+ - Use sagas for cross-service workflows that require atomicity.
222
+ - Accept eventual consistency for non-critical cross-service reads (feed assembly, search indexing, analytics).
223
+ - Establish clear ownership: one service is the source of truth for each piece of data.
224
+
225
+ ### Stage 4: Multi-Region (Geo-Distributed Consistency)
226
+
227
+ When the system spans multiple geographic regions, the speed of light becomes the consistency bottleneck. A round-trip between US-East and EU-West takes ~80ms. Consensus across 3 regions takes ~160ms minimum.
228
+
229
+ **Key decisions at this stage:**
230
+ - Use global consensus (Spanner, CockroachDB) only for data that truly requires global strong consistency (user accounts, billing, configuration).
231
+ - Use regional strong consistency with cross-region eventual consistency for data that is region-primary (user content, session data).
232
+ - Implement conflict resolution strategies for multi-region writes (last-writer-wins, CRDTs, application-level merge).
233
+ - Accept that some operations will have higher latency and design UX accordingly (optimistic UI with reconciliation).
234
+
235
+ ### Stage 5: Hybrid Consistency (Per-Path Tuning)
236
+
237
+ Mature systems apply different consistency models to different data paths within the same application. This is the most sophisticated and most correct approach.
238
+
239
+ **Examples:**
240
+ - **Strong:** Account balance, inventory count, seat reservation.
241
+ - **Causal:** Chat messages (within a conversation), collaborative document edits.
242
+ - **Read-your-writes:** User profile updates, order status after placing an order.
243
+ - **Eventual:** Social feed assembly, search index, recommendation scores, analytics dashboards.
244
+
245
+ This per-path approach maximizes both correctness and performance by applying the minimum consistency level that satisfies each path's business requirements.
246
+
247
+ ---
248
+
249
+ ## Failure Modes
250
+
251
+ ### Split-Brain
252
+
253
+ **What it is:** A network partition causes a cluster to divide into two (or more) sub-clusters, each believing it is the active cluster. Both sub-clusters accept writes independently, creating divergent data states.
254
+
255
+ **Real incident — GitLab (documented post-mortem):** A PostgreSQL cluster experienced a connectivity loss that caused Pacemaker to lose track of the master node. Pacemaker failed over, electing a new master (DB5) while the original master (DB4) continued operating. Both databases acted as master for approximately 30 minutes. Writes that went to DB5 during this period were lost when the split-brain was resolved, because DB5 was designated the "victim" during reconciliation. The data loss window spanned about 6 hours of operations.
256
+
257
+ **Prevention:** Quorum-based systems (Raft, Paxos) prevent split-brain by requiring a majority to make progress. The minority partition cannot elect a leader and stops accepting writes. Fencing mechanisms (STONITH — "Shoot The Other Node In The Head") forcefully shut down nodes that might be operating independently. AWS RDS Multi-AZ uses synchronous replication to the standby, ensuring the standby has all data before a failover.
258
+
259
+ ### Lost Updates
260
+
261
+ **What it is:** Two concurrent transactions read the same value, modify it independently, and write back. The second write overwrites the first, losing the first transaction's update.
262
+
263
+ **Classic example:** Two users read a wiki page (version 5), edit different sections, and save. The second save creates version 6 from their edit of version 5, silently discarding the first user's changes. This is why collaborative editing systems (Google Docs, Notion) use operational transforms or CRDTs rather than read-modify-write cycles.
264
+
265
+ **Prevention:** Optimistic concurrency control (version numbers / ETags). Each record carries a version number. On update, the client sends the version it read. The database rejects the update if the current version does not match (409 Conflict). The client must re-read, re-apply its changes, and retry.
266
+
267
+ ### Write Skew
268
+
269
+ **What it is:** Two concurrent transactions each read an overlapping data set, make disjoint updates based on what they read, and both commit. Neither transaction's update conflicts with the other's update at the row level, but together they violate a business invariant.
270
+
271
+ **Classic example — the on-call doctor problem:** A hospital requires at least one doctor on call at all times. Two doctors (Alice and Bob) are both on call. Alice checks: "Is another doctor on call? Yes (Bob). I can remove myself." Concurrently, Bob checks: "Is another doctor on call? Yes (Alice). I can remove myself." Both transactions commit. Zero doctors are on call. No row-level conflict occurred — Alice updated her own row, Bob updated his own row. But the cross-row invariant (at least one doctor on call) is violated.
272
+
273
+ **Another example — the banking overdraft:** Two accounts held by one person, each with $100. The bank's rule: the combined balance must be >= 0. Two concurrent withdrawals of $200 each, one from each account. Each transaction checks the total ($200), approves the withdrawal, and commits. Final state: both accounts at -$100, combined balance -$200. The invariant is violated.
274
+
275
+ **Prevention:** Serializable isolation level. PostgreSQL's Serializable Snapshot Isolation (SSI) detects write skew by tracking the read sets of concurrent transactions and aborting one if their combined writes could violate serializability. Oracle does NOT detect write skew — its "Serializable" isolation level is actually Snapshot Isolation, which is susceptible to this anomaly. This is a critical distinction when choosing databases for applications with cross-row invariants.
276
+
277
+ ### Phantom Reads
278
+
279
+ **What it is:** A transaction reads a set of rows matching a condition, another transaction inserts a new row matching that condition, and the first transaction re-reads and sees a different set of rows. The "phantom" is the new row that appeared between reads.
280
+
281
+ **Impact:** Phantom reads break aggregate calculations, range queries, and any logic that depends on the completeness of a result set. A report that sums all orders placed today may miss orders inserted between the range query and the sum.
282
+
283
+ **Prevention:** Serializable isolation or predicate locking. PostgreSQL SSI handles this. Repeatable Read in PostgreSQL (which is actually Snapshot Isolation) prevents phantoms for snapshot queries but not for modifications that depend on the absence of rows.
284
+
285
+ ### Dirty Reads
286
+
287
+ **What it is:** A transaction reads data written by another transaction that has not yet committed. If the writing transaction rolls back, the reading transaction has acted on data that never existed.
288
+
289
+ **Prevention:** Any isolation level above Read Uncommitted prevents dirty reads. This is the least concerning anomaly because virtually all production databases default to at least Read Committed.
290
+
291
+ ### Stale Read Cascades
292
+
293
+ **What it is:** A service reads stale data from an eventually consistent store and uses it as input for a write operation or a decision that propagates to other services. The staleness is not corrected by eventual convergence because the stale read has already been consumed and acted upon.
294
+
295
+ **Example:** Service A reads a user's subscription tier from a cache (stale: still shows "premium"). Service A grants the user premium-tier access. The user's subscription actually expired 2 minutes ago. The access grant is logged, billed, and cannot be automatically revoked because Service B (billing) sees the user as expired but Service C (access) sees an active grant from Service A.
296
+
297
+ **Prevention:** For decisions with business consequences, always read from the source of truth, not from caches or eventually consistent projections. Use the CQRS principle: queries can be eventually consistent, but commands must validate against strongly consistent state.
298
+
299
+ ---
300
+
301
+ ## Technology Landscape
302
+
303
+ ### Relational Databases
304
+
305
+ **PostgreSQL** — Offers true Serializable Snapshot Isolation (SSI), the strongest isolation level available in any mainstream database. SSI detects read-write conflicts including write skew and phantom reads without the performance penalty of traditional two-phase locking. PostgreSQL also offers Read Committed (default), Repeatable Read (actually Snapshot Isolation), and Serializable. Streaming replication is asynchronous by default (eventual consistency for replicas) but can be configured as synchronous (strong consistency at the cost of write latency).
306
+
307
+ **MySQL/InnoDB** — Default isolation is Repeatable Read with gap locking. This prevents phantoms for locking reads but not for snapshot reads. MySQL Group Replication (MGR) provides synchronous replication with Paxos-based consensus for multi-primary setups. The XA transaction protocol is supported for distributed transactions across multiple MySQL instances.
308
+
309
+ ### NewSQL / Distributed SQL
310
+
311
+ **Google Cloud Spanner** — Globally distributed with linearizable consistency achieved via TrueTime (atomic clocks + GPS in every data center). External consistency for all transactions — if transaction T1 commits before T2 starts, T2 sees T1's effects. Write latency: ~7ms in a single region, ~14ms globally. The gold standard for strong consistency at global scale, but requires Google's infrastructure.
312
+
313
+ **CockroachDB** — Distributed SQL with serializable isolation by default. Uses Raft for consensus. Provides serializable transactions and read-after-write consistency without atomic clocks. The key trade-off vs. Spanner: CockroachDB cannot guarantee external consistency for transactions on non-overlapping keys because it lacks TrueTime. In practice, this matters only for workloads where the real-time ordering of independent transactions is critical. For most applications, CockroachDB's guarantees are indistinguishable from Spanner's.
314
+
315
+ **TiDB** — MySQL-compatible distributed SQL using Raft. Default isolation is Snapshot Isolation (repeatable read). Offers pessimistic and optimistic transaction modes. Strong consistency within a Raft group; cross-range transactions use two-phase commit with a timestamp oracle.
316
+
317
+ **YugabyteDB** — PostgreSQL-compatible distributed SQL using Raft. Supports serializable and snapshot isolation. Provides strong consistency for writes with tunable consistency for reads (strong or eventual per query).
318
+
319
+ ### NoSQL
320
+
321
+ **Amazon DynamoDB** — Offers two consistency options per read operation: eventually consistent reads (default, higher throughput, lower latency) and strongly consistent reads (reads from the leader node, may have slightly higher latency). Writes are always consistent. DynamoDB Transactions provide ACID semantics across multiple items and tables within a single AWS region.
322
+
323
+ **MongoDB** — Offers tunable consistency through read concerns (local, majority, linearizable, snapshot) and write concerns (1, majority, journaled). Causal consistency sessions ensure that reads within a session reflect prior writes in that session. The writeConcern:majority + readConcern:majority combination provides a pragmatic middle ground.
324
+
325
+ **Apache Cassandra** — Tunable consistency per query. Consistency levels range from ONE (fastest, most available, least consistent) to ALL (slowest, least available, most consistent). QUORUM reads and writes provide strong consistency if R + W > N (read replicas + write replicas > total replicas). LOCAL_QUORUM provides strong consistency within a data center with eventual consistency across data centers.
326
+
327
+ ### Streaming and Event Infrastructure
328
+
329
+ **Apache Kafka** — Provides exactly-once semantics (EOS) within Kafka transactions (producer + consumer + Kafka Streams). This does not extend to external systems — writing to Kafka and a database atomically still requires the outbox pattern or a transactional producer with idempotent consumers. Kafka's replication uses ISR (in-sync replicas); with acks=all, a produced message is durable once all ISR members acknowledge.
330
+
331
+ **Redis** — Single-threaded command processing provides serializable execution on a single node. Redis Cluster uses asynchronous replication — writes acknowledged by the master may be lost if the master fails before replicating. Redis Sentinel provides failover but with the same async replication data loss risk. For use cases requiring consistency, Redis is best used as a cache with a strongly consistent backing store, not as the source of truth.
332
+
333
+ ---
334
+
335
+ ## Decision Tree
336
+
337
+ Use this decision tree to choose the appropriate consistency model for each data path in your system.
338
+
339
+ ```
340
+ START: What is the business impact of temporarily stale data?
341
+
342
+ ├── Financial loss, legal liability, or safety risk
343
+ │ ├── Is the data within a single database?
344
+ │ │ ├── YES → Use SERIALIZABLE isolation (PostgreSQL SSI)
345
+ │ │ └── NO → Is the latency budget > 100ms?
346
+ │ │ ├── YES → Use distributed SQL (Spanner / CockroachDB)
347
+ │ │ └── NO → Use saga pattern with compensating transactions
348
+ │ │ + strong consistency at each local step
349
+ │ └── Examples: payment processing, inventory decrement,
350
+ │ booking/reservation, unique constraint enforcement
351
+
352
+ ├── User confusion or degraded experience (but recoverable)
353
+ │ ├── Is it the user's own data they're reading after writing?
354
+ │ │ ├── YES → Use read-your-writes consistency
355
+ │ │ │ (read from leader for N seconds after write)
356
+ │ │ └── NO → Is ordering important?
357
+ │ │ ├── YES → Use causal consistency (MongoDB sessions)
358
+ │ │ └── NO → Use monotonic reads (session affinity)
359
+ │ └── Examples: profile updates, order status, chat messages,
360
+ │ collaborative editing
361
+
362
+ ├── Negligible impact — staleness is invisible or irrelevant
363
+ │ └── Use eventual consistency with appropriate replication lag
364
+ │ monitoring and alerting
365
+ │ └── Examples: social feeds, search indexes, analytics,
366
+ │ recommendations, notifications, CDN-cached content
367
+
368
+ └── MIXED — different paths in the same system
369
+ └── Apply different consistency models per path
370
+ (this is the correct answer for most real systems)
371
+ ```
372
+
373
+ ### Quick Reference by Domain
374
+
375
+ | Domain | Write Path | Read Path | Recommended Model |
376
+ |---|---|---|---|
377
+ | Financial ledger | Strong (serializable) | Strong for balance queries, eventual for reports | Distributed SQL or serializable local DB |
378
+ | E-commerce inventory | Strong for decrement | Eventual for catalog display, strong for checkout | Hybrid — strong at purchase, eventual for browse |
379
+ | Social media feed | Eventual (async fan-out) | Eventual | Eventual with read-your-writes for own posts |
380
+ | Chat / messaging | Causal (within conversation) | Causal | Causal consistency sessions |
381
+ | Search | N/A (index is a derived view) | Eventual | CDC-powered index with sub-second lag |
382
+ | User authentication | Strong (unique constraints) | Strong | Single primary database |
383
+ | Analytics dashboard | N/A (batch/stream ingest) | Eventual | Data warehouse with scheduled refresh |
384
+ | Configuration / feature flags | Strong | Read-your-writes | Consensus-backed store (etcd, Consul) |
385
+
386
+ ---
387
+
388
+ ## Implementation Sketch
389
+
390
+ ### Outbox Pattern with PostgreSQL + Debezium
391
+
392
+ ```sql
393
+ -- Business table
394
+ CREATE TABLE orders (
395
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
396
+ customer_id UUID NOT NULL,
397
+ total DECIMAL(10,2) NOT NULL,
398
+ status TEXT NOT NULL DEFAULT 'pending',
399
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now()
400
+ );
401
+
402
+ -- Outbox table — same database, same transaction
403
+ CREATE TABLE outbox (
404
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
405
+ aggregate_type TEXT NOT NULL, -- e.g., 'Order'
406
+ aggregate_id UUID NOT NULL, -- e.g., the order ID
407
+ event_type TEXT NOT NULL, -- e.g., 'OrderCreated'
408
+ payload JSONB NOT NULL, -- the event data
409
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now()
410
+ );
411
+
412
+ -- Index for the CDC connector to read in order
413
+ CREATE INDEX idx_outbox_created ON outbox (created_at);
414
+ ```
415
+
416
+ ```python
417
+ # Application code — single transaction for business write + event
418
+ async def create_order(customer_id: str, items: list, total: Decimal):
419
+ async with db.transaction():
420
+ # Business write
421
+ order = await db.execute(
422
+ "INSERT INTO orders (customer_id, total, status) "
423
+ "VALUES ($1, $2, 'pending') RETURNING *",
424
+ customer_id, total
425
+ )
426
+ # Outbox write — same transaction, atomic
427
+ await db.execute(
428
+ "INSERT INTO outbox (aggregate_type, aggregate_id, event_type, payload) "
429
+ "VALUES ('Order', $1, 'OrderCreated', $2)",
430
+ order.id,
431
+ json.dumps({
432
+ "order_id": str(order.id),
433
+ "customer_id": customer_id,
434
+ "total": str(total),
435
+ "items": items
436
+ })
437
+ )
438
+ return order
439
+ ```
440
+
441
+ Debezium reads the PostgreSQL WAL via its outbox event router, publishes `OrderCreated` events to Kafka, and downstream services consume them. If the transaction rolls back, the outbox row is never written, and no event is published. Atomicity is guaranteed by the local database transaction.
442
+
443
+ ### Optimistic Concurrency Control
444
+
445
+ ```python
446
+ async def update_order_status(order_id: str, new_status: str, expected_version: int):
447
+ result = await db.execute(
448
+ "UPDATE orders SET status = $1, version = version + 1 "
449
+ "WHERE id = $2 AND version = $3 "
450
+ "RETURNING *",
451
+ new_status, order_id, expected_version
452
+ )
453
+ if result is None:
454
+ raise ConflictError(
455
+ f"Order {order_id} was modified by another transaction. "
456
+ f"Expected version {expected_version}, current version differs. "
457
+ "Re-read and retry."
458
+ )
459
+ return result
460
+ ```
461
+
462
+ ### Saga Orchestrator (Simplified)
463
+
464
+ ```python
465
+ class OrderSaga:
466
+ """
467
+ Orchestration-based saga for order placement.
468
+ Each step has a forward action and a compensating action.
469
+ """
470
+ steps = [
471
+ SagaStep(
472
+ name="reserve_inventory",
473
+ action=inventory_service.reserve,
474
+ compensate=inventory_service.release_reservation
475
+ ),
476
+ SagaStep(
477
+ name="charge_payment",
478
+ action=payment_service.charge,
479
+ compensate=payment_service.refund
480
+ ),
481
+ SagaStep(
482
+ name="confirm_order",
483
+ action=order_service.confirm,
484
+ compensate=order_service.cancel
485
+ ),
486
+ ]
487
+
488
+ async def execute(self, order_data: dict):
489
+ completed = []
490
+ try:
491
+ for step in self.steps:
492
+ result = await step.action(order_data)
493
+ completed.append((step, result))
494
+ order_data = {**order_data, **result}
495
+ except Exception as e:
496
+ # Compensate in reverse order
497
+ for step, result in reversed(completed):
498
+ try:
499
+ await step.compensate(result)
500
+ except Exception as comp_error:
501
+ # Log for manual intervention — compensation failed
502
+ logger.critical(
503
+ f"Compensation failed for {step.name}: {comp_error}. "
504
+ f"Manual intervention required."
505
+ )
506
+ raise SagaFailedError(f"Saga failed at {step.name}: {e}")
507
+ return order_data
508
+ ```
509
+
510
+ ### Read-After-Write Consistency with Replication Position
511
+
512
+ ```python
513
+ class ConsistentReader:
514
+ """
515
+ Routes reads to the primary for a window after writes,
516
+ or waits for replica to catch up to the write position.
517
+ """
518
+ def __init__(self, primary_pool, replica_pool, consistency_window_ms=5000):
519
+ self.primary = primary_pool
520
+ self.replica = replica_pool
521
+ self.window_ms = consistency_window_ms
522
+ self._last_write = {} # session_id -> (timestamp, lsn)
523
+
524
+ async def read(self, query: str, params: list, session_id: str):
525
+ last = self._last_write.get(session_id)
526
+ if last and (time.now_ms() - last.timestamp) < self.window_ms:
527
+ # Within consistency window — read from primary
528
+ return await self.primary.execute(query, params)
529
+ # Outside window — safe to read from replica
530
+ return await self.replica.execute(query, params)
531
+
532
+ async def write(self, query: str, params: list, session_id: str):
533
+ result = await self.primary.execute(query, params)
534
+ lsn = await self.primary.execute("SELECT pg_current_wal_lsn()")
535
+ self._last_write[session_id] = WritePosition(
536
+ timestamp=time.now_ms(), lsn=lsn
537
+ )
538
+ return result
539
+ ```
540
+
541
+ ---
542
+
543
+ ## Cross-References
544
+
545
+ - **[cap-theorem-and-tradeoffs](../distributed/cap-theorem-and-tradeoffs.md)** — The theoretical foundation for why strong consistency and high availability cannot coexist during network partitions. Data consistency decisions are fundamentally CAP decisions.
546
+ - **[saga-pattern](../patterns/saga-pattern.md)** — Detailed implementation guide for sagas as the primary mechanism for cross-service consistency without distributed transactions.
547
+ - **[distributed-systems-fundamentals](../distributed/distributed-systems-fundamentals.md)** — Foundational concepts (network partitions, failure detection, consensus) that underpin all consistency models.
548
+ - **[data-modeling](../data/data-modeling.md)** — Data model design directly affects which consistency anomalies are possible. Denormalization introduces consistency maintenance burden.
549
+ - **[sql-vs-nosql](../data/sql-vs-nosql.md)** — Database category choice constrains available consistency options. SQL databases default to strong consistency; NoSQL databases offer tunable consistency.
550
+ - **[idempotency-and-retry](../integration/idempotency-and-retry.md)** — Eventual consistency systems require idempotent operations because events may be delivered more than once. Retry logic without idempotency guarantees creates consistency bugs.
551
+
552
+ ---
553
+
554
+ ## Sources
555
+
556
+ - [Consistency Patterns in Distributed Systems - Design Gurus](https://www.designgurus.io/blog/consistency-patterns-distributed-systems)
557
+ - [Engineering Trade-offs: Eventual Consistency in Practice - ByteByteGo](https://blog.bytebytego.com/p/a-guide-to-eventual-consistency-in)
558
+ - [Why Eventual Consistency Fails in Distributed Systems - Works On My Machine](https://medium.com/works-on-my-machine/production-bugs-no-one-teaches-you-2-eventually-consistent-doesnt-mean-eventually-correct-78111bc1aa14)
559
+ - [Strong vs. Eventual Consistency - AlgoMaster](https://blog.algomaster.io/p/strong-vs-eventual-consistency)
560
+ - [Difference Between Two-Phase Commit and Saga Pattern - Baeldung](https://www.baeldung.com/cs/two-phase-commit-vs-saga-pattern)
561
+ - [Saga Design Pattern - Azure Architecture Center](https://learn.microsoft.com/en-us/azure/architecture/patterns/saga)
562
+ - [CAP, PACELC, ACID, BASE - ByteByteGo](https://blog.bytebytego.com/p/cap-pacelc-acid-base-essential-concepts)
563
+ - [ACID vs BASE Databases - AWS](https://aws.amazon.com/compare/the-difference-between-acid-and-base-database/)
564
+ - [Transactional Outbox Pattern - AWS Prescriptive Guidance](https://docs.aws.amazon.com/prescriptive-guidance/latest/cloud-design-patterns/transactional-outbox.html)
565
+ - [Reliable Microservices Data Exchange With the Outbox Pattern - Debezium](https://debezium.io/blog/2019/02/19/reliable-microservices-data-exchange-with-the-outbox-pattern/)
566
+ - [Living Without Atomic Clocks: Where CockroachDB and Spanner Diverge](https://www.cockroachlabs.com/blog/living-without-atomic-clocks/)
567
+ - [The One Crucial Difference Between Spanner and CockroachDB - AuthZed](https://authzed.com/blog/prevent-newenemy-cockroachdb)
568
+ - [What Write Skew Looks Like - CockroachDB](https://www.cockroachlabs.com/blog/what-write-skew-looks-like/)
569
+ - [A Beginner's Guide to the Write Skew Anomaly - Vlad Mihalcea](https://vladmihalcea.com/write-skew-2pl-mvcc/)
570
+ - [GitLab Postgres DB Split Brain Incident Post-Mortem](https://gitlab.com/gitlab-com/gl-infra/production-engineering/-/issues/212)
571
+ - [Split-Brain 101 - Percona](https://www.percona.com/blog/split-brain-101-what-you-should-know/)
572
+ - [Why Strong Consistency? - Marc Brooker](https://brooker.co.za/blog/2025/11/18/consistency.html)
573
+ - [Azure Cosmos DB Consistency Levels - Microsoft](https://learn.microsoft.com/en-us/azure/cosmos-db/consistency-levels)
574
+ - [Disasters I've Seen in a Microservices World](https://world.hey.com/joaoqalves/disasters-i-ve-seen-in-a-microservices-world-a9137a51)