A customer name is an attribute, not a durable relationship
Harbor has two customers named Taylor and one customer whose trading name changes. A name-based join can merge different parties or split one party across periods. Give each customer a stable customer identifier; give jobs, invoices and payments their own identifiers. A job belongs to a customer, an invoice may cover multiple job lines and a payment may be allocated across invoices. State those relationships before choosing tables.
Separate an invoice header from invoice lines to avoid repeating mutable customer or invoice-level facts in every line. A foreign key can prevent a line referring to a nonexistent invoice, but it cannot prove that the invoice represents authorized work. Technical integrity and business authorization are complementary controls. Preserve corrections with a reason and history rather than changing identifiers to conceal discrepancies.
Document currency, units and timestamp semantics. A total of 10,000 has no stable meaning without those definitions. A system can enforce a numeric type while accepting the wrong currency or tax basis. Validate permitted values and reconcile substantive meaning as well as storage structure.
A timeout is uncertainty about outcome
Suppose accounting receives invoice event E001, commits invoice I001 for 12,000 and then the network loses the acknowledgement. The sender cannot infer that the commit failed. Retrying without a stable event identity can create a second invoice. Use an idempotency key representing the intended business operation, and store the recognized key and business effect together under an appropriate transaction boundary.
On an exact replay of E001 with the same content, return the recorded result without reapplying the effect. Reusing E001 with a different amount is a conflict requiring rejection or investigation, not permission to overwrite the invoice. Compare a stable payload representation or business fields, and define how authorized corrections receive their own linked identities. The teaching lab stores a tuple as the simplified fingerprint; production designs need a carefully specified canonical representation and concurrency controls.
A local database transaction can make a local effect and processed-event record atomic. It does not make an external email or a remote accounting system part of the same atomic commit. An outbox can record an intended outgoing event in the local transaction, followed by retried delivery; the receiver must still cope with duplicates. Exactly-once language needs a stated boundary and assumptions.
Reconciliation complements prevention
The synthetic stream contains E001 for I001 worth 12,000, an exact replay of E001, E002 for I002 worth 8,000 and E003 as a −1,000 correction linked to I001. There are four received messages, three distinct accepted operations and a net invoice balance of 19,000. Counting messages as invoices or summing every received amount produces a misleading report.
Reconcile accepted identities, rejected conflicts, source counts, currency and amounts. A balanced grand total can hide an omitted 1,000 item and a duplicated different 1,000 item. Compare entity identities and control categories, not only one number. Age pending and failed events with an accountable owner. A dead-letter queue is evidence awaiting resolution, not successful integration.
Late cancellation and correction events also require a policy. Distinguish the current operational projection from an as-of report, and retain occurrence and receipt times. Consider concurrency, recovery after a crash between steps and safe replay of a known fixture. The isolated lab demonstrates duplicate handling for its stated serial model; it does not prove distributed correctness or authorize changes to production records.
Worked example: Four messages do not mean four invoices
12,000 + replayed 12,000 + 8,000 − 1,000 would incorrectly give 31,000. Apply each distinct accepted operation once: 12,000 + 8,000 − 1,000 = 19,000.
Worked example: A reused key can reveal a conflict
If E001 reappears as 13,000 instead of 12,000, flag conflicting content and preserve the original effect. An authorized 1,000 change needs a separately identified correction and approval evidence.