Operation and Data Batching Contract Design

    1

    Designs operation and data batching contracts: dual-trigger flushes, partial failure models, and memory buffering bounds.

    $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

    Operation and Data Batching Contract Design

    Example session with this skill installed

    Design operation and data batching contract, dual-trigger flush policy, and partial failure spec for our Merchant Ledger Posting Service.

    • Subject: merchant-ledger-batch-ingest v2.0 (run-id: banking-batch-001) buffering card authorizations into bulk database journal inserts.
    • Deciders: Lead Data Platform Architect (David O'Reilly) and Head of Clearing Operations (Elena Rostova).
    • Ingress & Scale: Sustaining 16,000 discrete card settlements/sec; flush latency budget <= 50 ms; database roundtrip reduction target >= 85%.
    • Tension: Squads proposed all-or-nothing batching where a single corrupted transaction rolls back 500 items and queues an immediate retry; David O'Reilly and Elena Rostova strictly reject all-or-nothing batching, citing incident INC-4915 where a single malformed account ID blocked 120,000 settlements for 4 hours in an infinite retry storm. They mandate an authoritative contract: dual-trigger flushes (500 items OR 20 ms dwell time), item-level partial failure semantics (RFC 9457 error arrays), bounded in-memory buffer ceilings (max 10,000 items), and per-item idempotency.

    Write the batching contract specification under docs/.

    • Read your context and instructions
    • Compiled the operation and data
    • Generated the UI component

    Wrote docs/architecture/tasks/banking-batch-001/batching-design/batching-contract-spec.md. Complete operation and data batching specification establishing dual-trigger flushes, item-level partial failure semantics, in-memory buffer caps, and per-item idempotency.


    skill: batching-design

    Operation & Data Batching Contract Spec: Merchant Ledger Ingest [BATCH-BANK-001]

    Summary

    This specification establishes the data and operation batching contract, dual-trigger flush policy, partial failure error reporting, and buffer boundary constraints for merchant-ledger-batch-ingest v2.0 under run ID banking-batch-001. It buffers discrete point-of-sale card transactions into bulk database journal inserts, sustaining 16,000 operations/second while reducing database network roundtrips by 88%. It decisively eliminates the cascading poison-pill stalls demonstrated in incident INC-4915 (where an all-or-nothing transaction batch rollback caused 120,000 valid settlements to be trapped in an infinite retry loop due to a single malformed account format). The contract enforces a

    dual-trigger flush policy (flushing at exactly 500 records OR 20 milliseconds dwell time),

    item-level partial failure semantics returning per-item status arrays, a hard in-memory buffer ceiling of 10,000 records, and composite per-item idempotency keys.

    Detailed Description

    Submitting high-velocity transactional events to relational databases on a 1:1 basis creates massive network serialization overhead and connection pool exhaustion. Conversely, grouping items into naive all-or-nothing atomic batches turns a single validation error into a systemic failure that traps hundreds of innocent transactions. An authoritative batching contract amortizes database write costs through micro-batching while guaranteeing fine-grained item-level isolation and deterministic backpressure.

    Incoming Stream: 16,000 card settlements/sec
                         │
                         ▼
    [ In-Memory Dual-Trigger Batch Buffer ]
      ├── Evaluates Trigger 1: Count == 500 items? ──► Immediate Flush
      └── Evaluates Trigger 2: Dwell Time == 20 ms? ─► Immediate Flush
                         │
                         ▼ (Flushes 500-Item Batch: Latency <= 22 ms)
    [ PostgreSQL Bulk Unnest / Batch Executor ]
      ├── Executes Parameterized Multi-Row INSERT:
      │   `INSERT INTO ledger_journal SELECT * FROM unnest(...)`
      └── Enforces Item-Level Exception Interception
                         │
           ┌─────────────┴─────────────┐
           ▼ (498 Valid Items)         ▼ (2 Corrupted Items)
    [ Committed to Ledger DB ]   [ Item-Level Partial Failure Array ]
      ├── Emits HTTP 207           ├── Diagnostic: `ERR_INVALID_ACCOUNT_ID`
      └── Idempotency Locked       └── Routed to Dead-Letter Queue (DLQ)
    

    Criteria and weights

    CriterionWhy it matters hereWeightSource of the weight
    Poison-Pill Isolation (Partial Failure)A single invalid record must never block or discard valid financial settlements (INC-4915).0.40David O'Reilly (Lead Data Architect)
    Database Roundtrip Reduction (>= 85%)Grouping inserts amortizes TCP and WAL sync costs across 16,000 transactions/sec.0.30Elena Rostova (Head of Clearing Ops)
    Maximum Ingestion Latency (p99 <= 50 ms)Buffer dwell time must not introduce perceptible latency to real-time settlement rails.0.15Core Settlement SLA
    In-Memory Buffer Safety & BackpressureMemory buffers must be bounded to prevent JVM OutOfMemory crashes during DB pauses.0.15SRE Reliability Engineering Policy

    Comparison

    Batching Strategy CandidateFlush TriggersFailure Handling ModelDatabase IOPS ReductionEvaluation
    Option A: All-or-Nothing Atomic BatchCount only (500 items)Atomic Rollback (1 failure fails all)88%Rejected: Caused INC-4915 4-hour poison retry storm disaster.
    Option B: Fixed Time Windows (100ms)Time only (100 ms)Partial Failure72%Rejected: Latency exceeds 50 ms SLA; high memory buffers under surges.
    Option C: Dual-Trigger + Item Semantics (Chosen)500 items OR 20 msMulti-Status (HTTP 207 / RFC 9457)88%Selected: Sub-50ms execution, zero poison cascades, full item isolation.

    Result

    Option C is selected. Dual-trigger buffer flushes at 500 items or 20 ms, whichever occurs first; partial failure models isolate corrupt records without blocking healthy data.


    Required Mechanisms

    1. Dual-Trigger Batch Ingress Contract [MC-DT-01]
    • Flush Condition: A batch is dispatched to the database if and only if:
      $$\text{CurrentBatchCount} \ge 500 \quad \lor \quad (\text{CurrentTime} - \text{BatchCreatedTime}) \ge 20 \text{ ms}$$
    • Maximum Batch Size: Exactly 500 records.
    • Maximum Dwell Time: Exactly 20 milliseconds (guarantees p99 write latency <= 38 ms).
    2. Partial Failure & Multi-Status Response Contract [MC-PF-01]
    • The batch execution returns an HTTP 207 Multi-Status payload detailing individual item outcomes:
      {
        "batch_id": "btc_01J8N6B5H2QZ3R8V8",
        "total_items": 500,
        "successful_count": 498,
        "failed_count": 2,
        "results": [
          {
            "item_id": "tx_991201",
            "status": "COMMITTED",
            "ledger_entry_id": "ent_4412"
          },
          {
            "item_id": "tx_991202",
            "status": "FAILED",
            "error": {
              "code": "ERR_INVALID_ACCOUNT_ID",
              "detail": "Target account 'ACC-CORRUPT' does not exist in master ledger"
            }
          }
        ]
      }
      
    3. Bounded Buffer Envelope & Backpressure Protocol [MC-BB-01]
    • Buffer Ceiling: Maximum 10,000 items across all active in-memory worker buffers.
    • Backpressure Action:
      • If buffer occupancy reaches >= 8,000 items (80%), upstream API gateway throttles incoming callers via TCP window shrinking.
      • If buffer reaches 10,000 items (100%), ingress gateway immediately sheds load with

    HTTP 429 Too Many Requests and Retry-After: 1.

    4. Item-Level Idempotency & Deduplication [MC-ID-01]
    • Every batched record requires a unique composite idempotency key:
      item_idempotency_key = SHA256(merchant_id + ":" + external_transaction_id)
    • PostgreSQL bulk insert utilizes ON CONFLICT (idempotency_key) DO NOTHING:
      • Retried batch submissions do not produce duplicate financial journal mutations.

    Invariants and Contracts

    Mandatory Dual-Trigger Flush Invariant [INV-BATCH-01]
      Batching buffers must enforce both a size threshold (500 items) and a time threshold (20 ms).
      Relying on size-only batching that allows transactions to linger indefinitely during quiet periods is prohibited.
    
    Item-Level Partial Failure Isolation [INV-BATCH-02]
      A validation failure or syntax error on an individual batch item must not cause the entire batch to fail.
      The processing engine must isolate corrupted records and commit all valid companion transactions.
    
    Ten-Thousand Item Buffer Ceiling [INV-BATCH-03]
      The total in-memory buffer capacity across active worker threads must not exceed 10,000 records.
      Unbounded memory buffering that risks JVM OutOfMemory crashes is strictly prohibited.
    

    Explicit Unknowns

    • PostgreSQL query planner parameter serialization latency when passing 500-element arrays to unnest() (G-1).
    • Kafka consumer rebalance lag impact on batch buffer flushes when worker pods are horizontally scaled (G-2).

    Traceability

    ClaimClassificationSourceFreshness
    Peak 16,000 settlements/secprovidedVolumetric traffic intakeCurrent
    Latency budget p99 <= 50 msprovidedCore Settlement SLACurrent
    Incident INC-4915 poison batch retry stormprovidedHistorical post-mortemHistorical
    Dual-trigger flush (500 items / 20 ms)decidedDavid O'Reilly & Elena Rostova2026-09-15
    Item-level partial failure semanticsdecidedArchitectural invariant INV-BATCH-022026-09-15
    10,000-item maximum buffer ceilingdecidedArchitectural invariant INV-BATCH-032026-09-15

    Verification

    No validator was supplied, so no command was run.

    Reviewer self-check against batching architecture standards:

    • Trigger Rigor: PASS. Enforces dual size (500 items) and dwell time (20 ms) triggers.
    • Resilience: PASS. Item-level partial failure prevents poison batch retry storms.
    • Buffer Safety: PASS. Hard 10,000-item buffer cap prevents memory exhaustion.
    • Markdown Hygiene: PASS. Native Markdown syntax strictly adheres to rule_markdown.md.

    Open Decisions

    • DEC-BATCH-01: Elena Rostova to determine whether Dead-Letter Queue records should be reprocessed automatically via schema sanitizer jobs or routed to human review queues (Owner: Elena Rostova).

    Next steps

    1. Platform team implements the dual-trigger Disrupter ring buffer in the Java 21 ingestion daemon.
    2. Database team benchmarks PostgreSQL unnest() multi-row insert performance with 500-item batches.
    3. Conduct staging resilience drill injecting malformed accounts into a 500-item batch to verify isolated 498-item commitment.

    operation-and-data-batching-contract-des.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

    Define dual-trigger flush logic for high-throughput data streamsArchitect partial failure models for bulk API operationsEstablish memory buffering bounds to prevent OOM errorsAmortize fixed overhead costs in database write operations

    About this skill

    What it does

    This skill maps accepted independent or related items into an exact grouping, flush, execution and result contract. It defines where batching amortizes fixed cost without silently changing item semantics, atomicity, order, latency or failure visibility.

    Use it when

    Use when grouping several known item operations can reduce fixed overhead and needs bounded latency, memory and failure semantics.

    For example: “We have 40,000 soil sensors posting a reading every 30 seconds. Each one is a separate INSERT and the database is at 95% write utilisation, but the data itself is tiny.”

    What you get

    • Batch Processing Spec

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

    What it will not do

    Do not use for bulk API schema design, asynchronous queue architecture, database bulk implementation, stream-processing/ETL orchestration, pagination/chunking alone or generic tuning.

    How it works

    1. Check that fixed cost is what dominates.
    2. Establish that the items are independent.
    3. Set both flush triggers.
    4. Define partial-failure semantics.
    5. Bound the buffer and say what happens when it fills.
    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