Skip to content

    AI Architect Case Files

    Case: Insurance Claim Triage and Duplicate Events

    An insurer's event-driven claim triage created duplicate tasks and emails after a restart. Event keys, idempotent consumers and a dead-letter topic fixed it.

    By Published 8 min read

    • ai-architect
    • case-file
    • industry-financial-services
    • pattern-event-driven
    • failure-duplicate-processing
    • kind-composite
    Share

    Composite scenario, not a real company. Assembled from common industry patterns; every number is illustrative and its assumptions are listed at the end.

    This case belongs to Multi-agent and event-driven AI architecture.

    Context

    • A mid-sized property insurer takes claims through a portal and a call centre. Each becomes a "claim submitted" event on an event bus.
    • 12 workers read the events. A model reads each narrative and form fields and returns a route: fast track, standard adjuster or specialist.
    • A downstream service creates the adjuster task and sends the customer an acknowledgement.
    • A triage call takes about 3 seconds. After a storm the portal sees about 2 claims per second.
    • The model only recommends a route; coverage decisions stay with adjusters.

    Problem statement

    After a deployment restarted all 12 workers, adjusters found duplicate tasks, some customers got two emails, and a withdrawn claim still got an adjuster task.

    Symptom Design cause Size
    Duplicate tasks and emails Position committed every 100 claims, but tasks and emails created after every claim: a restart replayed up to 99 claims per partition Up to 12 x 99 = 1,188 duplicate runs and side effects
    Withdrawn claim still got a task Events had no key, so "submitted" and "withdrawn" for one claim could land on different partitions and be handled in either order Order lost

    Goal: no duplicate side effects from a worker restart, at most 12 repeated model calls (one in flight per partition), and 95% of claims triaged within 60 seconds of submission at peak.

    Constraints

    • A claim is never lost, even if the model is down or returns garbage.
    • The case-management system creates a task for every request and does not deduplicate.
    • Customers get one acknowledgement, and injury claims reach a human adjuster whatever the model's confidence.

    Why the traditional approach fell short

    Approach Why it fell short
    Rules router on form fields Misroutes the long tail: "other" plus "water through the ceiling after the storm" looks trivial
    Manual triage by clerks Accurate, but the queue grows exactly when claims arrive in bursts
    Classic classifier Needs labelled history and fails on event types it has not seen

    The model reads the narrative, which is why it helps. Queues, restarts and retries are ordinary distributed-systems work that it does nothing to fix.

    Options considered

    Option Idea Verdict
    A. Rules router (non-AI) Route by claim type, amount and postcode Kept as the fallback when the model is unavailable: standard queue by these rules
    B. Synchronous call from intake The portal calls the triage service and waits Rejected: submission waits 3 s plus tail latency, and a model outage blocks submission
    C. Event bus with idempotent workers Keyed events, result and deduplication record in one transaction, offsets committed after the work, a dead-letter topic Accepted
    D. Rely on the broker's exactly-once transactions alone Kafka transactions write records and offsets atomically Rejected as the only defence: it covers what is written to Kafka, not the model call, the email or the task

    The default is C with A behind it. For a few hundred claims a day, a job table polled by one worker is simpler.

    Solution architecture

    Figure 1. Claim triage components with keyed events, deduplication and a dead-letter path

    Claim triage componentsClient app to API gateway; API gateway to Event bus (key: claim id); Event bus to Worker group (deliver); Worker group to Model gateway; Model gateway to LLM provider; Worker group to Document store (one transaction); Document store to Outbox relay; Outbox relay to Event bus (publishes); Event bus to Tool server (deliver); Worker group to Dead-letter topic (2 failed attempts); Dead-letter topic to Approval serviceClient appClient appAPI gatewayAPI gatewayEvent bus: claims.submittedEvent busclaims.submittedLLM providerLLM providerApproval service: manual queueApprovalservicemanual queueDead-letter topicDead-lettertopicWorker group: 12 consumersWorker group12 consumersModel gatewayModel gatewayEvent bus: claims.triagedEvent busclaims.triagedOutbox relayOutbox relayDocument store: dedup, result, outboxDocument storededup, result,outboxTool server: task, email, dedupTool servertask, email,dedupkey: claim iddeliverone transactionpublishesdeliver2 failed attempts

    How to read this: solid arrows are the normal path left to right, the bottom branch is where a claim goes when triage keeps failing, and each box that writes names its deduplication rule.

    Figure 2. Runtime path of one claim event, including a replay

    sequenceDiagram accTitle: Runtime path of one claim event accDescr: The Worker reads a claim event and checks the Document store for its event id. If the event was already processed it skips the model and commits its offset. Otherwise it calls the Model gateway, validates the answer, writes the result with a deduplication record and an outbox row in one transaction, then commits the offset. After two invalid answers it publishes the event to the dead-letter topic. A relay later publishes the triaged event and the Tool server deduplicates before creating the task. autonumber participant B as Event bus participant W as Worker participant D as Document store participant M as Model gateway participant R as Outbox relay participant T as Tool server B->>W: claim submitted (claim C-1042, event E-91, offset n) W->>D: has event E-91 been processed? alt already processed (replay after restart) D-->>W: yes Note over W: Decision - skip the model call W->>B: commit offset n else new event W->>M: triage prompt with narrative and form fields M-->>W: JSON with route, injury flag, confidence Note over W: Decision - validate the schema, apply the injury rule alt answer valid W->>D: one transaction - dedup record, result, outbox row D-->>W: committed W->>B: commit offset n else invalid after the allowed attempts W->>B: publish to the dead-letter topic with the reason W->>B: commit offset n end end R->>D: read unsent outbox rows R->>B: publish claim triaged (event E-92) B->>T: deliver claim triaged Note over T: Skip if E-92 was already applied, else create task and send email

    How to read this: the outer alt separates a replay from new work, the inner alt separates a valid answer from a dead-lettered one, and the last three lines are the separate delivery path from the outbox.

    How AI solved it, step by step

    Step through one claim, then switch to "Without the fix".

    One claim event, end to end (interactive when JavaScript is on)

    As designed

    1. Event arrives. Claim C-1042, event E-91, offset n arrives. The claim id is the event key, so its events share a partition, in order.
    2. Replay check. The worker asks the Document store whether E-91 was processed. If yes, it is a replay: skip the model call and commit offset n.
    3. Triage call. A new event goes to the Model gateway, which returns JSON: a route, an injury flag and a confidence.
    4. Validate. The worker checks the JSON against its schema. Invalid output is retried once; a second failure goes to the dead-letter topic with the reason.
    5. Rules decide. Code applies the rules: an injury flag or a confidence below 0.8 sends the claim to the adjuster queue, never to fast track.
    6. One transaction. The worker writes the deduplication record, the result and an outbox row in one database transaction, then commits offset n.
    7. Dead letter. A dead-lettered claim lands in the manual triage queue and raises an alert, so a person sees it.
    8. Delivery. The outbox relay publishes "claim triaged" (E-92). The Tool server skips an id it has applied, otherwise creates the task and sends one email.

    Without the fix

    1. No event key. "Submitted" and "withdrawn" for one claim can land on different partitions and be handled in either order.
    2. Late commit. Workers create the task and email after every claim but commit their position only every 100.
    3. Restart. A deployment restarts all 12 workers. Each replays up to 99 claims.
    4. Duplicates. Up to 12 x 99 = 1,188 duplicate runs. The case system does not deduplicate, so adjusters see duplicate tasks and customers get two emails.

    Under the hood

    Per Kafka's documentation, events with the same key are written to the same partition, and a consumer reads a partition's events in the order they were written. Each partition is consumed by exactly one consumer in a consumer group at a time, and a consumer's position is a single integer, the offset.

    Order of work A crash in between means Delivery
    Process, then save the position Some messages are seen again At-least-once (Kafka's default)
    Save the position, then process Some messages can be lost At-most-once

    This case chooses at-least-once on purpose: losing a claim is worse than seeing one twice. The consumer is idempotent. The deduplication record shares a transaction with the result, so a replayed event finds it and does nothing.

    Commit policy Uncommitted per partition Worst-case replay on restart
    Every 100 claims 99 12 x 99 = 1,188
    After each event 1 in flight 12

    See Under the hood: Partitions, consumer groups and offsets.

    What went wrong / failure modes

    Failure What happens and what the design does
    Crash between the model call and the transaction The event replays and the model is called again: at most 12 repeated calls per restart, accepted
    Crash inside the Tool server It can fail after creating the task or email and before recording the event id. One repeated task or email per such crash remains possible; the design removes the replay of up to 1,188 claims, not this window
    A poison event A malformed narrative makes the model return invalid JSON twice. Mitigation: the dead-letter topic, an alert when it is non-empty for 15 minutes, and a manual queue. An unread dead-letter topic loses claims
    A parked event lets later ones overtake it Per-claim sequence numbers; a worker that sees a gap routes the claim to the manual queue
    The deduplication record expires Records last 14 days, longer than the topic's 7-day retention, so no replay outlives them

    Results

    These are illustrative targets, not measurements. The Tool server crash window is separate.

    Measure Before After
    Duplicate side effects from worker replays, per restart Worst case 12 x 99 = 1,188 0
    Repeated model calls, per restart Up to 1,188 (no dedupe) At most 12
    Capacity against peak Not stated 12 x (1 claim / 3 s) = 4 claims per second against a peak of 2: 50% utilisation

    Tradeoffs and when NOT to use this approach

    • The deduplication write adds a database dependency, and per-event commits add broker traffic; at 2 claims per second both are small.
    • Ordering holds only within one partition. At low volume, a job table and one worker may beat a bus.
    • Never let the model route injury or coverage-sensitive claims without a human.

    Design rules extracted

    1. Key events by the entity whose order matters, so its events share a partition.
    2. Commit the offset only after the work and its deduplication record are durable, and expect replays.
    3. Give every side effect a key derived from the event, and make each consumer skip keys it has applied.
    4. Send failing events to a dead-letter topic that a person owns, with an alert.
    5. Let the model recommend; let rules decide anything that cannot be undone.

    Assumptions

    • 2 claims per second at peak, 3 s per call and 12 partitions with one worker each are chosen for illustration; utilisation is 2 x 3 / 12 = 0.5.
    • Offsets are committed every 100 claims in the first design: 99 uncommitted per partition in the worst case, 12 x 99 = 1,188.
    • The confidence threshold of 0.8, the 2 model attempts, the 15-minute alert, the 14-day deduplication retention and the 7-day topic retention are invented settings.
    • The Kafka statements are from the Apache Kafka documentation, read on 2026-10-21; the insurer, its systems and all figures are invented.

    Last verified: 2026-10-22

    Ask about this article

    Get answers grounded in this post. AI-generated — based on this article, and may be imperfect.

    Scaled AI Weekly

    Enjoyed this? Get more like it every Monday.

    Real architecture decisions, LLMOps patterns that survive production, and engineering leadership advice — from 12+ years of building at enterprise scale. Free. No spam. Unsubscribe anytime.

    Get new articles by email

    Free. We email a confirmation link first, and you can unsubscribe from any email.

    Join engineers building production AI systems

    Comments