OBEY Designing Data-Intensive Applications by Martin Kleppmann
Purpose
This repository follows Designing Data-Intensive Applications in the sense of Martin Kleppmann:
design systems around explicit trade-offs in reliability, scalability, maintainability, consistency, and data flow.
All code generation, edits, and reviews must optimize for:
- explicit data and consistency semantics
- idempotent and replay-safe processing
- clear ownership of truth
- durable boundaries between storage, messaging, and computation
- schema evolution awareness
- realistic distributed systems assumptions
This file is a binding engineering policy: MUST is binding, SHOULD is a strong default, and MUST NOT is forbidden.
Primary Directive
Data systems are defined by trade-offs.
When uncertain, make those trade-offs explicit instead of hiding them behind vague abstractions.
Always ask:
- what is the source of truth?
- what are the consistency expectations?
- what happens on retries, duplicates, reordering, and partial failure?
- how does the data evolve over time?
- where is state durable, cached, derived, or ephemeral?
Do not design distributed behavior as if everything were local, ordered, and exactly once.
Reliability Rules
- Treat crashes, partial writes, duplicate work, timeouts, and stale reads as normal design inputs.
- Make write acknowledgment semantics explicit.
- Avoid hidden assumptions about durable success.
- Design for restart, replay, and partial failure recovery.
Anti-patterns (MUST NOT):
- side effects that cannot be retried safely
- no distinction between accepted, persisted, and applied
- assuming one successful response means all downstream effects succeeded
Scalability and Maintainability Rules
- Describe load with concrete parameters before changing architecture.
- Describe performance with latency, throughput, percentiles, and tail behavior where they matter.
- Do not claim scalability from node count alone; identify the bottleneck, access pattern, and contention point.
- Keep operability, simplicity, and evolvability as first-class design goals.
- Prefer designs that make production behavior inspectable and changeable over opaque clever mechanisms.
- Avoid accidental complexity from unnecessary distribution, premature heterogeneity, or hidden coupling.
Data Model and Storage Rules
- Choose storage shape based on access patterns, consistency needs, and update behavior.
- Do not force one storage pattern onto all workloads.
- Keep the ownership of each dataset explicit.
- Distinguish primary data from indexes, caches, projections, and search copies.
Source of Truth
For every important piece of data, identify:
- primary owner
- derived copies
- replication path
- update path
- consistency expectation
Anti-patterns (MUST NOT):
- many writable copies with no ownership
- cache quietly becoming the real source of truth
- denormalized copies with no repair strategy
Query Model and Data Shape Rules
- Choose relational, document, graph, key-value, or analytical models according to relationships, query needs, update locality, and evolution pressure.
- Do not use a document model when many-to-one or many-to-many relationships require awkward duplication or application-side joins.
- Do not force a relational shape when data is naturally self-contained and usually accessed together.
- Use declarative query languages where they make intent clearer and leave optimization to the engine.
- Use graph models when relationships are first-class and traversal is central.
- Treat Cypher, SPARQL, Datalog, SQL, MapReduce, and application code as different expression choices with different maintainability and optimization tradeoffs.
Storage Engine and Indexing Rules
- Match indexing strategy to write pattern, read pattern, range scans, update cost, and recovery needs.
- Use log-structured storage, SSTables, and LSM-tree style approaches when write throughput and sequential writes are the dominant fit.
- Use B-tree style indexes when ordered access, point lookups, and mature transactional behavior fit the workload.
- Treat secondary indexes as separate data structures with write amplification, partitioning, and consistency costs.
- Distinguish OLTP access from analytical workloads; do not force one layout to serve both well.
- Use column-oriented storage, compression, sort order, materialized views, or cubes only when analytical access patterns justify them.
- Keep in-memory assumptions explicit; memory residency is a performance strategy, not a durability model.
Consistency Rules
- Be explicit about read-after-write expectations.
- Be explicit about staleness tolerance.
- Be explicit about conflict handling.
- Use strong consistency only where the product truly requires it.
- Use eventual consistency intentionally, not accidentally.
Write Semantics
Document or encode:
- when a write is durable
- when it is visible
- whether readers may see stale data
- how conflicts are detected or resolved
Anti-patterns (MUST NOT):
- “eventual consistency” used as a slogan instead of a contract
- stale-read bugs blamed on infrastructure with no product decision behind them
- no conflict model for concurrent updates
Idempotency and Replay Rules
- Handlers of commands, jobs, and events must tolerate retries where delivery or acknowledgment is uncertain.
- Prefer deduplication keys or naturally idempotent state transitions.
- Design processing to survive replay after crashes.
- Never assume exactly-once delivery unless the system boundary truly provides it and the design proves it.
Anti-patterns (MUST NOT):
- duplicate billing/order/send on retry
- handlers with non-repeatable side effects and no guard
- event processors depending on “it probably won't happen twice”
Ordering Rules
- Do not assume global order in distributed systems.
- Require only the minimum ordering guarantees the business logic actually needs.
- When ordering matters, define its scope:
- per key
- per stream
- per partition
- per record or entity whose history is being updated
- Keep ordering-sensitive logic close to the key or stream that defines the order.
Anti-patterns (MUST NOT):
- implicit reliance on total ordering
- out-of-order events corrupting state because no versioning or sequence policy exists
- parallel consumers updating the same key with no ordering plan
Event, Log, and Stream Rules
- Distinguish commands, events, and materialized views clearly.
- Events describe facts that happened; commands request action.
- Logs and streams are durable histories, not merely transport pipes.
- Consumers must tolerate lag, duplicates, restart, and replay.
- Derived projections must be rebuildable where feasible.
Event Design
- use stable identifiers
- include enough metadata for correlation and replay
- version payloads carefully
- keep semantics explicit
Anti-patterns (MUST NOT):
- event payloads tied to one serializer or internal object layout
- projections that cannot be rebuilt
- assuming consumers keep up forever
Schema Evolution Rules
- Schemas will change; plan for it.
- Version contracts intentionally.
- Prefer backward- and forward-compatible changes where possible.
- Keep old readers and writers in mind during rollout.
- Distinguish internal refactors from contract changes.
Anti-patterns (MUST NOT):
- breaking payloads or DB semantics without migration strategy
- reusing fields with new meaning
- silently changing enum or status semantics across services
Encoding and Data Flow Rules
- Choose encoding formats by compatibility needs, schema guarantees, readability, size, and language independence.
- Do not rely on language-specific serialization for long-lived or cross-service data.
- Treat JSON, XML, binary encodings, Thrift, Protocol Buffers, and Avro as contract choices with different schema-evolution tradeoffs.
- Define reader and writer compatibility during rolling upgrades.
- Keep database writes, service calls, and asynchronous messages explicit about who reads old and new formats during migration.
- Avoid RPC designs that hide network failure, version skew, latency, or partial failure behind local-call syntax.
Partitioning and Locality Rules
- Keep data and work colocated by the key that most often drives consistency or aggregation.
- Partition by a workload-relevant key, not by convenience alone.
- Be explicit about hot-key risk and skew.
- Design cross-partition operations carefully.
Anti-patterns (MUST NOT):
- partitioning that makes every common query cross-node
- no plan for skew or hotspots
- requiring cross-partition transactions for ordinary operations
Replication Rules
- Choose leader-follower, multi-leader, or leaderless replication according to write topology, failure tolerance, latency, and conflict handling.
- Be explicit about synchronous and asynchronous replication tradeoffs.
- Define behavior during node outages, follower catch-up, failover, and reconfiguration.
- Preserve read-your-writes, monotonic reads, and consistent prefix reads only when the product or workflow requires them and the design provides them.
- Do not rely on quorum formulas without checking stale reads, sloppy quorums, hinted handoff, and concurrent writes.
- Make conflict detection and resolution explicit for concurrent writes.
Transaction Rules
- Use local transactions where they solve a real consistency problem cleanly.
- Avoid distributed transactions as a default coordination strategy.
- When cross-boundary coordination is required, define the commit, recovery, reconciliation, and failure semantics explicitly.
- Make atomicity scope explicit.
Isolation and Invariants
- Know whether read committed, snapshot isolation, serial execution, two-phase locking, or serializable snapshot isolation is required for the invariant.
- Protect against lost updates, write skew, and phantoms where application correctness depends on them.
- Do not accept weaker isolation for correctness-critical invariants without a deliberate design that preserves the invariant another way.
Anti-patterns (MUST NOT):
- multi-system two-phase coordination by default
- side effects emitted outside transactional boundaries with no repair path
- pretending asynchronous side effects are atomic because they “usually happen”
Derived Data Rules
- Treat indexes, search copies, caches, and read models as derived data unless they are explicitly authoritative.
- Derived data must be repairable, rebuildable, or re-syncable.
- Know how lag affects user-visible behavior.
- Keep derivation pipelines observable.
Anti-patterns (MUST NOT):
- no way to rebuild projections
- no lag visibility
- mixing primary writes directly into derived stores with no ownership model
Distributed Fault, Clock, and Consensus Rules
- Treat network delay, packet loss, partitions, duplicated messages, and arbitrary pauses as normal distributed-system risks.
- Do not infer remote failure or success from timeout alone.
- Use monotonic clocks for measuring elapsed time; do not use wall clocks for ordering unless clock assumptions are explicit and safe.
- Do not rely on synchronized clocks for correctness unless uncertainty bounds and failure behavior are part of the design.
- Treat majority decisions, leases, locks, and leadership as assumptions that need a fault model.
- Use linearizability only where a single up-to-date value is required and the availability/latency cost is acceptable.
- Use total order broadcast, atomic commit, or consensus only when the coordination problem truly requires it.
- Make membership and coordination-service dependencies explicit; they are part of the system design, not invisible plumbing.
Batch and Stream Processing Rules
- Design batch jobs so inputs, outputs, and intermediate state can be recomputed or recovered.
- Keep external side effects out of replayable jobs unless idempotency is explicit.
- Use MapReduce-style, dataflow, or high-level batch APIs according to join strategy, intermediate materialization, and operational needs.
- Distinguish event time, processing time, and ingestion time in stream processing.
- Define windowing, late data, joins, state storage, checkpoints, and fault tolerance for streams that affect correctness.
- Treat change data capture, event sourcing, and log-based synchronization as ways to derive and propagate data, not as magic consistency.
- Define at-most-once, at-least-once, or exactly-once processing guarantees for each source-to-sink path.
API and Service Boundary Rules
- Service boundaries must reflect data ownership and update semantics.
- Do not split one tightly consistent business concept across many services casually.
- Avoid chatty cross-service joins on hot paths.
- Contracts must encode identifiers, versions, and failure semantics clearly.
Review Rules
When reviewing code, actively look for:
- hidden assumptions about ordering
- hidden assumptions about exactly-once delivery
- lack of idempotency
- no source-of-truth ownership
- broken schema evolution practices
- no versioning or sequencing where concurrency matters
- side effects that cannot be repaired
- write paths that update several stores with unclear guarantees
- projections that cannot be rebuilt
- partitioning blind to locality or hotspots
Forbidden Patterns
Exactly-Once Wishful Thinking
- assuming a broker or queue magically prevents all duplicates
- writing non-idempotent handlers without safeguards
Hidden Consistency Contract
- readers and writers disagreeing on freshness requirements
- stale or conflicting behavior treated as incidental instead of product design
Uncoordinated Multi-Writes
- writing to several authorities in one operation with no atomicity or repair strategy
- side effects sent before durable state with no recovery path
Schema Drift by Accident
- changing payload meaning without versioning
- reusing fields for new concepts
- no rollout compatibility strategy
Code Generation Rules
When generating code, default to:
- explicit identifiers and ownership
- explicit idempotency where retries or duplicates can happen
- explicit versioning or conflict strategy where ordering matters
- explicit distinction between authoritative and derived data
- repairable or rebuildable downstream state
- compatibility-aware schema changes
- observability for lag, retries, and failures
Avoid by default:
- assuming strict global order
- exactly-once promises with no proof
- writing the same fact into several places as if they were one transaction
- treating streams and queues as fire-and-forget
Testing Rules
- Test duplicate delivery handling.
- Test out-of-order event or message handling where applicable.
- Test replay safety.
- Test conflict resolution or optimistic concurrency behavior.
- Test schema compatibility when contracts evolve.
- Test rebuild or repair of derived views where that capability exists.
Review Checklist
Before finalizing any change, verify:
- Is the source of truth explicit?
- Are consistency expectations explicit?
- Is the code safe under retry or duplicate delivery?
- Is ordering dependency explicit and scoped?
- Can derived data be rebuilt or repaired?
- Is schema evolution considered?
- Is atomicity scope honest?
- Did we avoid exactly-once wishful thinking?
- Are service boundaries aligned with data ownership?
- Are lag and failure observable?
If any answer is no, revise before shipping.
Final Instruction
When uncertain, prefer the design that:
- makes data ownership explicit
- makes consistency semantics explicit
- survives retries, duplicates, and replay
- supports evolution without silent breakage
- treats distributed systems trade-offs honestly
Do not hide distributed complexity behind local-looking code.
1---
2name: book-designing-data-intensive-applications-full
3description: >-
4 DDIA (Martin Kleppmann) — Full rules — comprehensive mandatory coding standards. Use when asked to apply DDIA principles or review code against DDIA standards.
5origin: "github.com/ciembor/agent-rules-books (MIT)"
6license: MIT
7version: "1.0.0"
8compatibility: "yana-ai >= 0.14.0"
9metadata:
10 source: https://skillmd.com/skills/yanacuti1121/book-designing-data-intensive-applications-full
11---
12
13# OBEY Designing Data-Intensive Applications by Martin Kleppmann
14
15## Purpose
16
17This repository follows **Designing Data-Intensive Applications** in the sense of Martin Kleppmann:
18design systems around explicit trade-offs in reliability, scalability, maintainability, consistency, and data flow.
19
20All code generation, edits, and reviews must optimize for:
21- explicit data and consistency semantics
22- idempotent and replay-safe processing
23- clear ownership of truth
24- durable boundaries between storage, messaging, and computation
25- schema evolution awareness
26- realistic distributed systems assumptions
27
28This file is a binding engineering policy: `MUST` is binding, `SHOULD` is a strong default, and `MUST NOT` is forbidden.
29
30---
31
32## Primary Directive
33
34Data systems are defined by trade-offs.
35When uncertain, make those trade-offs explicit instead of hiding them behind vague abstractions.
36
37Always ask:
381. what is the source of truth?
392. what are the consistency expectations?
403. what happens on retries, duplicates, reordering, and partial failure?
414. how does the data evolve over time?
425. where is state durable, cached, derived, or ephemeral?
43
44Do not design distributed behavior as if everything were local, ordered, and exactly once.
45
46---
47
48## Reliability Rules
49
501. Treat crashes, partial writes, duplicate work, timeouts, and stale reads as normal design inputs.
512. Make write acknowledgment semantics explicit.
523. Avoid hidden assumptions about durable success.
534. Design for restart, replay, and partial failure recovery.
54
55Anti-patterns (MUST NOT):
56- side effects that cannot be retried safely
57- no distinction between accepted, persisted, and applied
58- assuming one successful response means all downstream effects succeeded
59
60---
61
62## Scalability and Maintainability Rules
63
641. Describe load with concrete parameters before changing architecture.
652. Describe performance with latency, throughput, percentiles, and tail behavior where they matter.
663. Do not claim scalability from node count alone; identify the bottleneck, access pattern, and contention point.
674. Keep operability, simplicity, and evolvability as first-class design goals.
685. Prefer designs that make production behavior inspectable and changeable over opaque clever mechanisms.
696. Avoid accidental complexity from unnecessary distribution, premature heterogeneity, or hidden coupling.
70
71---
72
73## Data Model and Storage Rules
74
751. Choose storage shape based on access patterns, consistency needs, and update behavior.
762. Do not force one storage pattern onto all workloads.
773. Keep the ownership of each dataset explicit.
784. Distinguish primary data from indexes, caches, projections, and search copies.
79
80### Source of Truth
81For every important piece of data, identify:
82- primary owner
83- derived copies
84- replication path
85- update path
86- consistency expectation
87
88Anti-patterns (MUST NOT):
89- many writable copies with no ownership
90- cache quietly becoming the real source of truth
91- denormalized copies with no repair strategy
92
93---
94
95## Query Model and Data Shape Rules
96
971. Choose relational, document, graph, key-value, or analytical models according to relationships, query needs, update locality, and evolution pressure.
982. Do not use a document model when many-to-one or many-to-many relationships require awkward duplication or application-side joins.
993. Do not force a relational shape when data is naturally self-contained and usually accessed together.
1004. Use declarative query languages where they make intent clearer and leave optimization to the engine.
1015. Use graph models when relationships are first-class and traversal is central.
1026. Treat Cypher, SPARQL, Datalog, SQL, MapReduce, and application code as different expression choices with different maintainability and optimization tradeoffs.
103
104---
105
106## Storage Engine and Indexing Rules
107
1081. Match indexing strategy to write pattern, read pattern, range scans, update cost, and recovery needs.
1092. Use log-structured storage, SSTables, and LSM-tree style approaches when write throughput and sequential writes are the dominant fit.
1103. Use B-tree style indexes when ordered access, point lookups, and mature transactional behavior fit the workload.
1114. Treat secondary indexes as separate data structures with write amplification, partitioning, and consistency costs.
1125. Distinguish OLTP access from analytical workloads; do not force one layout to serve both well.
1136. Use column-oriented storage, compression, sort order, materialized views, or cubes only when analytical access patterns justify them.
1147. Keep in-memory assumptions explicit; memory residency is a performance strategy, not a durability model.
115
116---
117
118## Consistency Rules
119
1201. Be explicit about read-after-write expectations.
1212. Be explicit about staleness tolerance.
1223. Be explicit about conflict handling.
1234. Use strong consistency only where the product truly requires it.
1245. Use eventual consistency intentionally, not accidentally.
125
126### Write Semantics
127Document or encode:
128- when a write is durable
129- when it is visible
130- whether readers may see stale data
131- how conflicts are detected or resolved
132
133Anti-patterns (MUST NOT):
134- “eventual consistency” used as a slogan instead of a contract
135- stale-read bugs blamed on infrastructure with no product decision behind them
136- no conflict model for concurrent updates
137
138---
139
140## Idempotency and Replay Rules
141
1421. Handlers of commands, jobs, and events must tolerate retries where delivery or acknowledgment is uncertain.
1432. Prefer deduplication keys or naturally idempotent state transitions.
1443. Design processing to survive replay after crashes.
1454. Never assume exactly-once delivery unless the system boundary truly provides it and the design proves it.
146
147Anti-patterns (MUST NOT):
148- duplicate billing/order/send on retry
149- handlers with non-repeatable side effects and no guard
150- event processors depending on “it probably won't happen twice”
151
152---
153
154## Ordering Rules
155
1561. Do not assume global order in distributed systems.
1572. Require only the minimum ordering guarantees the business logic actually needs.
1583. When ordering matters, define its scope:
159 - per key
160 - per stream
161 - per partition
162 - per record or entity whose history is being updated
1634. Keep ordering-sensitive logic close to the key or stream that defines the order.
164
165Anti-patterns (MUST NOT):
166- implicit reliance on total ordering
167- out-of-order events corrupting state because no versioning or sequence policy exists
168- parallel consumers updating the same key with no ordering plan
169
170---
171
172## Event, Log, and Stream Rules
173
1741. Distinguish commands, events, and materialized views clearly.
1752. Events describe facts that happened; commands request action.
1763. Logs and streams are durable histories, not merely transport pipes.
1774. Consumers must tolerate lag, duplicates, restart, and replay.
1785. Derived projections must be rebuildable where feasible.
179
180### Event Design
181- use stable identifiers
182- include enough metadata for correlation and replay
183- version payloads carefully
184- keep semantics explicit
185
186Anti-patterns (MUST NOT):
187- event payloads tied to one serializer or internal object layout
188- projections that cannot be rebuilt
189- assuming consumers keep up forever
190
191---
192
193## Schema Evolution Rules
194
1951. Schemas will change; plan for it.
1962. Version contracts intentionally.
1973. Prefer backward- and forward-compatible changes where possible.
1984. Keep old readers and writers in mind during rollout.
1995. Distinguish internal refactors from contract changes.
200
201Anti-patterns (MUST NOT):
202- breaking payloads or DB semantics without migration strategy
203- reusing fields with new meaning
204- silently changing enum or status semantics across services
205
206---
207
208## Encoding and Data Flow Rules
209
2101. Choose encoding formats by compatibility needs, schema guarantees, readability, size, and language independence.
2112. Do not rely on language-specific serialization for long-lived or cross-service data.
2123. Treat JSON, XML, binary encodings, Thrift, Protocol Buffers, and Avro as contract choices with different schema-evolution tradeoffs.
2134. Define reader and writer compatibility during rolling upgrades.
2145. Keep database writes, service calls, and asynchronous messages explicit about who reads old and new formats during migration.
2156. Avoid RPC designs that hide network failure, version skew, latency, or partial failure behind local-call syntax.
216
217---
218
219## Partitioning and Locality Rules
220
2211. Keep data and work colocated by the key that most often drives consistency or aggregation.
2222. Partition by a workload-relevant key, not by convenience alone.
2233. Be explicit about hot-key risk and skew.
2244. Design cross-partition operations carefully.
225
226Anti-patterns (MUST NOT):
227- partitioning that makes every common query cross-node
228- no plan for skew or hotspots
229- requiring cross-partition transactions for ordinary operations
230
231---
232
233## Replication Rules
234
2351. Choose leader-follower, multi-leader, or leaderless replication according to write topology, failure tolerance, latency, and conflict handling.
2362. Be explicit about synchronous and asynchronous replication tradeoffs.
2373. Define behavior during node outages, follower catch-up, failover, and reconfiguration.
2384. Preserve read-your-writes, monotonic reads, and consistent prefix reads only when the product or workflow requires them and the design provides them.
2395. Do not rely on quorum formulas without checking stale reads, sloppy quorums, hinted handoff, and concurrent writes.
2406. Make conflict detection and resolution explicit for concurrent writes.
241
242---
243
244## Transaction Rules
245
2461. Use local transactions where they solve a real consistency problem cleanly.
2472. Avoid distributed transactions as a default coordination strategy.
2483. When cross-boundary coordination is required, define the commit, recovery, reconciliation, and failure semantics explicitly.
2494. Make atomicity scope explicit.
250
251### Isolation and Invariants
252- Know whether read committed, snapshot isolation, serial execution, two-phase locking, or serializable snapshot isolation is required for the invariant.
253- Protect against lost updates, write skew, and phantoms where application correctness depends on them.
254- Do not accept weaker isolation for correctness-critical invariants without a deliberate design that preserves the invariant another way.
255
256Anti-patterns (MUST NOT):
257- multi-system two-phase coordination by default
258- side effects emitted outside transactional boundaries with no repair path
259- pretending asynchronous side effects are atomic because they “usually happen”
260
261---
262
263## Derived Data Rules
264
2651. Treat indexes, search copies, caches, and read models as derived data unless they are explicitly authoritative.
2662. Derived data must be repairable, rebuildable, or re-syncable.
2673. Know how lag affects user-visible behavior.
2684. Keep derivation pipelines observable.
269
270Anti-patterns (MUST NOT):
271- no way to rebuild projections
272- no lag visibility
273- mixing primary writes directly into derived stores with no ownership model
274
275---
276
277## Distributed Fault, Clock, and Consensus Rules
278
2791. Treat network delay, packet loss, partitions, duplicated messages, and arbitrary pauses as normal distributed-system risks.
2802. Do not infer remote failure or success from timeout alone.
2813. Use monotonic clocks for measuring elapsed time; do not use wall clocks for ordering unless clock assumptions are explicit and safe.
2824. Do not rely on synchronized clocks for correctness unless uncertainty bounds and failure behavior are part of the design.
2835. Treat majority decisions, leases, locks, and leadership as assumptions that need a fault model.
2846. Use linearizability only where a single up-to-date value is required and the availability/latency cost is acceptable.
2857. Use total order broadcast, atomic commit, or consensus only when the coordination problem truly requires it.
2868. Make membership and coordination-service dependencies explicit; they are part of the system design, not invisible plumbing.
287
288---
289
290## Batch and Stream Processing Rules
291
2921. Design batch jobs so inputs, outputs, and intermediate state can be recomputed or recovered.
2932. Keep external side effects out of replayable jobs unless idempotency is explicit.
2943. Use MapReduce-style, dataflow, or high-level batch APIs according to join strategy, intermediate materialization, and operational needs.
2954. Distinguish event time, processing time, and ingestion time in stream processing.
2965. Define windowing, late data, joins, state storage, checkpoints, and fault tolerance for streams that affect correctness.
2976. Treat change data capture, event sourcing, and log-based synchronization as ways to derive and propagate data, not as magic consistency.
2987. Define at-most-once, at-least-once, or exactly-once processing guarantees for each source-to-sink path.
299
300---
301
302## API and Service Boundary Rules
303
3041. Service boundaries must reflect data ownership and update semantics.
3052. Do not split one tightly consistent business concept across many services casually.
3063. Avoid chatty cross-service joins on hot paths.
3074. Contracts must encode identifiers, versions, and failure semantics clearly.
308
309---
310
311## Review Rules
312
313When reviewing code, actively look for:
314- hidden assumptions about ordering
315- hidden assumptions about exactly-once delivery
316- lack of idempotency
317- no source-of-truth ownership
318- broken schema evolution practices
319- no versioning or sequencing where concurrency matters
320- side effects that cannot be repaired
321- write paths that update several stores with unclear guarantees
322- projections that cannot be rebuilt
323- partitioning blind to locality or hotspots
324
325---
326
327## Forbidden Patterns
328
329### Exactly-Once Wishful Thinking
330- assuming a broker or queue magically prevents all duplicates
331- writing non-idempotent handlers without safeguards
332
333### Hidden Consistency Contract
334- readers and writers disagreeing on freshness requirements
335- stale or conflicting behavior treated as incidental instead of product design
336
337### Uncoordinated Multi-Writes
338- writing to several authorities in one operation with no atomicity or repair strategy
339- side effects sent before durable state with no recovery path
340
341### Schema Drift by Accident
342- changing payload meaning without versioning
343- reusing fields for new concepts
344- no rollout compatibility strategy
345
346---
347
348## Code Generation Rules
349
350When generating code, default to:
3511. explicit identifiers and ownership
3522. explicit idempotency where retries or duplicates can happen
3533. explicit versioning or conflict strategy where ordering matters
3544. explicit distinction between authoritative and derived data
3555. repairable or rebuildable downstream state
3566. compatibility-aware schema changes
3577. observability for lag, retries, and failures
358
359Avoid by default:
360- assuming strict global order
361- exactly-once promises with no proof
362- writing the same fact into several places as if they were one transaction
363- treating streams and queues as fire-and-forget
364
365---
366
367## Testing Rules
368
3691. Test duplicate delivery handling.
3702. Test out-of-order event or message handling where applicable.
3713. Test replay safety.
3724. Test conflict resolution or optimistic concurrency behavior.
3735. Test schema compatibility when contracts evolve.
3746. Test rebuild or repair of derived views where that capability exists.
375
376---
377
378## Review Checklist
379
380Before finalizing any change, verify:
381- Is the source of truth explicit?
382- Are consistency expectations explicit?
383- Is the code safe under retry or duplicate delivery?
384- Is ordering dependency explicit and scoped?
385- Can derived data be rebuilt or repaired?
386- Is schema evolution considered?
387- Is atomicity scope honest?
388- Did we avoid exactly-once wishful thinking?
389- Are service boundaries aligned with data ownership?
390- Are lag and failure observable?
391
392If any answer is no, revise before shipping.
393
394---
395
396## Final Instruction
397
398When uncertain, prefer the design that:
3991. makes data ownership explicit
4002. makes consistency semantics explicit
4013. survives retries, duplicates, and replay
4024. supports evolution without silent breakage
4035. treats distributed systems trade-offs honestly
404
405Do not hide distributed complexity behind local-looking code.