Bird
Raised Fist0

Fraud Detection System - Real-Time Transaction Scoring

SYSTEM-DESIGNhardInterview freq: very_high
Choose your preparation mode6 modes available
⚖️
Gradient Boosting vs Neural Network

In a real-time fraud detection system with a 50ms latency SLA, would you use gradient boosting or a neural network? Justify your choice.

📊
Comparison
DimensionGradient BoostingNeural Network
Accuracy on structured dataHighModerate
Training speedFastSlow
Inference latencyModerateFast
InterpretabilityHighLow
ScalabilityModerateHigh
✅
Verdict
Default to gradient boosting for fraud detection on tabular data with n < 1M and latency SLA > 50ms. Switch to neural networks when n > 1M, latency SLA < 50ms, and complex interaction modeling is required.
💡
Key Insight
The choice between gradient boosting and neural networks hinges on data volume, latency requirements, and the complexity of feature interactions.
⚠️
Interview Trap
❌ Wrong: Always use gradient boosting for tabular data.
Ignoring the need for real-time interaction modeling and low latency requirements.
✅ Consider the latency requirements and the complexity of interactions; neural networks may be necessary for real-time, low-latency systems with complex data.
Gradient Boosting
"High performance on tabular data with limited computational resources."
  • 2-3× slower inference time compared to neural networks when optimized for latency.
  • Limited ability to capture complex feature interactions without manual feature engineering.
  • Scalability issues with very large datasets (n > 10M) due to memory constraints.
  • Less effective in leveraging unstructured data like images or text.
Ideal When
  • n < 1M
  • Latency SLA > 50ms
  • Feature count < 100
  • Limited computational resources (e.g., no GPU access)
PayPal uses gradient boosting for fraud detection due to its efficiency on structured transaction data and interpretability.
Neural Network
"Ability to model complex interactions and leverage embeddings for high-dimensional data."
  • Requires significant computational resources, often necessitating GPU acceleration.
  • Longer training times compared to gradient boosting, especially on smaller datasets.
  • Can be prone to overfitting without careful regularization and tuning.
  • Less interpretable, making it challenging for regulatory environments.
Ideal When
  • n > 1M
  • Latency SLA < 50ms
  • Access to GPUs
  • Need to model complex interactions or use embeddings
Stripe employs neural networks for real-time fraud detection, leveraging their ability to handle large-scale data and complex patterns.
🐍
Gradient Boosting - Example
▼ Show
Python
from sklearn.ensemble import GradientBoostingClassifier
model = GradientBoostingClassifier(n_estimators=100, learning_rate=0.1)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
🐍
Neural Network - Example
▼ Show
Python
from keras.models import Sequential
from keras.layers import Dense
model = Sequential()
model.add(Dense(64, input_dim=X_train.shape[1], activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='adam', loss='binary_crossentropy')
model.fit(X_train, y_train, epochs=10, batch_size=32)
✅
Use Gradient Boosting When
  • •n < 1M
  • •Latency SLA > 50ms
  • •Limited computational resources
  • •Feature count < 100
✅
Use Neural Network When
  • •n > 1M
  • •Latency SLA < 50ms
  • •Access to GPUs
  • •Need for complex interaction modeling
↳
Nuances
  • For tabular data even with 10M rows, gradient boosting often matches neural networks because the inductive bias of convolutions/attention doesn't apply - structure is in features, not space.
  • Neural networks can outperform gradient boosting when embeddings are crucial for capturing user/item interactions.
  • Gradient boosting's interpretability can be a decisive factor in regulated industries where model decisions need to be explained.

Practice

(1/5)
1. For an ad click-through rate prediction model, which metric is most appropriate to optimize for business value?
easy
A. Recall
B. Precision
C. AUC-ROC
D. Accuracy

Solution

  1. Step 1: Understand business objectives.

    CTR prediction models need to balance true positive rate and false positive rate.
  2. Step 2: Eliminate wrong options.

    Accuracy (A) doesn't account for class imbalance. Precision (B) and Recall (C) focus on one aspect of performance, not the trade-off.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    AUC-ROC balances trade-offs in CTR. [OK]
Hint: AUC-ROC balances trade-offs in CTR. [OK]
Common Mistakes:
2. For an anomaly detection system using an Autoencoder, which metric is most appropriate to evaluate its performance?
easy
A. Precision
B. Reconstruction Error
C. Accuracy
D. F1 Score

Solution

  1. Step 1: Identify the key metric for Autoencoders.

    Autoencoders are evaluated based on how well they can reconstruct the input data, making reconstruction error a critical metric.
  2. Step 2: Eliminate wrong options.

    Accuracy is incorrect because accuracy is not informative for imbalanced datasets. Precision and D are more relevant for classification tasks, not reconstruction tasks.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Autoencoder = reconstruction error focus [OK]
Hint: Autoencoder = reconstruction error focus [OK]
Common Mistakes:
3. For a spam detection system, which metric is most appropriate to optimize for?
easy
A. F1 Score
B. Precision
C. Recall
D. Accuracy

Solution

  1. Step 1: Understand the importance of balancing precision and recall

    F1 Score balances precision and recall, which is crucial in spam detection.
  2. Step 2: Eliminate less balanced metrics

    Accuracy (A) can be misleading with imbalanced data. Precision (B) and Recall (C) alone don't balance false positives and negatives.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    F1 balances precision and recall. [OK]
Hint: F1 balances precision and recall. [OK]
Common Mistakes:
4. In an LLM evaluation system, what failure might occur if the benchmark tasks are not updated regularly?
medium
A. The system will become too complex to manage.
B. The evaluation results will become less relevant over time.
C. The LLM will overfit to the benchmark tasks.
D. The human evaluators will become biased.

Solution

  1. Step 1: Consider the impact of outdated benchmarks

    Outdated benchmarks can lead to less relevant evaluation results as models evolve.
  2. Step 2: Eliminate wrong options

    Complexity and human bias are unrelated to benchmark updates, and overfitting is more about training data.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Outdated benchmarks lead to irrelevant results. [OK]
Hint: Outdated benchmarks lead to irrelevant results. [OK]
Common Mistakes:
5. In an HNSW-based vector search system, what is a likely failure mode if the graph's maximum layer is not properly maintained?
medium
A. Increased precision but decreased recall
B. Increased memory usage without affecting speed
C. Decreased search speed due to inefficient traversal
D. Decreased indexing speed but improved search accuracy

Solution

  1. Step 1: Understand the role of the maximum layer.

    The maximum layer affects traversal efficiency.
  2. Step 2: Eliminate wrong options.

    Precision, recall, and memory usage are not directly affected by the maximum layer.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Max layer affects traversal speed. [OK]
Hint: Max layer affects traversal speed. [OK]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard