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
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
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".
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
- Key events by the entity whose order matters, so its events share a partition.
- Commit the offset only after the work and its deduplication record are durable, and expect replays.
- Give every side effect a key derived from the event, and make each consumer skip keys it has applied.
- Send failing events to a dead-letter topic that a person owns, with an alert.
- 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