← Innovation & Leadership
AI ARCHITECT · R&D · MASTER STUDY GUIDE

AI Architect
Complete Reference

Basics → Advanced → Code → Scenarios → Architecture → Quiz

📐 ML Algorithms — Basics to Advanced

BASIC Supervised Learning

Linear Regression

Predicts continuous output using a line: y = mx + b. Loss = MSE.

Logistic Regression

Binary classification via sigmoid: σ(z) = 1/(1+e⁻ᶻ).

Decision Trees

Splits data by feature thresholds. Prone to overfit without pruning.

ADVANCED Ensemble Methods

XGBoost

Gradient boosting with regularization (L1/L2), tree pruning, column subsampling.

LightGBM

Histogram-based splits, leaf-wise growth — faster than XGBoost on large data.

Random Forest

Bagging of decision trees; reduces variance via averaging.

ADVANCED Neural Networks

CNN

Convolutional layers extract spatial features. Used in image/time-series tasks.

RNN/LSTM

Sequential memory via gates: input, forget, output. Handles time-series.

Transformer

Attention-based parallelism. Backbone of modern LLMs.

💻 ML Code — Simple & Memorable
🔹 XGBoost Classifier
pythonfrom xgboost import XGBClassifier from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score # Split data X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.2, random_state=42 ) # Train model model = XGBClassifier(n_estimators=100, max_depth=5, learning_rate=0.1, use_label_encoder=False) model.fit(X_train, y_train) # Evaluate preds = model.predict(X_test) print(f"Accuracy: {accuracy_score(y_test, preds):.2%}")
🔹 Neural Net with PyTorch
pythonimport torch import torch.nn as nn class SimpleNet(nn.Module): def __init__(self, in_dim, out_dim): super().__init__() self.net = nn.Sequential( nn.Linear(in_dim, 128), nn.ReLU(), nn.Dropout(0.3), nn.Linear(128, out_dim) ) def forward(self, x): return self.net(x) model = SimpleNet(20, 2) optimizer = torch.optim.Adam(model.parameters(), lr=1e-3) loss_fn = nn.CrossEntropyLoss()
📊 Feature Engineering & EDA

BASIC EDA Steps

  • Shape / dtypes / .describe()
  • Missing value analysis: df.isnull().sum()
  • Distribution plots: histplot, boxplot
  • Correlation heatmap (seaborn)
  • Outlier detection: IQR / Z-score
🔹 Feature Engineering Pipeline
pythonfrom sklearn.pipeline import Pipeline from sklearn.preprocessing import StandardScaler, OneHotEncoder from sklearn.compose import ColumnTransformer from sklearn.impute import SimpleImputer num_pipe = Pipeline([ ('impute', SimpleImputer(strategy='median')), ('scale', StandardScaler()) ]) cat_pipe = Pipeline([ ('impute', SimpleImputer(strategy='most_frequent')), ('encode', OneHotEncoder(handle_unknown='ignore')) ]) preprocessor = ColumnTransformer([ ('num', num_pipe, num_cols), ('cat', cat_pipe, cat_cols) ])
🔬 Developer-Level AIML Interview Questions

DEV Bias-Variance Tradeoff

High bias → underfitting (model too simple). High variance → overfitting (model memorizes). Solution: regularization (L1/L2), dropout, more data, cross-validation.

DEV Imbalanced Classes

Techniques: SMOTE oversampling, class_weight='balanced', use PR-AUC/F1 instead of accuracy, threshold tuning, ensemble methods.

DEV Gradient Descent Variants

BGD: full batch, stable but slow. SGD: noisy but fast. Mini-batch: best of both. Adam: adaptive LR — default choice for deep learning.

DEV Hyperparameter Tuning

GridSearchCV (exhaustive), RandomizedSearchCV (fast), Optuna (Bayesian optimization), Ray Tune (distributed). Always use k-fold CV to evaluate.

🎬 Real-Time Scenarios

Scenario 1: Fraud Detection System

You have 1M transactions, 0.1% are fraud. Your XGBoost model has 99% accuracy but catches only 20% of fraud cases. What do you do?

▶ Show Answer
The accuracy is misleading (imbalanced classes). Actions: (1) Switch metric to Recall/F1/AUC-PR. (2) Apply SMOTE or adjust scale_pos_weight in XGBoost. (3) Lower the decision threshold from 0.5 to 0.2. (4) Use cost-sensitive learning. (5) Try ensemble with isolation forest for anomaly detection layer.

Scenario 2: Model Degradation in Production

Your credit scoring model was 92% accurate at launch. After 6 months accuracy dropped to 78%. No code changed. Why?

▶ Show Answer
Data drift / concept drift. The distribution of input features has changed (economic conditions, user behavior shifts). Fix: (1) Monitor feature distributions with KL divergence. (2) Set up automated retraining triggers. (3) Use MLflow to version models. (4) Implement shadow deployment to test new model before swap. (5) Add feature drift alerts via Evidently AI.
🧠 LLM Fundamentals

BASIC Transformer Architecture

Self-Attention

Computes relevance of each token to every other token via Q, K, V matrices.

Positional Encoding

Sine/cosine waves injected to give tokens position awareness.

Feed-Forward

Two linear layers with non-linearity applied per token independently.

ADVANCED LLM Variants

Frontier closed model

Multimodal, 128k context, RLHF + RLAIF trained.

BERT

Encoder-only. Masked LM pretraining. Best for NLU tasks.

Open-weight model

Open-weight. Group Query Attention, RoPE embeddings, SwiGLU.

Long-context model

1M token context, mixture-of-experts, native multimodal.

ADVANCED Fine-Tuning Techniques

Full Fine-Tuning

All weights updated. Expensive, needs lots of GPU RAM.

LoRA

Low-Rank Adaptation: adds small trainable matrices A, B. ΔW = BA.

QLoRA

LoRA on 4-bit quantized model. Fits 70B on single A100.

RLHF

Reward model from human preferences → PPO policy update.

🛠️ Prompt Engineering

Techniques

  • Zero-shot No examples, direct instruction
  • Few-shot 2-5 input→output examples
  • CoT "Let's think step by step"
  • ReAct Reason + Act in alternation
  • Tree of Thought Explore multiple paths
  • Self-Consistency Sample N paths, majority vote
🔹 LLM API with structured output
pythonfrom openai import OpenAI import json client = OpenAI() response = client.chat.completions.create( model="gpt-4o", response_format={"type": "json_object"}, messages=[ {"role": "system", "content": "Extract entities. Return JSON."}, {"role": "user", "content": "Apple Inc. was founded by Steve Jobs in 1976."} ] ) result = json.loads(response.choices[0].message.content) print(result)
🔗 LLM Orchestration / Gen AI Frameworks
🔹 Orchestration chain (Python)
pythonfrom langchain_openai import ChatOpenAI from langchain_core.prompts import ChatPromptTemplate from langchain_core.output_parsers import StrOutputParser llm = ChatOpenAI(model="gpt-4o-mini") prompt = ChatPromptTemplate.from_template( "Summarize this in 3 bullets:\n{text}" ) # LCEL pipe syntax chain = prompt | llm | StrOutputParser() result = chain.invoke({"text": "Your document here..."}) print(result)
🔹 LangGraph Agent Loop
pythonfrom langgraph.graph import StateGraph, END from typing import TypedDict, List class AgentState(TypedDict): messages: List[str] next_action: str def call_llm(state): # Call LLM, return updated state return {"next_action": "tool" if needs_tool else "end"} def call_tool(state): # Execute tool, append result return state graph = StateGraph(AgentState) graph.add_node("llm", call_llm) graph.add_node("tool", call_tool) graph.add_conditional_edges("llm", lambda s: s["next_action"]) app = graph.compile()
🎬 Gen AI Scenarios

Scenario: LLM Hallucinating in Customer Support Bot

Your LLM-powered support bot is confidently giving wrong answers about product pricing and policies. It's in production. How do you fix this?

▶ Show Answer
1. Implement RAG: pull real-time pricing/policy from your DB/Confluence before generating answer. 2. Add a system prompt: "Only answer from the provided context. Say 'I don't know' if not in context." 3. Add guardrails with NeMo Guardrails or LlamaGuard for output validation. 4. Implement confidence scoring — route low-confidence answers to human agents. 5. Log all responses, implement human-in-the-loop for high-stakes decisions. 6. Fine-tune on verified QA pairs for domain alignment.
🔄 MLOps Lifecycle
— MLOps Pipeline —
Data Ingest
→
Feature Store
(Feast/Tecton)
→
Model Training
(managed ML platform)
→
Experiment Tracking
(MLflow/W&B)
Model Registry
→
CI/CD
(GitHub Actions)
→
Serving
(FastAPI/Triton)
→
Monitoring
(Evidently/Grafana)
📦 MLflow — Model Versioning
pythonimport mlflow import mlflow.sklearn mlflow.set_experiment("fraud-detection-v2") with mlflow.start_run(): # Log params mlflow.log_param("n_estimators", 100) mlflow.log_param("max_depth", 5) # Train model.fit(X_train, y_train) # Log metrics mlflow.log_metric("f1", f1_score(y_test, preds)) mlflow.log_metric("auc", roc_auc_score(y_test, proba)) # Log model mlflow.sklearn.log_model(model, "model") run_id = mlflow.active_run().info.run_id
python# Register model to registry result = mlflow.register_model( f"runs:/{run_id}/model", "FraudDetectionModel" ) # Transition to production client = mlflow.MlflowClient() client.transition_model_version_stage( name="FraudDetectionModel", version=result.version, stage="Production" ) # Load in serving model = mlflow.pyfunc.load_model( "models:/FraudDetectionModel/Production" )
🐳 Docker + Kubernetes for ML
🔹 Dockerfile for ML API
dockerfileFROM python:3.11-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . EXPOSE 8000 CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
🔹 FastAPI Model Endpoint
pythonfrom fastapi import FastAPI from pydantic import BaseModel import mlflow app = FastAPI() model = mlflow.pyfunc.load_model("models:/FraudModel/Production") class Transaction(BaseModel): amount: float merchant_category: str hour_of_day: int @app.post("/predict") def predict(tx: Transaction): df = pd.DataFrame([tx.dict()]) proba = model.predict_proba(df)[0][1] return {"fraud_prob": proba, "flag": proba > 0.5}
🔹 K8s Deployment YAML
yamlapiVersion: apps/v1 kind: Deployment metadata: name: fraud-model-api spec: replicas: 3 selector: matchLabels: app: fraud-api template: metadata: labels: {app: fraud-api} spec: containers: - name: api image: myrepo/fraud-api:1.2 ports: - containerPort: 8000 resources: requests: memory: "512Mi" cpu: "250m" limits: memory: "1Gi" cpu: "500m" --- apiVersion: v1 kind: Service metadata: name: fraud-api-svc spec: type: LoadBalancer ports: - port: 80 targetPort: 8000
🔍 RAG Pipeline Architecture
— RAG Flow —
Documents
(PDF/Web/DB)
→
Chunking
(RecursiveTextSplitter)
→
Embedding
(text-embedding-3)
→
Vector DB
(managed vector DB)
User Query
→
Embed Query
→
Similarity Search
(Top-K chunks)
→
LLM + Context
→ Answer
💻 RAG Implementation
🔹 Ingestion Pipeline
pythonfrom langchain_community.document_loaders import PyPDFLoader from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain_openai import OpenAIEmbeddings from langchain_pinecone import PineconeVectorStore # Load & split loader = PyPDFLoader("policy.pdf") docs = loader.load() splitter = RecursiveCharacterTextSplitter( chunk_size=1000, chunk_overlap=200 ) chunks = splitter.split_documents(docs) # Embed and store embeddings = OpenAIEmbeddings(model="text-embedding-3-large") vectorstore = PineconeVectorStore.from_documents( chunks, embeddings, index_name="my-index" )
🔹 RAG Query Chain
pythonfrom langchain.chains import RetrievalQA from langchain_openai import ChatOpenAI llm = ChatOpenAI(model="gpt-4o", temperature=0) retriever = vectorstore.as_retriever( search_type="mmr", # max marginal relevance search_kwargs={"k": 5, "fetch_k": 20} ) qa_chain = RetrievalQA.from_chain_type( llm=llm, retriever=retriever, return_source_documents=True ) result = qa_chain.invoke("What is our refund policy?") print(result["result"]) print([d.metadata["page"] for d in result["source_documents"]])
🤖 AI Agent Frameworks

ADVANCED Agent Architectures

ReAct Agent

Thought → Action → Observation loop. Uses tools and reasons over results.

Plan-and-Execute

Planner LLM creates steps → Executor LLM runs each step.

Multi-Agent

Supervisor routes to specialist agents (coder, researcher, analyst).

🔹 Tool-calling Agent
pythonfrom langchain.agents import create_tool_calling_agent, AgentExecutor from langchain.tools import tool @tool def get_stock_price(ticker: str) -> str: """Get current stock price for a ticker symbol.""" return f"${ticker}: $182.50" # mock @tool def calculate_pe_ratio(price: float, eps: float) -> float: """Calculate P/E ratio.""" return price / eps tools = [get_stock_price, calculate_pe_ratio] agent = create_tool_calling_agent(llm, tools, prompt) executor = AgentExecutor(agent=agent, tools=tools, verbose=True) executor.invoke({"input": "Analyze AAPL stock with P/E ratio"})
🔒 AI Security & Compliance

Prompt Injection

Attacker embeds instructions in user input to override system prompt. Defense: Input sanitization, instruction hierarchy, NeMo Guardrails, separate system/user contexts.

Data Leakage

LLMs may memorize training data. Defense: PII detection before RAG ingestion (Presidio), output filtering, differential privacy in fine-tuning.

OWASP LLM Top 10

  • Prompt Injection
  • Insecure Output Handling
  • Training Data Poisoning
  • Model Denial of Service
  • Supply Chain Vulnerabilities
🐍 Python Essentials for Data Science
🔹 Pandas Power Patterns
pythonimport pandas as pd import numpy as np # Method chaining — clean & readable result = ( df .query("amount > 1000 and status == 'completed'") .assign(log_amount=lambda x: np.log1p(x["amount"])) .groupby("merchant_category") .agg( total=("amount", "sum"), avg=("amount", "mean"), count=("amount", "count") ) .sort_values("total", ascending=False) .reset_index() )
🔹 Decorators & Generators
pythonimport time, functools # Timing decorator def timeit(func): @functools.wraps(func) def wrapper(*args, **kwargs): start = time.perf_counter() result = func(*args, **kwargs) elapsed = time.perf_counter() - start print(f"{func.__name__}: {elapsed:.3f}s") return result return wrapper # Memory-efficient generator def chunk_dataframe(df, size=1000): for i in range(0, len(df), size): yield df.iloc[i:i+size] # Async for parallel API calls import asyncio, aiohttp async def fetch_all(urls): async with aiohttp.ClientSession() as session: tasks = [fetch(session, url) for url in urls] return await asyncio.gather(*tasks)
❓ Python Interview Q&A

DEV GIL — Global Interpreter Lock

Python's GIL allows only one thread to execute at a time. For CPU-bound tasks, use multiprocessing. For I/O-bound, use asyncio or threading. GIL doesn't affect multi-process ML training.

DEV Memory Optimization

Use generators instead of lists. Downcast dtypes: df.astype({'col': 'float32'}). Use __slots__ in classes. Dask for out-of-memory DataFrames. Polars for fast columnar ops.

DEV Context Managers

from contextlib import contextmanager @contextmanager def timer(label): t = time.time() yield print(f"{label}: {time.time()-t:.2f}s")

DEV List vs Generator Performance

List: O(n) memory, instantiated upfront. Generator: O(1) memory, lazy evaluation. For ML pipelines processing millions of records, generators are essential to avoid OOM errors.

☕ Java Core + Spring Boot
🔹 Spring Boot Microservice Skeleton
java// Entity @Entity @Table(name="transactions") public class Transaction { @Id @GeneratedValue private Long id; private BigDecimal amount; private String status; private LocalDateTime createdAt; } // Repository public interface TransactionRepo extends JpaRepository<Transaction, Long> { List<Transaction> findByStatus(String status); } // Service @Service @Transactional public class TransactionService { @Autowired private TransactionRepo repo; public Transaction process(TransactionDto dto) { var tx = mapper.toEntity(dto); return repo.save(tx); } }
🔹 REST Controller + Validation
java@RestController @RequestMapping("/api/v1/transactions") public class TransactionController { @Autowired private TransactionService svc; @PostMapping public ResponseEntity<Transaction> create(@Valid @RequestBody TransactionDto dto) { return ResponseEntity .status(HttpStatus.CREATED) .body(svc.process(dto)); } @GetMapping("/{id}") public ResponseEntity<Transaction> get(@PathVariable Long id) { return svc.findById(id) .map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); } }
🌐 Microservices Patterns

ADVANCED Circuit Breaker

Resilience4j: CLOSED → OPEN (after N failures) → HALF_OPEN (probe). Prevents cascade failures between services.

@CircuitBreaker(name="fraud-svc", fallbackMethod="fallback") public Boolean checkFraud(Long txId) {...}

ADVANCED Saga Pattern

Distributed transactions without 2PC. Choreography (events) or Orchestration (central coordinator). Each step publishes success/failure events.

ADVANCED Event Sourcing + CQRS

Store all state changes as immutable events. CQRS: separate read/write models. Enables replay, audit trail, temporal queries.

❓ Java Developer Questions

DEV Java 17+ Stream API

// Parallel stream processing var stats = transactions.parallelStream() .filter(t -> t.getAmount().compareTo( BigDecimal.ZERO) > 0) .collect(Collectors.groupingBy( Transaction::getStatus, Collectors.summarizingDouble( t -> t.getAmount().doubleValue()) ));

DEV Spring Security JWT

@Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { return http .csrf(csrf -> csrf.disable()) .sessionManagement(s -> s.sessionCreationPolicy( SessionCreationPolicy.STATELESS)) .authorizeHttpRequests(auth -> auth .requestMatchers("/auth/**").permitAll() .anyRequest().authenticated()) .addFilterBefore(jwtFilter, ...) .build(); }
📊 Data Engineering Stack

BASIC ETL vs ELT

ETL

Extract → Transform (on server) → Load. Traditional, good for sensitive data.

ELT

Extract → Load (raw) → Transform (in DWH). Modern cloud approach with cloud data warehouses.

BASIC Data Formats

  • Parquet Columnar, great compression, fast analytics
  • Avro Row-based, schema evolution, streaming
  • Delta Lake ACID on data lake, time travel
  • Iceberg Table format for massive tables

ADVANCED Medallion Architecture

Bronze

Raw ingested data. No transformation. Append-only.

Silver

Cleaned, validated, joined. Business rules applied.

Gold

Aggregated, business-ready. Serving layer for BI/ML.

⚡ Apache Spark + Airflow
🔹 PySpark ETL Job
pythonfrom pyspark.sql import SparkSession from pyspark.sql import functions as F spark = SparkSession.builder \ .appName("FraudETL") \ .config("spark.sql.adaptive.enabled", "true") \ .getOrCreate() # Read raw from S3 df = spark.read.parquet("s3://bucket/raw/transactions/") # Transform clean = ( df .filter(F.col("amount") > 0) .withColumn("date", F.to_date("timestamp")) .withColumn("hour", F.hour("timestamp")) .dropDuplicates(["tx_id"]) ) # Aggregate (Gold layer) daily = clean.groupBy("date", "merchant_id") \ .agg(F.sum("amount").alias("daily_volume"), F.count("*").alias("tx_count")) # Write to Delta Lake (Silver) clean.write.format("delta") \ .mode("merge") \ .partitionBy("date") \ .save("s3://bucket/silver/transactions/")
🔹 Airflow DAG
pythonfrom airflow import DAG from airflow.operators.python import PythonOperator from airflow.providers.amazon.aws.operators.glue import GlueJobOperator from datetime import datetime, timedelta default_args = { 'retries': 2, 'retry_delay': timedelta(minutes=5), 'email_on_failure': True } with DAG( "fraud_etl_pipeline", schedule="@daily", start_date=datetime(2024, 1, 1), default_args=default_args, catchup=False ) as dag: ingest = GlueJobOperator( task_id="ingest_raw", job_name="raw-ingest" ) transform = PythonOperator( task_id="transform", python_callable=run_spark_job ) validate = PythonOperator( task_id="data_quality", python_callable=run_great_expectations ) ingest >> transform >> validate
🎬 Data Engineering Scenarios

Scenario: Late-Arriving Data Problem

Your daily Spark job calculates revenue per merchant. Occasionally, transactions arrive 2-3 days late. Your reports show wrong numbers. How to fix?

▶ Show Answer
1. Use event_time not processing_time for partitioning. 2. Implement watermarking in streaming: df.withWatermark("event_time", "3 days"). 3. For batch: use Delta Lake's MERGE into instead of overwrite — upsert late arrivals. 4. Reprocess partition when late data arrives using Airflow's backfill + catchup. 5. Add a "reporting cutoff" flag — freeze metrics for reporting after 5 days, note them as estimated before that.
λ Lambda Architecture Deep Dive
— Lambda Architecture (Nathan Marz) —
All Data Sources
(Events/Logs/DB)
BATCH LAYER
Spark / Hadoop
↓
Batch Views
(Recomputed daily)
SPEED LAYER
Kafka + Flink/Spark
↓
Real-time Views
(Last hours only)
SERVING LAYER
Merges Batch + Speed views
Query / Dashboard / API
⚡ Kappa vs Lambda

Lambda Architecture

  • Two paths: batch + streaming
  • Complex but handles reprocessing
  • Batch ensures correctness
  • Good for: fraud detection, reporting
  • Tools: Spark + Kafka + HBase

Kappa Architecture

  • Single streaming path only
  • Simpler, lower latency
  • Reprocess by replaying Kafka
  • Good for: real-time analytics
  • Tools: Kafka + Flink + Cassandra
🔄 Kafka + Flink Streaming
🔹 Kafka Producer (Python)
pythonfrom kafka import KafkaProducer import json producer = KafkaProducer( bootstrap_servers=['kafka:9092'], value_serializer=lambda v: json.dumps(v).encode() ) # Publish transaction event producer.send('transactions', { 'tx_id': 'T123', 'amount': 450.00, 'merchant': 'AMZN', 'timestamp': '2024-01-15T10:30:00Z' }) producer.flush()
🔹 Kafka Consumer with windowing
pythonfrom kafka import KafkaConsumer from collections import defaultdict from datetime import datetime, timedelta consumer = KafkaConsumer( 'transactions', bootstrap_servers=['kafka:9092'], auto_offset_reset='earliest', value_deserializer=lambda x: json.loads(x.decode()) ) # 5-min tumbling window aggregation window = defaultdict(lambda: {'count': 0, 'total': 0}) for msg in consumer: tx = msg.value key = tx['merchant'] window[key]['count'] += 1 window[key]['total'] += tx['amount'] # Alert if velocity exceeds threshold if window[key]['count'] > 100: alert(f"High velocity: {key}")
☁️ Public Cloud Architecture for AI
— Cloud AI/ML Reference Architecture —
Object-store data lake
→
Managed ETL
(jobs)
→
Managed ML
(Train)
→
Managed ML
Endpoint
Managed stream
(Streaming)
→
Serverless fn
(Trigger)
→
Managed LLM
(API)
→
API gateway
+ CDN
🔧 Cloud CLI — Entry Level Commands

Object storage commands

aws s3 cp data.csv s3://bucket/raw/
Upload a file to object storage
aws s3 sync ./local/ s3://bucket/data/
Sync a folder to object storage
aws s3 ls s3://bucket/ --recursive
List all objects

Managed ML CLI

aws sagemaker list-training-jobs
View all training jobs
aws sagemaker describe-endpoint --endpoint-name my-ep
Check endpoint status
aws sagemaker create-model --model-name fraud-v1 ...
Register model
💻 Managed LLM API — in Python
pythonimport boto3, json bedrock = boto3.client('bedrock-runtime', region_name='us-east-1') # Claude 3 via Bedrock response = bedrock.invoke_model( modelId='anthropic.claude-3-sonnet-20240229-v1:0', body=json.dumps({ "anthropic_version": "bedrock-2023-05-31", "max_tokens": 1024, "messages": [{"role": "user", "content": "Summarize this financial report..."}] }) ) result = json.loads(response['body'].read()) print(result['content'][0]['text']) # SageMaker endpoint invocation sm_runtime = boto3.client('sagemaker-runtime') sm_response = sm_runtime.invoke_endpoint( EndpointName='fraud-detection-endpoint', ContentType='application/json', Body=json.dumps({"features": [450.0, 2, 1, 0]}) ) prediction = json.loads(sm_response['Body'].read())
🎬 Cloud Scenario

Scenario: Design a Real-Time Fraud Detection System on a Public Cloud

You need to score 10,000 transactions/second for fraud with <50ms latency. Model is an XGBoost + LLM explanation. Design the cloud architecture.

▶ Show Answer
1. Managed data streams: ingest 10k TPS. 2. Serverless function (or stream analytics): feature extraction in real-time. 3. Managed ML endpoint with multi-model server + auto-scaling (target tracking on InvocationsPerInstance). 4. ElastiCache Redis: cache merchant profiles, avoid DB round-trips. 5. For LLM explanations: async call to a managed LLM API (non-blocking) — use a message queue to decouple. 6. Key-value store: store fraud flags with TTL. 7. Cloud monitoring + tracing: monitor P99 latency. 8. Use the ML platform's inference recommender to optimize instance type.
💰 BFS / Fintech Domains

BASIC Key BFS Concepts

AML

Anti-Money Laundering. Detect structuring, layering, smurfing patterns in transaction graphs.

KYC

Know Your Customer. Identity verification, document validation, risk scoring at onboarding.

PSD2 / Open Banking

EU regulation mandating banks expose APIs. Enables TPP access to account data.

ADVANCED Fraud Detection Patterns

Card Not Present

Online fraud. Behavioral biometrics + device fingerprinting + velocity checks.

Account Takeover

Stolen credentials. Anomaly detection on login location, device, time.

Synthetic Identity

Fake identities using real SSNs. Graph analysis to detect identity clusters.

ADVANCED Credit Risk Models

PD Model

Probability of Default. Logistic regression with bureau + behavioral features.

LGD

Loss Given Default. Recovery rates by collateral type.

CECL

Current Expected Credit Loss. IFRS 9 / FASB standard for lifetime loss provisioning.

🔗 Graph-Based Fraud Detection
🔹 NetworkX Transaction Graph
pythonimport networkx as nx import pandas as pd # Build transaction graph G = nx.DiGraph() for _, row in transactions.iterrows(): G.add_edge( row['sender'], row['receiver'], weight=row['amount'], timestamp=row['ts'] ) # Detect high centrality nodes (money mules) betweenness = nx.betweenness_centrality(G, weight='weight') suspects = {n: s for n, s in betweenness.items() if s > 0.5} # Detect cycles (round-tripping) cycles = list(nx.simple_cycles(G)) print(f"Suspicious cycles: {len(cycles)}")

DEV Real-Time Velocity Check

import redis r = redis.Redis() def check_velocity(card_id, amount): key = f"vel:{card_id}:1h" pipe = r.pipeline() pipe.incrbyfloat(key, amount) pipe.expire(key, 3600) total, _ = pipe.execute() if float(total) > 10000: return {"flag": True, "reason": "velocity_breach", "total_1h": float(total)} return {"flag": False}
🏛️ Project: AI-Powered Fraud Detection Platform
— Production Architecture (public cloud) —
Mobile / Web App
→
API Gateway
+ WAF
→
Spring Boot
Microservices
→
Kafka
Event Bus
Managed stream
(Streams)
→
Serverless fn
(Feature Extract)
→
Managed ML
(ML Scoring)
→
Managed LLM
(Explanation)
Object-store data lake
↔
Lakehouse
Delta tables
↔
Cloud
DWH
↔
MLflow
Registry
Managed
Vector DB
↔
RAG
Pipeline
↔
Grafana
+ Evidently
↔
Kubeflow
Pipelines
🏗️ Project: LLM-Powered Customer Service Platform
— LLM Platform Architecture —
User Query
→
Intent
Classifier
→
Guardrails
(NeMo)
→
LangGraph
Agent
Tool: SQL DB
Tool: Policy RAG
Tool: Calculator
Tool: Escalate
Frontier LLM
(managed API)
→
Output Validator
(Hallucination Check)
→
Response
+ Audit Log
📐 Design Patterns for AI Systems

Human-in-the-Loop

Route low-confidence predictions (<0.7) to human review. Collect labels → continuous retraining. Feedback loop closes the model-data gap.

Shadow Deployment

Run new model in parallel with production. Compare outputs without affecting users. Graduate to A/B then full cutover. Zero risk rollout.

Canary Release

Route 5% traffic to new model → monitor metrics → gradually increase. Rollback instantly if KPIs degrade. Blue-green variant for atomic switch.

Score: 0 / 10
Personal IIT Kanpur CTO-program learning notes shared by Viswa · not an official IIT Kanpur site · not linked to any employer or company · company and product names intentionally left out.