Transactional Inbox Consumer Design

    1

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

    $5

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 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

    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.

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

    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

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.

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

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 1 month ago

    Permissions

    Read Files
    Write Files

    Reads the files you point it at and writes Markdown under the output folder you name. No network access, no environment variables, and no bundled scripts.

    Listed1 month ago

    What's inside

    Frequently Asked Questions

    No. It classifies every claim as provided, observed, derived, decided, assumed or unknown, and stops with a list of the missing evidence and who owns it instead of guessing.

    No. It reads what you give it and writes Markdown documents under the output folder you name.

    Any agent that supports SKILL.md skills, including Claude Code, Codex CLI, Cursor and Gemini CLI. It has no scripts and makes no network calls.

    Unzip it into your agent's skills folder, for example: unzip inbox-design.zip -d ~/.claude/skills/

    New in APIs & Backend