Rebuilding a Real-Time Risk Platform: Decision Record
After separating rule management, stream processing, and decision records, P99 decision latency fell from minutes to under a minute. The trade-offs, and which choices I would make again.
On this page · 13 sections
At Soul I led platform engineering for real-time risk control: feature computation, event processing, rule execution, and the tooling policy teams used every day. When I arrived, the system worked—but it worked by being slow and by asking everyone to be careful. P99 decision latency—that is, the time within which 99% of decisions complete—was measured in minutes, and the only way to learn what a policy change would do was to ship it.
This is the decision record I wish I had been handed on day one. Company details, internal identifiers, and exact traffic figures are generalized; the shape of the problem and the trade-offs are not.
TL;DR for reviewers
- Problem: rule authoring, feature computation, and enforcement shared one path, so policy velocity traded directly against latency and safety.
- Decision: separate a rule control plane, a bounded streaming hot path (Kafka, Spark, Redis), and an evidence plane for replay and A/B comparison.
- Outcome: P99 decision latency went from minutes to under a minute; policy changes became testable against real traffic before they reached users; non-compliant content dropped materially across the app.
- Cost we accepted: rule changes propagate in bounded seconds instead of instantly, and the system now carries more explicit state—versions, cursors, decision records—that someone has to own.
Context: what “risk control” actually had to guarantee
A social product generates a continuous stream of events: posts, messages, profile edits, logins, payments. Risk control has to look at each one, combine it with recent behaviour, run a changing set of rules, and decide—allow, review, limit, or block.
Three groups depended on that decision, and each defined “correct” differently. In the table, look at the last column: all three pains came from the same shared path.
| Stakeholder | What they needed | What hurt them |
|---|---|---|
| Policy and operations | Change rules quickly when abuse patterns shift | Every change was a production gamble |
| Product and users | Fast, consistent decisions with few false positives | Slow decisions let abuse spread; wrong ones punished real users |
| Engineering on call | A hot path whose cost was predictable | One expensive rule could slow every decision |
The staff-level work was not “make it faster.” It was to stop those three needs from fighting over the same code path.
The constraints I wrote down first
Before discussing technology, I wrote the contracts the new system had to keep. Every later design argument was settled by pointing at one of them.
- Freshness: event-to-decision latency has an explicit P99 target, and rule propagation has its own, separate bound.
- Bounded cost: no rule may perform unbounded work on the hot path—no unlimited windows, no unbounded fan-out, no external call without a timeout and a fallback.
- Ordering where it matters: order is guaranteed per business key (a user, a device), never globally.
- Idempotent effects: events can be processed more than once; enforcement actions must not be applied twice.
- Explainability: any historical decision can be traced to the event, the feature values, and the exact rule version that produced it.
- Unknown is not false: a missing feature or a timed-out dependency produces an explicit reason code, never a silent “no match.”
Writing these down did more for alignment than any diagram. Policy teams could see that “instant rule changes” and “bounded hot path” were competing asks, and we could have that argument once, on paper, instead of in every incident review.
Options considered
The table lists four options. Look at the last column: why the first three were rejected, and what the chosen one costs.
| Option | Why it was attractive | Why I rejected it |
|---|---|---|
| Tune the existing path (caching, bigger machines) | Lowest short-term risk | Latency would improve, but authoring and execution stayed coupled; the next policy surge would undo the gain |
| Synchronous rule service called inline by every product path | Simple mental model | Every peak and every slow dependency would propagate into user-facing requests |
| Buy or adopt a general-purpose rules product | Faster start | Did not fit our feature model, replay needs, or per-key ordering; we would still own the hard parts |
| Three planes: control, streaming data, evidence | Separates the rate of change from the rate of traffic | More moving parts and more explicit state to operate |
The decisive argument was rates of change. Rules change a few times a day and are high-risk. Events arrive continuously and must be cheap. Evidence is written constantly but read rarely. Putting three different rates on one path guarantees that the slowest, riskiest one sets the pace for all of them.
The architecture
The diagram below shows the three planes together: the control plane produces an immutable bundle and moves the active pointer, the data plane decides on a bounded hot path, and the evidence plane records every decision off the hot path.
Control plane: rules become immutable artifacts
A rule edit no longer changed production directly. It produced a candidate bundle—that is, a versioned package of rules—that was validated, cost-checked, and—crucially—replayed against recorded traffic and compared with the active bundle. Only then could an operator move the active pointer. Rollback meant moving the pointer back, not editing rules in a panic.
Evaluators loaded a verified local snapshot and switched at an event boundary. That is why rule propagation became “bounded seconds” rather than “instant”: it was the price of every evaluator agreeing on exactly which version made each decision.
Data plane: a hot path with a budget
The streaming path was redesigned around three components:
- Kafka for durable, replayable input;
- Spark for feature computation;
- Redis for low-latency feature reads.
Three choices did most of the work:
- Partition by the business key whose order matters. Ordering per user was a requirement; global ordering was not. Hot keys were handled explicitly rather than by salting away the ordering guarantee.
- Give every rule a budget. Rules declared their cost class at authoring time; the control plane rejected rules whose cost could not be bounded. This moved the “one bad rule slows everything” failure from production to review.
- Precompute what can be precomputed. Features that were reused across many rules were computed once and cached, instead of being recomputed inside each rule.
Evidence plane: make every decision explainable
Each decision wrote a compact record: event identity, feature versions, bundle version, decision id, and reason codes. That record powered three things the old system could not do:
- explain a decision to an appeals reviewer;
- replay history against a candidate bundle;
- run A/B comparisons between policies on live traffic without letting the experiment enforce anything.
Rollout: shadow first, then traffic, then authority
The migration was a series of reversible steps, each with an explicit exit criterion:
- Shadow: the new path evaluated real events and recorded decisions but enforced nothing. We compared its decisions with the legacy path and investigated every systematic difference.
- Canary by traffic slice: a small share of keys was enforced by the new path, with automatic fallback if latency or error budgets were breached.
- Expand by event type: high-volume, low-risk event types moved first; complex, high-impact ones last.
- Retire the legacy path only after the replay tooling could reproduce historical decisions it had made.
The most valuable artifact of the rollout was the diff report from shadow mode. It surfaced rules whose behaviour depended on accidental timing in the old system—bugs that had looked like policy.
Outcome
- Latency: P99 decision latency dropped from minutes to under a minute.
- Policy velocity: rule and policy authors gained replay and A/B testing, so changes were evaluated against real traffic before they took effect.
- Effectiveness: non-compliant content fell materially across the app.
- Team: design-review and code-review standards written for this project became the team's defaults, and the engineers I coached owned major parts of the platform afterwards.
What I would do differently
- Build the evidence plane first. Replay and explanation were what made every later step safe. Starting with them would have shortened the shadow phase.
- Make reason codes a product surface earlier. Operations teams used them far more than dashboards; they deserved design attention from the start.
- Budget the control plane too. We bounded rule cost on the hot path but let validation and replay jobs grow freely, and they became the next bottleneck for policy velocity.
Lessons that transfer beyond risk control
- Separate things that change at different rates. Most platform pain comes from forcing a slow, risky process and a fast, cheap one through the same path.
- A mutable pointer to immutable content is the simplest reliable way to get fast rollback and reproducible history.
- Shadow traffic is a design tool, not only a test. The disagreements it surfaces are often the most honest requirements document you will get.
- Write the contract before the architecture. At staff scope, the document that ends an argument is worth more than the diagram that starts one.
Related reading
- Local RAG Design: Store the Evidence First, Then Retrieve applies the same evidence-first separation to retrieval.
- Work Habits I Changed as My Scope Grew describes the working habits behind this project.
Related notes
LLM Runtime: Which Layer Should Own Rate Limits, Retries, and Routing
Once the second business, the second provider, and the second tenant show up, calling the SDK directly is no longer enough. This piece covers the responsibility boundary of an LLM Runtime, multi-model routing, reliability under high concurrency, and how to choose an observability approach.
Five Questions to Answer Before Putting Agents into Production
Cost and risk, who holds control, how delivery is verified, which layer owns model calls, and how it is evaluated after launch: answer these in order before writing Agent code.
Working on something similar?
I'm always happy to compare notes on distributed systems, delivery, and applied AI.
[email protected]