UMAR SAYYAD

PRINCIPAL SOFTWARE ENGINEER

Architecture

Event-Driven Architecture in Insurance Claims

What moving a claims pipeline off nightly batch actually cost

  • Umar Sayyad
  • 2 min read
  • Updated

A claims pipeline that runs once a night is a claims pipeline that is wrong for twenty-three hours a day. Everyone knew it. What nobody had costed was the batch window itself, which had quietly become the place the system put every problem it did not want to solve.

What the batch window was hiding

The nightly job did far more than move rows. It deduplicated claims that had been submitted twice, reconciled payments that had landed out of order, and quietly dropped anything it could not parse. None of that was written down. All of it was load-bearing.

Going event-driven meant each of those behaviours had to become explicit. Deduplication became an idempotency key. Out-of-order payments became a windowed join. The silent drops became a dead-letter topic that somebody had to actually look at.

The shape that worked

Claims enter on one topic and leave on another, with the scoring service in between. The important constraint is that the scorer is pure: the same claim scored twice produces the same result, which is what makes a replay safe.

Go
// internal/claims/score.go
// Score is deterministic: the same claim always yields the same decision.
// That is what makes a replay safe, and a replay is how we recover.
func (s *Scorer) Score(ctx context.Context, c Claim) (Decision, error) {
	if err := c.Validate(); err != nil {
		return Decision{}, fmt.Errorf("claim %s: %w", c.ID, err)
	}

	features := s.features.Extract(c)
	return s.model.Decide(ctx, features)
}

Idempotency, concretely

Every claim carries a key derived from the policy number and the submission timestamp. The consumer writes the decision under that key or does nothing. It is unglamorous and it is the entire reason the migration was reversible.

SQL
INSERT INTO claim_decisions (idempotency_key, claim_id, decision, scored_at)
VALUES ($1, $2, $3, now())
ON CONFLICT (idempotency_key) DO NOTHING;

What it cost

MeasureBatchEvent-driven
Time to decisionup to 26 hoursunder 4 seconds p95
Failure blast radiusthe whole night's runone claim
Operational surface1 cron job3 topics, 2 consumer groups, 1 DLQ
People who understood it2the whole team, eventually

The last row is the one that mattered most a year later.

The operational surface genuinely grew. Anyone who tells you event-driven is simpler has not carried a pager for one. What changed is that the complexity became visible and attributable instead of hiding inside a job that only two people could read.

We did not make the system simpler. We made it possible to be wrong about one claim instead of all of them. — a staff engineer on the team, in the retro

If you are about to do this

  1. Write down what the batch window is doing before you remove it. All of it, including the parts nobody designed.
  2. Make the processor deterministic first. Replay is your recovery story and it does not work without it.
  3. Build the dead-letter path on day one, with an owner. A DLQ nobody reads is a silent drop with extra steps.
  4. Expect the operational surface to grow, and budget for the on-call training that comes with it.

The migration took two quarters, which was roughly twice the estimate. Every week of the overrun went into the four items above, and none of it was wasted.