Caching and messaging
Idempotent consumer marker
Store stable identity and business effect atomically. Source-reviewed integration fragment or manual procedure, NOT RUN.
Formal Syntax & Structure
java syntaxjava
PRIMARY KEY(tenant,event_id)Working Example
Example Snippetjava
-- PostgreSQL 17, fresh disposable schema. Fixed synthetic event delivery.CREATE TABLE IF NOT EXISTS lab_processed (tenant text, event_id text, quantity integer NOT NULL CHECK(quantity>0), PRIMARY KEY(tenant,event_id));CREATE TABLE IF NOT EXISTS lab_total (tenant text PRIMARY KEY, quantity bigint NOT NULL CHECK(quantity>=0));-- Execute the transaction twice. The second run should have no effect.BEGIN;WITH accepted AS ( INSERT INTO lab_processed(tenant,event_id,quantity) VALUES ('tenant-a','e1',2) ON CONFLICT (tenant,event_id) DO NOTHING RETURNING tenant,quantity)INSERT INTO lab_total(tenant,quantity) SELECT tenant,quantity FROM acceptedON CONFLICT (tenant) DO UPDATE SET quantity=lab_total.quantity+EXCLUDED.quantity;COMMIT;SELECT quantity FROM lab_total WHERE tenant='tenant-a';-- Expected 2. This fixed payload assumes same ID means same payload.-- General consumer must compare stored payload and reject conflicting duplicates.