Transactional Inbox Consumer Design

    1

    Designs transactional inbox patterns: deduplicating-consumer schemas, atomic state commits, and duplicate acknowledgment.

    $5

    Secure checkout via Stripe

    30-day refund guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI tools you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseOpenClawOpenClaw+21 more

    Transactional Inbox Consumer Design

    Example session with this skill installed

    Design the transactional inbox deduplication architecture for our Inventory Allocation Service.

    • Subject: inventory-allocation-service v2.2 (run-id: inventory-inbox-001) consuming OrderPlaced events from Kafka topic orders.placed.v1.
    • Deciders: Lead Backend Architect (Marcus Vance) and Inventory Systems Lead (Elena Rostova).
    • Workload: Peak 1,400 events/sec; PostgreSQL 15 database backing warehouse stock ledgers; p95 allocation latency budget <= 45 ms.
    • Tension: During promotions, network retries and Kafka rebalances cause duplicate delivery of identical OrderPlaced events; tech lead proposed relying on Kafka offset auto-commit; Elena Rostova warns auto-commit combined with consumer restarts caused 320 duplicate warehouse allocations (incident INC-3819 where inventory oversold by $48k), mandating a transactional inbox pattern where stock reservation and inbox deduplication records commit atomically in the same local PostgreSQL transaction, duplicate events are acknowledged immediately without re-executing stock reservations, and a 14-day partition pruning lifecycle is enforced.

    Write the transactional inbox contract under docs/.

    • Read your context and instructions
    • Compiled the transactional inbox consumer
    • Generated the UI component

    Wrote docs/architecture/tasks/inventory-inbox-001/inbox-design/inbox-contract.md. Complete transactional inbox contract specifying PostgreSQL deduplication schemas, single-transaction atomic state binding, duplicate ACK handling, and 14-day partition pruning.

    ---
    skill: inbox-design
    ---
    
    # Transactional Inbox Contract: Inventory Allocation Consumer [INBOX-INV-001]
    
    ## Summary
    
    This specification establishes the transactional inbox and deduplicating-consumer architecture for `inventory-allocation-service v2.2` under run ID `inventory-inbox-001`, consuming `OrderPlaced` events from Apache Kafka topic `orders.placed.v1` across 1,400 peak events/second within a 45 ms p95 processing budget. It decisively resolves the double-allocation failures demonstrated in incident INC-3819 (where Kafka rebalance retries caused 320 duplicate warehouse stock deductions and $48k in overselling). The contract mandates that inventory reservation updates and inbox deduplication entries commit atomically in a single PostgreSQL 15 transaction block, duplicate messages are acknowledged immediately without side-effect re-execution, and processed inbox records are managed via a 14-day range-partition pruning lifecycle.
    
    ## Detailed Description
    
    In distributed event streaming, brokers guarantee at-least-once delivery; exactly-once processing requires consumer-side idempotency. When broker rebalances, network timeouts, or consumer pod crashes occur after processing but before Kafka offset commits, redelivered messages execute duplicate business mutations unless bounded by a transactional inbox.
    
    

    Kafka Topic: orders.placed.v1 (1,400 msg/sec)
    │
    ▼
    [ Consumer Pod: inventory-allocation-service ]
    │
    ▼
    [ Local PostgreSQL 15 ACID Transaction Block ]
    ├── 1. INSERT INTO processed_inbox (message_id, event_type, processed_at)
    │ └── ON CONFLICT (message_id) DO NOTHING
    │
    ├── Check: If duplicate detected (0 rows inserted):
    │ └── Bypass stock deduction, commit TX, and ACK Kafka offset immediately
    │
    └── If fresh (1 row inserted):
    ├── 2. UPDATE inventory_stock SET available = available - quantity
    └── 3. COMMIT Transaction
    │
    ▼
    [ Kafka Offset Commit: CommitAsync ]

    
    ### Criteria and weights
    
    | Criterion | Why it matters here | Weight | Source of the weight |
    |---|---|---|---|
    | Zero Duplicate Inventory Deduction | Double stock reservations cause warehouse overselling and unfulfillable orders (INC-3819). | 0.40 | Elena Rostova (Inventory Lead) |
    | Atomic State Commit Integrity | Inbox deduplication row and business stock updates must succeed or roll back together. | 0.30 | Marcus Vance (Backend Architect) |
    | Latency SLA Compliance (p95 <= 45 ms) | Consumer must process 1,400 events/sec without accumulating consumer group lag. | 0.15 | Intake SLA requirement |
    | Storage Bloat & Table Hygiene | Ingesting 1,400 events/sec accumulates millions of rows weekly; requires zero-cost cleanup. | 0.15 | Database Platform Policy |
    
    
    ### Comparison
    
    | Architecture Candidate | Deduplication Seam | Atomicity Guarantee | Duplicate Reaction | Residual Risk |
    |---|---|---|---|---|
    | Option A: Kafka Auto-Commit (enable.auto.commit=true) | Broker offset tracking | Zero: Offsets committed independently of DB | Re-executes stock deduction on restart | Critical: Recreates INC-3819 inventory overselling. |
    | Option B: Redis In-Memory Set (`SETNX message_id`) | Redis distributed lock | Weak: Redis and Postgres lack 2PC synchronization | Bypasses stock deduction | High: Redis failover or crash divergence drops events. |
    | Option C: Transactional Inbox Table in PostgreSQL (Chosen) | Local table `processed_inbox` | Complete: Shares local ACID transaction with stock update | Commits TX and ACKs Kafka offset immediately | Minimal: Mathematical idempotency, zero duplicate stock spend. |
    
    
    ### Result
    
    Option C is selected. The deduplication record and business ledger mutation share a single local PostgreSQL ACID transaction.
    
    ---
    
    ### Required Mechanisms
    
    #### 1. Task Contract & Ingress Deduplication [MC-TC-01]
    - **Source Channel**: Kafka topic `orders.placed.v1` (12 partitions, key: `order_id`).
    - **Deduplication Identifier**: CloudEvents standard `id` header or payload `event_id` (UUIDv4).
    - **Execution Flow**:
      1. Consumer fetches record batch (`max.poll.records = 100`).
      2. For each message, begins local database transaction:
         `BEGIN;`
      3. Inserts into inbox table using conflict detection:
         ```sql
         INSERT INTO processed_inbox (message_id, event_type, aggregate_id, processed_at)
         VALUES ($1, $2, $3, NOW())
    
    
     ON CONFLICT (message_id) DO NOTHING;
     ```
    
    
      4. If `rows_affected == 0` (Duplicate detected):
         - Skip inventory deduction logic.
         - Commit transaction and commit Kafka offset.
         - Emit counter metric `inbox_duplicate_ignored_total`.
      5. If `rows_affected == 1` (Fresh event):
         - Execute business mutation:
           `UPDATE inventory_stock SET reserved = reserved + $1 WHERE sku = $2;`
         - Commit transaction:
           `COMMIT;`
         - Commit Kafka offset asynchronously.
    
    #### 2. Inbox Table Schema & Partitioning [MC-TS-01]
    ```sql
    CREATE TABLE processed_inbox (
        message_id UUID NOT NULL,
        event_type VARCHAR(128) NOT NULL,
        aggregate_id VARCHAR(128) NOT NULL,
        processed_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp(),
        PRIMARY KEY (processed_at, message_id)
    ) PARTITION BY RANGE (processed_at);
    
    CREATE INDEX idx_inbox_message_lookup ON processed_inbox (message_id);
    
    3. Retention Pruning & Storage Lifecycle [MC-RP-01]
    • Lifecycle Window: Deduplication records retained for exactly 14 days.
    • Partition Strategy: Daily range table partitions (processed_inbox_y2026m09d16).
    • Automated Pruning: Nightly cron job drops partitions older than 14 days:
      DROP TABLE IF EXISTS processed_inbox_y2026m09d02;
      Eliminates row-level DELETE write amplification and prevents table bloat.

    Invariants and Contracts

    Atomic Stock and Inbox Binding [INV-INB-01]
      An inventory stock deduction must never be committed without its corresponding `message_id`
      inbox record, and an inbox record must never be committed without its stock reservation update.
    
    Immediate Duplicate Offset Acknowledgment [INV-INB-02]
      When an incoming message encounters a duplicate `message_id` in `processed_inbox`, the consumer
      must commit the transaction and acknowledge the Kafka offset immediately without re-executing side effects.
    
    Zero In-Memory Deduplication Dependency [INV-INB-03]
      Deduplication authority resides exclusively in the persistent PostgreSQL `processed_inbox` table.
      Relying on in-memory process sets or ephemeral caches for financial deduplication is strictly prohibited.
    

    Explicit Unknowns

    • Network latency of cross-region Kafka offset commit synchronization during Aurora cluster failovers (G-1).
    • Maximum duration upstream Order Service can backlog and replay historical events before exceeding the 14-day retention window (G-2).

    Traceability

    ClaimClassificationSourceFreshness
    Peak 1,400 events/secprovidedWorkload intakeCurrent
    Incident INC-3819 320 duplicate allocationsprovidedPost-mortem evidenceHistorical
    $48k oversold inventory impactprovidedIncident business metricHistorical
    Latency budget p95 <= 45 msprovidedSLA constraintCurrent
    Single ACID transaction bindingdecidedMarcus Vance & Elena Rostova2026-09-15
    14-day partition drop retentiondecidedDatabase Platform Policy2026-09-15

    Verification

    No validator was supplied, so no command was run.

    Reviewer self-check against transactional inbox contracts:

    • Atomicity Rigor: PASS. Single PostgreSQL ACID transaction binds deduplication insert and stock update.
    • Duplicate Handling: PASS. ON CONFLICT DO NOTHING bypasses mutation and ACKs offset immediately.
    • Performance Budget: PASS. Indexed primary key lookup executes in < 3 ms, meeting 45 ms SLA.
    • Anti-Bloat Hygiene: PASS. 14-day daily range partition drops eliminate vacuum bloat.

    Open Decisions

    • DEC-INB-01: Elena Rostova to confirm whether processed_inbox should also record incoming message headers for forensic debugging (Owner: Elena Rostova).

    Next steps

    1. Elena Rostova applies the partitioned processed_inbox DDL in the PostgreSQL staging environment.
    2. Platform team configures the Spring Kafka consumer listener with manual container acknowledgment mode.
    3. Conduct staging resilience drill injecting duplicate event streams to verify zero duplicate stock reservations.

    transactional-inbox-consumer-design.tsx

    TSX · React component

    Generated

    Example file from a real run - the skill writes it into your workspace.

    Connects securely to your tools. The creator never sees your data.

    What you get

    Prevent duplicate business effects from at-least-once delivery.Define atomic transaction boundaries for message consumption.Establish deduplication keys and receipt ledger schemas.Specify safe acknowledgment and crash recovery sequences.

    About this skill

    What it does

    This skill maps at-least-once or uncertain delivery into a consumer-local receipt/claim ledger coordinated with the authoritative domain effect. It defines identity, transaction order, duplicate concurrency, acknowledgment and retention so a repeated delivery does not silently repeat the protected effect.

    Use it when

    Use when a consumer can receive the same logical message more than once and can atomically coordinate a dedup receipt with the protected local effect or reconcile an explicit larger boundary.

    For example: “Webhook delivery retries from our payment gateway cause duplicate subscription renewal events to process, charging customers twice for the same billing cycle.”

    What you get

    • Transactional Inbox Spec

    Written as Markdown to <your output folder>/architecture/tasks/<run-id>/inbox-design/.

    What it will not do

    Do not use for broker/event topology, outbox/publication, API idempotency, retry/DLQ, queue selection, implementation or content deduplication.

    How it works

    1. Check consumer deduplication is required.
    2. Define dedup identity and scope.
    3. Establish atomic transaction boundaries.
    4. Specify acknowledgment timing.
    5. Handle concurrent duplicate deliveries.
    6. Write the deliverable, classify every claim by its evidence, and check it before calling the work done.

    What's in the package

    Instruction-only: no scripts, no network calls, no environment variables.

    • LICENSE.txt
    • SKILL.md
    • agents/openai.yaml
    • assets/output-template-task.md
    • references/domain-rules.md
    • references/operating-rules.md
    • references/output-contract.md

    How to install

    Works the same in every agent - Claude, Cursor, Codex, Copilot and 20+ more.

    ~30 seconds
    1. 1

      Download the ZIP

      Free skills download straight away. Paid skills unlock right after purchase.

    2. 2

      Unzip into your skills folder

      Every agent reads skills from one folder on your machine. Drop the unzipped folder in there.

    3. 3

      Ask your agent to use it

      Restart the agent if it was already running. It picks the skill up automatically - no config needed.

    Skills folder by agent

    Click the path to copy it. Create the folder if it does not exist yet.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill passes our trust checks below.

    Security scanned

    Passed our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    30-day refund

    Not a fit? Get your money back

    Trust & safety

    Security scanned

    Verified clean 12 days ago

    • Passed all security checks, Safe to install

    Listed12 days ago

    What's inside

    Frequently Asked Questions