Design a fraud decision service around its deadline
System design turns business requirements into data paths, service boundaries, failure behaviour, and measurable contracts. The goal is not to draw the most boxes; it is to explain what must happen, when it must happen, what can fail, and how evidence returns to improve the system.
Our synthesis system scores card transactions for fraud in real time. It must respond quickly without treating every model score as a final truth. A decision policy combines prediction, threshold, deterministic business rules, and a manual-review path.
What You Will Be Able to Explain
- Translate functional and non-functional requirements into architecture
- Separate synchronous decisions from asynchronous learning
- Design feature, model, duplicate-event, and timeout fallbacks
- Prevent leakage with delayed fraud labels
- Calculate capacity and plan release/rollback lineage
The contracts in an end-to-end ML architecture
These terms name different responsibilities. Read the meaning before following them through the diagrams and worked example.
Core vocabulary
Start with the decision deadline, then attach the learning loop
The synchronous path validates the transaction, deduplicates its identity, reads fresh real-time features, obtains a model score, and applies threshold plus business rules. Only these operations belong on the customer-facing deadline because the approve/review/reject result cannot be returned without them.
Prediction logging is initiated on the live path but written durably without making slow analytics block the response. Monitoring, delayed fraud labels, training-dataset construction, candidate training, evaluation, registry approval, canary analysis, and broad release are asynchronous.
End-to-end real-time fraud detection system
How do the live decision path and learning feedback loop connect?
Keep the customer decision path short; move learning work off it
Which operations must finish before the transaction response?
Design the failure path before it is needed
If the online feature store is unavailable, use only a reviewed fallback: a fresh-enough cache with recorded age, a model designed for a reduced feature set, deterministic high-risk rules, or manual review. If the model times out, do not blindly approve; cancel it and follow the degraded decision policy.
Stream duplicates are handled with a stable transaction/idempotency key and a stored prior outcome. Delayed labels join to the original transaction and prediction timestamp. Features for a historical row are cut off at that time; the later fraud report is the label, never an earlier feature.
A candidate release records code, training data, feature definitions, environment, artifact, metrics, threshold, rules, and runtime versions. Shadow or canary evidence decides promotion. Rollback changes traffic to the previous known-good bundle while preserving the incident trail.
Requirements become measurable design decisions
Worked Example: Calculate minimum theoretical serving capacity
Given: Peak traffic is 2,000 requests/second. One model instance safely handles 250 requests/second under the approved latency target. Assume perfect balancing and no failed or unavailable instance for the theoretical calculation.
- Required theoretical count = peak rate ÷ safe per-instance rate.
- 2,000 ÷ 250 = 8 instances.
- Check: 8 × 250 = 2,000 requests/second, exactly equal to the stated peak.
- Eight leaves no capacity for a burst above forecast, one failed instance, deployment replacement, maintenance, or estimation error. Losing one leaves 7 × 250 = 1,750 requests/second.
- Production therefore provisions more than the theoretical minimum or defines controlled load shedding. The amount of headroom is chosen from failure tolerance, burst data, scaling delay, SLO, and cost—not a universal percentage.
Result and interpretation: Eight is the minimum mathematical count under ideal assumptions, not a safe production plan. Capacity design includes redundancy, scaling time, overload policy, and validated latency at load.
The following figures turn the example into an operational decision. Follow every branch and note which state is recorded before work continues.
Named failures lead to named safe routes
How does the system avoid blindly approving when a dependency fails?
Ten system-design questions answered
Translate capacity and fallback decisions into an implementation
The label above each block states what it is. Runnable Python can be executed as shown with the standard library; pseudocode and configuration communicate architecture and require adaptation to a real platform.
Make the fraud decision path explicit
The model produces evidence; trusted policy produces the action. Every branch writes a versioned reason and uses the transaction key idempotently.
def decide(transaction):
prior = decisions.get(transaction.idempotency_key)
if prior:
return prior
validated = validate(transaction)
features = feature_service.get(validated.card_id, deadline_ms=25)
if not features:
return persist_and_review(validated, "features_unavailable")
score = model.predict(features, deadline_ms=35)
if score is None:
return apply_reviewed_fallback(validated)
action = policy.apply(score, validated, threshold_version="t7")
return persist_once(action, versions=current_versions())Describe the release bundle
Rollback must restore compatible components, not only model bytes.
release: fraud-v23
model_artifact: model-v23
feature_contract: fraud-features-v8
request_schema: transaction-v5
decision_policy: policy-v7
threshold: 0.82
runtime_image: sha256:runtime-19
rollback_bundle: fraud-v22
canary_guardrails: [p95_latency, error_rate, review_rate, confirmed_loss]Make the fraud service's trade-offs explicit
- Write functional and non-functional requirements, traffic assumptions, data availability, and error costs before choosing components.
- Keep the synchronous path minimal and time-bounded; make durable learning work asynchronous.
- Define a safe degraded result for every critical dependency and test it under realistic load.
- Record compatible bundles of model, features, schema, policy, threshold, and runtime so release and rollback remain coherent.
Failure Analysis and Recovery
Observed failure → likely cause → controlled response
Connect to Earlier Lessons
- Customer churn project
Apply the lifecycle to a classical ML project.
- RAG project
Compare retrieval and evidence failures in a generative system.
- Multi-agent project
Compare multi-step coordination and observability trade-offs.
Summary / Key Takeaways
- System design begins with the user decision, functional requirements, non-functional requirements, and explicit assumptions.
- Real-time validation, deduplication, feature lookup, inference, and decision policy form the synchronous fraud path.
- Logging, delayed labels, monitoring, dataset creation, training, evaluation, and release belong to durable asynchronous workflows.
- Feature or model failure must route to reviewed cache, reduced capability, deterministic rules, or manual review—not blind approval.
- Point-in-time joins keep delayed fraud labels out of earlier features and preserve leakage-safe training data.
- Eight instances are the theoretical minimum for 2,000 requests/second at 250 each, but production needs evidence-based failure and burst headroom.
- Safe release and rollback require lineage for the compatible model, feature, schema, threshold, policy, data, code, environment, and runtime bundle.