π PART V (i) β Data Correctness Across UI + DB (Idempotency, Concurrency, Reconciliation)
SECTION 0 β CORRECTNESS IS USER TRUST
Many βbugsβ are correctness failures:
-
double submit
-
stale reads
-
phantom success
-
lost updates
Senior fullstack correctness means you design invariants and enforce them at boundaries.
SECTION 1 β EXACTLY-ONCE IS MOSTLY A LIE
Distributed systems are at-least-once.
So you need:
-
idempotency keys
-
dedupe tables
-
idempotent consumers
SECTION 2 β IDEMPOTENCY KEYS (WHERE USERS RETRY)
Use idempotency for:
-
checkout
-
uploads
-
βcreateβ operations from flaky networks
Rules:
-
scope keys by user/tenant
-
store request hash
-
return the original result for repeats
SECTION 3 β OPTIMISTIC CONCURRENCY (STOP LOST UPDATES)
Pattern:
-
rows have
versionorupdated_at -
client sends
If-Match/ version -
server rejects stale writes (409)
UI handles:
-
refresh and retry
-
conflict resolution where needed
SECTION 4 β AUDIT TRAILS (WHEN IT MUST BE PROVABLE)
If money, permissions, or critical data is involved:
-
append-only audit events
-
who/what/when
-
correlation IDs
SECTION 5 β USER-VISIBLE CORRECTNESS PATTERNS
-
disable submit buttons on action
-
show processing vs success explicitly
-
rehydrate state from server after reload
-
avoid optimistic UI for irreversible actions unless you have compensations
SECTION 6 β RECONCILIATION JOBS (THE SAFETY NET)
If external systems exist (payments, email providers, storage):
-
periodically reconcile internal vs external truth
-
auto-heal safe mismatches
-
alert on unsafe mismatches
SECTION 7 β EXERCISES
-
Pick one create flow and define idempotency behavior.
-
Add an optimistic concurrency contract to one update endpoint.
-
Propose a reconciliation job for an external dependency.