<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ahad-23</title>
    <description>The latest articles on DEV Community by Ahad-23 (@ahad23).</description>
    <link>https://dev.to/ahad23</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1302122%2Fdc93a51d-c4a3-4b02-8e92-a1e733a80d87.jpeg</url>
      <title>DEV Community: Ahad-23</title>
      <link>https://dev.to/ahad23</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ahad23"/>
    <language>en</language>
    <item>
      <title>Blazing Fast Fraud Detection with Kafka (&lt;500ms, No Kidding)</title>
      <dc:creator>Ahad-23</dc:creator>
      <pubDate>Sun, 13 Apr 2025 14:29:19 +0000</pubDate>
      <link>https://dev.to/ahad23/blazing-fast-fraud-detection-with-kafka-500ms-no-kidding-ldj</link>
      <guid>https://dev.to/ahad23/blazing-fast-fraud-detection-with-kafka-500ms-no-kidding-ldj</guid>
      <description>&lt;blockquote&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  💡 The Motivation
&lt;/h2&gt;

&lt;p&gt;Let’s be real. Nobody likes waiting in queues, especially not the ones where money’s on the line and fraudsters are already ten steps ahead. Batch-processing systems? Too slow. By the time they catch a fraud, your card’s already buying pizza in two continents.&lt;/p&gt;

&lt;p&gt;So I set out to build a real-time fraud detection pipeline, one that catches shady transactions faster than you can say “Kafka.”&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚙️ Tech Stack
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Apache Kafka – for scalable, real-time data streaming&lt;/li&gt;
&lt;li&gt;Python – The glue that holds the pipeline together&lt;/li&gt;
&lt;li&gt;Scikit-learn – for the K-Nearest Neighbors model&lt;/li&gt;
&lt;li&gt;Matplotlib &amp;amp; Seaborn – graphs for nerdy satisfaction&lt;/li&gt;
&lt;li&gt;Docker Compose – one command to bring the whole circus alive&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧠 The Architecture (Visually)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffht6m51vzvyfygoxor01.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffht6m51vzvyfygoxor01.png" width="800" height="1079"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🗂️ Project Structure
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ccfraud_kafka/
│
├── pipeline/
│   ├── producer.py            # Streams transaction data to Kafka
│   ├── feature_processor.py   # Scales and preprocesses features
│   ├── fraud_detector.py      # Runs the ML model and predicts fraud
│   └── alert_system.py        # Sends alerts + plots graphs
│
├── models/
│   ├── train_model.py         # Trains and evaluates KNN
│   ├── fraud_model.pkl        # Saved model
│   ├── time_scaler.pkl        # Time scaler
│   └── amount_scaler.pkl      # Amount scaler
│
├── ccprod.csv                 # Sample chunk of the credit card dataset
└── docker-compose.yml         # Container orchestration

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ⚙️ Pipeline Flow (TL;DR)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Producer&lt;/strong&gt; reads transaction rows from CSV and streams them into the transactions Kafka topic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Feature Processor&lt;/strong&gt; consumes from that topic and applies RobustScaler to Time and Amount.&lt;/p&gt;

&lt;p&gt;Fraud Detector loads a trained KNN model and evaluates fraud probability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Alert System&lt;/strong&gt; logs suspicious transactions with full timestamps and gives beautiful metrics and visualizations.&lt;/p&gt;

&lt;p&gt;Best part? Some alerts clocked in &lt;strong&gt;under 30 milliseconds end-to-end&lt;/strong&gt;! Take that, Flash.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Code Snippets You’ll Love
&lt;/h2&gt;

&lt;p&gt;🌀 Streaming Producer&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def _clean_transaction(self, transaction):
    clean_tx = {k: float(v) for k, v in transaction.items()
                if k not in ['Class']}
    clean_tx['transaction_id'] = str(uuid.uuid4())
    clean_tx['timestamp_received'] = datetime.utcnow().isoformat()
    return clean_tx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔬 Feature Processor&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def _scale_features(self, transaction):
    scaled = transaction.copy()
    scaled['Time'] = self.scalers['Time'].transform([[transaction['Time']]])[0][0]
    scaled['Amount'] = self.scalers['Amount'].transform([[transaction['Amount']]])[0][0]
    return scaled
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🤖 KNN Prediction&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;proba = self.model.predict_proba(features)[0][1]
if proba &amp;gt;= 0.8:
    # It’s a fraud, my dude!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🛠️ Deployment (Docker-ized AF)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3.8'
services:
  kafka:
    image: confluentinc/cp-kafka:7.0.1
  zookeeper:
    image: confluentinc/cp-zookeeper:7.0.1
  # microservices are launched manually (or add them later!)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🚀The Superheroes: Kafka Topics&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Create raw transactions topic
docker compose exec kafka kafka-topics --create --bootstrap-server kafka:9092 --topic transactions --partitions 3 --replication-factor 1 --config retention.ms=604800000

# Create processed transactions topic  
docker compose exec kafka kafka-topics --create --bootstrap-server kafka:9092 --topic processed_transactions --partitions 3 --replication-factor 1 --config retention.ms=604800000

# Create fraud predictions topic
docker compose exec kafka kafka-topics --create --bootstrap-server kafka:9092 --topic fraud_predictions --partitions 3 --replication-factor 1 --config retention.ms=2592000000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ✨ Output Sneak Peek
&lt;/h2&gt;

&lt;p&gt;🧠 Trained Model Metrics&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqs486vocjevql3vtlv7l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqs486vocjevql3vtlv7l.png" width="800" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;💸 Real-Time Fraud Alerts (Sample Logs)&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flim7j5cewcz783s5jdj3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flim7j5cewcz783s5jdj3.jpg" alt="Image description" width="611" height="244"&gt;&lt;/a&gt;&lt;br&gt;
→ End-to-end latency: ~30ms&lt;br&gt;
→ Fast enough to warn Batman before Joker hits send.&lt;/p&gt;

&lt;p&gt;📊 Visualizations (via alert_system.py)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbngemn9qiiy7hjg3c9sm.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbngemn9qiiy7hjg3c9sm.jpg" alt="Kafka Throughput (Transactions/minute)" width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frxnh4rhd71zuzwvbysek.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frxnh4rhd71zuzwvbysek.jpg" alt="Fraud Alerts Per Minute" width="800" height="337"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft6d313bn5xr83lou39l1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft6d313bn5xr83lou39l1.jpg" alt="Fraud vs Legit Distribution" width="640" height="628"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 Results Worth Flexing
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Minimum Latency: 30ms 🚀&lt;/li&gt;
&lt;li&gt;Average Inference Time: Sub-500ms&lt;/li&gt;
&lt;li&gt;Peak Throughput: 1200 tx/min&lt;/li&gt;
&lt;li&gt;Accuracy: 93%&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Built for speed, precision, and modular deployment.&lt;/p&gt;




&lt;h2&gt;
  
  
  💡 Future Scope
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Add Prometheus + Grafana for robust observability&lt;/li&gt;
&lt;li&gt;Upgrade to model versioning with MLFlow&lt;/li&gt;
&lt;li&gt;Shift to Spark Streaming or Flink if horizontal scaling is required&lt;/li&gt;
&lt;li&gt;Build a pipeline with the help of TARS and a conveniently located wormhole?(I need help)&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv42u2auk18fad26464vx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv42u2auk18fad26464vx.jpg" width="800" height="617"&gt;&lt;/a&gt;&lt;br&gt;
“The path of the fraudster is beset on all sides by the Kafka-powered processor and the righteous model...”&lt;br&gt;
– Not Jules. But let’s pretend.&lt;/p&gt;

&lt;p&gt;If this sparked your curiosity or made you laugh (even a little), you know the drill.&lt;br&gt;
Have questions? Ping me. I don’t bite (unless you're a fraudulent transaction). 💳💥&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>kafka</category>
      <category>datastreaming</category>
      <category>devops</category>
    </item>
    <item>
      <title>If to be or not to be is the question, ternary operator is the answer</title>
      <dc:creator>Ahad-23</dc:creator>
      <pubDate>Sat, 22 Jun 2024 16:18:13 +0000</pubDate>
      <link>https://dev.to/ahad23/if-to-be-or-not-to-be-is-the-question-ternary-operator-is-the-answer-1a10</link>
      <guid>https://dev.to/ahad23/if-to-be-or-not-to-be-is-the-question-ternary-operator-is-the-answer-1a10</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for &lt;a href="https://dev.to/challenges/cs"&gt;DEV Computer Science Challenge v24.06.12: One Byte Explainer&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Explainer
&lt;/h2&gt;

&lt;p&gt;Do I jump or duck? If the obstacle is high, jump, if it's low, duck. You need a quick decision. That's what the ternary operator does. Instead of pausing to think, it quickly chooses between two actions based on a condition.&lt;/p&gt;

&lt;p&gt;Also huge shoutout to my team member &lt;a class="mentioned-user" href="https://dev.to/vedangit"&gt;@vedangit&lt;/a&gt; !!&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>cschallenge</category>
      <category>computerscience</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Code Checkpoint: Memoisation and its magic</title>
      <dc:creator>Ahad-23</dc:creator>
      <pubDate>Sat, 22 Jun 2024 16:14:31 +0000</pubDate>
      <link>https://dev.to/ahad23/code-checkpoint-memoisation-and-its-magic-13me</link>
      <guid>https://dev.to/ahad23/code-checkpoint-memoisation-and-its-magic-13me</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for &lt;a href="https://dev.to/challenges/cs"&gt;DEV Computer Science Challenge v24.06.12: One Byte Explainer&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Explainer
&lt;/h2&gt;

&lt;p&gt;Memoization stores the results of expensive operations and returns them quickly when needed, saving time and effort. Think of a video game save point! Instead of replaying the same level every time you lose, you save your progress. Don't hate your cache!&lt;/p&gt;

&lt;p&gt;Also huge shoutout to my team member &lt;a class="mentioned-user" href="https://dev.to/vedangit"&gt;@vedangit&lt;/a&gt; !!&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>cschallenge</category>
      <category>computerscience</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Computer Science under 125 characters.</title>
      <dc:creator>Ahad-23</dc:creator>
      <pubDate>Sat, 22 Jun 2024 16:10:30 +0000</pubDate>
      <link>https://dev.to/ahad23/computer-science-under-125-characters-52fd</link>
      <guid>https://dev.to/ahad23/computer-science-under-125-characters-52fd</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for &lt;a href="https://dev.to/challenges/cs"&gt;DEV Computer Science Challenge v24.06.12: One Byte Explainer&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Explainer
&lt;/h2&gt;

&lt;p&gt;Assigning multiple complex tasks to metals, plastics,0's,1's, and electricity because we were too lazy to do it on pen and paper.&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional Context
&lt;/h2&gt;

&lt;p&gt;We saw the gap of no one explaining the title of the challenge and ended up doing something raw.&lt;/p&gt;

&lt;h2&gt;
  
  
  Team Submissions:
&lt;/h2&gt;

&lt;p&gt;Also a huge shoutout to my team member &lt;a class="mentioned-user" href="https://dev.to/vedangit"&gt;@vedangit&lt;/a&gt; !!&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>cschallenge</category>
      <category>computerscience</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
