<?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>Forem: Shushant Rishav</title>
    <description>The latest articles on Forem by Shushant Rishav (@shushantrishav).</description>
    <link>https://forem.com/shushantrishav</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%2F491953%2Fb7dae95d-a135-4f3e-8bcc-93c8547ea35f.png</url>
      <title>Forem: Shushant Rishav</title>
      <link>https://forem.com/shushantrishav</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/shushantrishav"/>
    <language>en</language>
    <item>
      <title>Building an AI Assistant That Actually Understands Company Policy</title>
      <dc:creator>Shushant Rishav</dc:creator>
      <pubDate>Wed, 24 Dec 2025 12:00:36 +0000</pubDate>
      <link>https://forem.com/shushantrishav/stride-assistant-intelligent-policy-aware-complaint-resolution-system-25e1</link>
      <guid>https://forem.com/shushantrishav/stride-assistant-intelligent-policy-aware-complaint-resolution-system-25e1</guid>
      <description>&lt;p&gt;Managing customer complaints in footwear retail is deceptively complex. Orders, warranty windows, product defects, inventory constraints, and outlet-specific rules intersect, creating a decision space where &lt;strong&gt;speed, accuracy, and consistency&lt;/strong&gt; are all hard requirements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STRIDE Assistant&lt;/strong&gt; is an AI-driven complaint resolution system designed to automate this process while ensuring &lt;strong&gt;strict policy compliance, accountability, and human oversight&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This document explains &lt;em&gt;why&lt;/em&gt; STRIDE Assistant exists, &lt;em&gt;how&lt;/em&gt; it works, and &lt;em&gt;how AI can be combined with deterministic policy logic&lt;/em&gt; to deliver reliable and auditable decisions in production systems.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Why STRIDE Assistant Exists
&lt;/h2&gt;

&lt;p&gt;A customer messages support:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“My shoe tore 4 days after purchase.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Without automation, a staff member must manually:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Verify the order and purchase date&lt;/li&gt;
&lt;li&gt;Check warranty eligibility&lt;/li&gt;
&lt;li&gt;Interpret company policy&lt;/li&gt;
&lt;li&gt;Confirm inventory availability&lt;/li&gt;
&lt;li&gt;Decide between return, replacement, repair, or rejection&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Multiply this by &lt;strong&gt;hundreds of tickets per day&lt;/strong&gt;, and the process becomes slow, inconsistent, and error-prone.&lt;/p&gt;

&lt;p&gt;STRIDE Assistant addresses this by combining:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AI-driven semantic analysis&lt;/strong&gt; to understand customer complaints&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deterministic policy enforcement&lt;/strong&gt; grounded in business rules&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Human-in-the-loop escalation&lt;/strong&gt; for ambiguous or high-risk cases&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Immutable audit logging&lt;/strong&gt; for compliance and traceability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result is &lt;strong&gt;fast, accurate, and accountable complaint handling&lt;/strong&gt;—without over-reliance on generative AI.&lt;/p&gt;




&lt;h2&gt;
  
  
  Architecture Overview
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Customer Message
        |
Session Verification (Order + Phone + JWT)
        |
Semantic Analysis (Intent Detection)
        |
Clarification Step (if required)
        |
Policy Retrieval
        |
Decision Engine (Policy + Order + Inventory)
        |
+-----------------------------+
| FINAL DECISION / TICKET     |
+-----------------------------+
        |
     OR Manual Review → Ticket Created
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Tools and Models Used
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;Tool / Model&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Semantic Analysis &amp;amp; RAG&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;LLaMA 3 (8B) via Ollama&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Intent detection and generation of professional, policy-safe customer responses&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Embeddings&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;SentenceTransformer (all-MiniLM-L6-v2)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Converts complaints and policy chunks into vectors for semantic retrieval&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;API Layer&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;FastAPI&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Secure endpoints for customers, staff, and admins (JWT-based)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Database&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;PostgreSQL&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Stores orders, tickets, staff actions, and audit logs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cache&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Redis&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Low-latency access to prefetched order data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Logging&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Structured Python logging&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Captures system events, AI decisions, and staff actions&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Why this setup?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;LLaMA 3 (8B)&lt;/strong&gt; hosted via &lt;strong&gt;Ollama&lt;/strong&gt; enables fully local, private inference with strong instruction-following capability.&lt;/li&gt;
&lt;li&gt;Embeddings enable deterministic policy retrieval without relying on probabilistic generation.&lt;/li&gt;
&lt;li&gt;The system explicitly separates &lt;em&gt;language understanding&lt;/em&gt; from &lt;em&gt;decision authority&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Dual-Logic Workflow
&lt;/h2&gt;

&lt;p&gt;STRIDE Assistant deliberately separates &lt;strong&gt;reasoning from enforcement&lt;/strong&gt; using two complementary logic layers:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Policy Retriever (RAG Layer)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Interprets the complaint semantically&lt;/li&gt;
&lt;li&gt;Retrieves relevant policy rules&lt;/li&gt;
&lt;li&gt;Produces an initial &lt;em&gt;suggested action&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Decision Engine (Deterministic Layer)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Validates the suggestion against:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Order history&lt;/li&gt;
&lt;li&gt;Warranty duration&lt;/li&gt;
&lt;li&gt;Product category&lt;/li&gt;
&lt;li&gt;Inventory availability&lt;/li&gt;
&lt;li&gt;Past customer interactions&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Produces an authoritative outcome that may:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Approve&lt;/li&gt;
&lt;li&gt;Suggest repair&lt;/li&gt;
&lt;li&gt;Require inspection&lt;/li&gt;
&lt;li&gt;Reject the complaint&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Complaints are rejected when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Warranty is expired&lt;/li&gt;
&lt;li&gt;Damage indicates misuse&lt;/li&gt;
&lt;li&gt;Repeated requests violate policy limits&lt;/li&gt;
&lt;li&gt;Required order data is missing&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  RAG Orchestration
&lt;/h2&gt;

&lt;p&gt;The RAG pipeline coordinates both logic layers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Aggregates signals across multiple turns&lt;/li&gt;
&lt;li&gt;Requests clarification when signals conflict&lt;/li&gt;
&lt;li&gt;Escalates ambiguous cases to inspection&lt;/li&gt;
&lt;li&gt;Produces a final ticket with &lt;strong&gt;explicit reasoning notes&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This prevents hallucinated decisions and ensures traceability.&lt;/p&gt;




&lt;h2&gt;
  
  
  Code Snippet: Combining Logic Outputs
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;policy_signal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;retriever&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_policy_signal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;decision_signal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;make_decision&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;user_text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;inventory_available&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;signals&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;policy_signal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;decision_signal&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;final_ticket&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;resolve_final_ticket&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;signals&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every ticket is generated only after &lt;strong&gt;policy compliance, historical context, and system constraints&lt;/strong&gt; are validated.&lt;/p&gt;




&lt;h2&gt;
  
  
  Authentication &amp;amp; Access Control
&lt;/h2&gt;

&lt;p&gt;STRIDE Assistant uses &lt;strong&gt;JWT-based authentication&lt;/strong&gt; across all actors:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;User&lt;/th&gt;
&lt;th&gt;Credentials&lt;/th&gt;
&lt;th&gt;Access&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Customer&lt;/td&gt;
&lt;td&gt;order_id + phone&lt;/td&gt;
&lt;td&gt;Submit complaints, track status&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Staff&lt;/td&gt;
&lt;td&gt;user_id + password&lt;/td&gt;
&lt;td&gt;Act on tickets, add remarks&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Admin&lt;/td&gt;
&lt;td&gt;role-based credentials&lt;/td&gt;
&lt;td&gt;Audit logs, system oversight&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Benefits&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stateless and scalable&lt;/li&gt;
&lt;li&gt;Role-based enforcement&lt;/li&gt;
&lt;li&gt;Every action is attributable and logged&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Staff &amp;amp; Admin Logging
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Staff actions (approve, reject, escalate, close, note delays) are recorded securely&lt;/li&gt;
&lt;li&gt;Logs are &lt;strong&gt;immutable&lt;/strong&gt; and stored in &lt;code&gt;staff_action_log&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Admins have &lt;strong&gt;read-only visibility&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;log_staff_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;staff&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ticket_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;remarks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures &lt;strong&gt;full accountability for both AI and human decisions&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Example End-to-End Workflow
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Customer: &lt;em&gt;“My shoe tore after 4 days.”&lt;/em&gt; → Policy retriever suggests &lt;code&gt;REPLACEMENT&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Decision engine validates eligibility&lt;/li&gt;
&lt;li&gt;Clarification requested if needed&lt;/li&gt;
&lt;li&gt;Signals are aggregated&lt;/li&gt;
&lt;li&gt;Final ticket is resolved as one of:
&lt;code&gt;RETURN&lt;/code&gt;, &lt;code&gt;REPLACEMENT&lt;/code&gt;, &lt;code&gt;REPAIR&lt;/code&gt;, &lt;code&gt;PAID_REPAIR&lt;/code&gt;, &lt;code&gt;INSPECTION&lt;/code&gt;, or &lt;code&gt;REJECT&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Inventory constraints are checked&lt;/li&gt;
&lt;li&gt;Ambiguous cases escalate to inspection&lt;/li&gt;
&lt;li&gt;Every ticket includes a &lt;strong&gt;system-generated reasoning note&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Staff actions are logged immutably&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Production Considerations
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Thread-safe LLM access via Ollama&lt;/li&gt;
&lt;li&gt;Transaction-safe ticket creation&lt;/li&gt;
&lt;li&gt;Redis-based order prefetching&lt;/li&gt;
&lt;li&gt;Role-based access control&lt;/li&gt;
&lt;li&gt;Structured logging for observability&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Future Improvements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Multi-model ensembles for higher signal accuracy&lt;/li&gt;
&lt;li&gt;Analytics dashboards for staff performance&lt;/li&gt;
&lt;li&gt;Versioned policy ingestion&lt;/li&gt;
&lt;li&gt;Predictive ticket prioritization&lt;/li&gt;
&lt;li&gt;GPU-backed inference for scale&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;STRIDE Assistant&lt;/strong&gt; demonstrates how AI can &lt;strong&gt;augment human decision-making without replacing it&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;By combining:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Semantic understanding via LLaMA 3&lt;/li&gt;
&lt;li&gt;Deterministic policy enforcement&lt;/li&gt;
&lt;li&gt;Structured escalation&lt;/li&gt;
&lt;li&gt;Immutable audit logs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;STRIDE delivers &lt;strong&gt;explainable, compliant, and production-safe complaint resolution,&lt;/strong&gt; a blueprint for enterprise AI systems built to operate under real-world constraints.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Author:&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/shushantrishav/" rel="noopener noreferrer"&gt;Shushant Rishav&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Repository:&lt;/strong&gt; &lt;a href="https://github.com/shushantrishav/STRIDE_Assistant" rel="noopener noreferrer"&gt;STRIDE_Assistant_DEMO&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>productivity</category>
      <category>rag</category>
    </item>
    <item>
      <title>Drowning in News? Meet NewsSelect: Your AI-Powered Summarizer</title>
      <dc:creator>Shushant Rishav</dc:creator>
      <pubDate>Sun, 27 Jul 2025 16:29:21 +0000</pubDate>
      <link>https://forem.com/shushantrishav/drowning-in-news-meet-newsselect-your-ai-powered-summarizer-3o86</link>
      <guid>https://forem.com/shushantrishav/drowning-in-news-meet-newsselect-your-ai-powered-summarizer-3o86</guid>
      <description>&lt;p&gt;In our hyper-connected digital age, keeping up with the news feels less like staying informed and more like trying to drink from a firehose. The sheer volume of articles across countless sources leads to an overwhelming sense of information overload. Manually sifting through lengthy pieces to grasp the core message is not just inefficient; it's practically impossible for most people.&lt;/p&gt;

&lt;p&gt;This challenge inspired NewsSelect – an end-to-end, AI-powered web application designed to cut through the noise. NewsSelect aims to automatically fetch live news articles, distill them into concise, abstractive summaries using a sophisticated deep learning model, and present them through a clean, responsive web interface. It’s about getting to the essence of the news, faster.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Brains Behind the Summaries: Our Technology Stack
&lt;/h2&gt;

&lt;p&gt;Building an intelligent summarization system that works in real-time requires a thoughtful selection of technologies. Here’s what powers NewsSelect and why each component was chosen:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Python 3.x&lt;/strong&gt;: For both machine learning and backend development due to its mature ecosystem.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TensorFlow 2.x / Keras&lt;/strong&gt;: Enables building Sequence-to-Sequence (Seq2Seq) models with attention mechanisms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pandas / NumPy&lt;/strong&gt;: For preprocessing and numerical operations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Matplotlib&lt;/strong&gt;: For visualizing training metrics.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Contractions&lt;/strong&gt;: Helps normalize text data by expanding contractions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Django&lt;/strong&gt;: Backend framework used for serving the ML model and scraping news articles.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;BeautifulSoup / Requests&lt;/strong&gt;: Handles web scraping of live news.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HTML/CSS/JS with Bootstrap&lt;/strong&gt;: For building a responsive and clean user interface.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TPU Runtime (Colab/Kaggle)&lt;/strong&gt;: Dramatically speeds up training time for the deep learning model.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  NewsSelect's Blueprint: High-Level Design
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+-----------------+         +----------------+        +-------------------+
|    Preprocess    |  ---&amp;gt;   |    Encoder      |  ---&amp;gt;  |   Attention Layer  |
|   Clean + Token  |         |   (Bi-LSTM)     |        | (Context Vector)   |
+-----------------+         +----------------+        +-------------------+
                                                                |
                                                                V
                                                       +----------------+
                                                       |    Decoder      |
                                                       |   (LSTM + FC)   |
                                                       +----------------+
                                                                |
                                                                V
                                                       +----------------+
                                                       |    Summary       |
                                                       +----------------+
                                                                |
                                                                V
                                                       +----------------+
                                                       |  Django Backend  |
                                                       | (Model Serving &amp;amp; |
                                                       |   Web Scraping)  |
                                                       +----------------+
                                                                |
                                                                V
                                                       +----------------+
                                                       |   Frontend UI    |
                                                       | (Responsive App) |
                                                       +----------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Workflow
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Data Preparation&lt;/strong&gt;: Preprocess 42,000+ news articles from Kaggle (news_summary.csv).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Text Normalization&lt;/strong&gt;: Clean, normalize, and tokenize input text.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Model Training&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Encoder&lt;/strong&gt;: Bi-LSTM to capture input context.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Attention Layer&lt;/strong&gt;: Guides decoder by focusing on relevant parts.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Decoder&lt;/strong&gt;: LSTM + Fully Connected layer to generate summaries.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Training Performance&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;100 epochs in 180 minutes on Kaggle TPU.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Final Training Accuracy: 89.62%&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validation Accuracy: 74.08%&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;AUC Score: 0.79&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;F1 Score: 0.73&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Deployment&lt;/strong&gt;: Model served via Django REST APIs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Live News Integration&lt;/strong&gt;: Scrapes and summarizes latest news dynamically.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frontend UI&lt;/strong&gt;: Clean, mobile-responsive interface using Bootstrap.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Key Features of NewsSelect
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Real-Time AI Summarization&lt;/strong&gt;: Fetches and summarizes live news articles.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Abstractive Summarization&lt;/strong&gt;: Generates new sentences rather than extracting existing ones.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Custom Preprocessing&lt;/strong&gt;: Includes text cleaning and contraction handling.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RESTful Django Backend&lt;/strong&gt;: Secure API access to the summarization engine.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Live Scraping Integration&lt;/strong&gt;: Dynamically updates news feed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Responsive UI&lt;/strong&gt;: Optimized for both desktop and mobile.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Accelerated Model Training&lt;/strong&gt;: Uses TPUs for efficient training.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Performance Metrics
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Final Training Accuracy&lt;/strong&gt;: 89.62%&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Final Validation Accuracy&lt;/strong&gt;: 74.08%&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Final Training Loss&lt;/strong&gt;: 0.7421&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Final Validation Loss&lt;/strong&gt;: 2.0726&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AUC Score&lt;/strong&gt;: 0.79&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;F1 Score&lt;/strong&gt;: 0.73&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Training was efficient and stable across epochs, validated by plots of Accuracy vs Epoch and Loss vs Epoch.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started Locally
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python 3.8+&lt;/li&gt;
&lt;li&gt;Django&lt;/li&gt;
&lt;li&gt;TensorFlow 2.x&lt;/li&gt;
&lt;li&gt;BeautifulSoup4&lt;/li&gt;
&lt;li&gt;Requests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Steps&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/shushantrishav/NewsSelect.git
&lt;span class="nb"&gt;cd &lt;/span&gt;NewsSelect
pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt
python manage.py runserver
&lt;span class="c"&gt;# Then open frontend/index.html in browser&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What's Next? Future Enhancements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Multilingual Summarization&lt;/strong&gt;: Support summaries in multiple languages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloud Deployment&lt;/strong&gt;: Serve model via GCP/AWS for scalability.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mobile PWA&lt;/strong&gt;: Build a Progressive Web App version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real-Time Analytics&lt;/strong&gt;: Track article popularity, summary usage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;More Categories&lt;/strong&gt;: Expand beyond general news (e.g., finance, health).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Experience NewsSelect Today
&lt;/h2&gt;

&lt;p&gt;NewsSelect stands as a powerful example of using deep learning and clean UI design to fight information overload. With real-time AI-generated summaries, users can now stay informed efficiently.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔍 Explore the Project
&lt;/h2&gt;

&lt;p&gt;🧪 Live Demo: &lt;a href="https://shushantrishav.pythonanywhere.com/news/" rel="noopener noreferrer"&gt;NewsSelect&lt;/a&gt;&lt;br&gt;
💻 GitHub Repo: &lt;a href="https://github.com/shushantrishav/NewsSelect" rel="noopener noreferrer"&gt;NewsSelect&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Thanks for reading!&lt;/p&gt;

&lt;p&gt;👉 Like this project? Drop a star on &lt;a href="https://github.com/shushantrishav/NewsSelect" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;br&gt;
💬 Have questions or feedback? Let’s connect in the comments!&lt;/p&gt;

&lt;p&gt;Feel free to contribute or ask questions!&lt;/p&gt;

</description>
      <category>nlp</category>
      <category>machinelearning</category>
      <category>python</category>
      <category>lstm</category>
    </item>
    <item>
      <title>Revolutionizing Retail: A Blockchain-Powered Loyalty and Transaction System with FastAPI + Ethereum</title>
      <dc:creator>Shushant Rishav</dc:creator>
      <pubDate>Sun, 27 Jul 2025 16:08:20 +0000</pubDate>
      <link>https://forem.com/shushantrishav/revolutionizing-retail-a-blockchain-powered-loyalty-and-transaction-system-with-fastapi-ethereum-2i72</link>
      <guid>https://forem.com/shushantrishav/revolutionizing-retail-a-blockchain-powered-loyalty-and-transaction-system-with-fastapi-ethereum-2i72</guid>
      <description>&lt;p&gt;Traditional retail systems, despite decades of evolution, continue to struggle with fundamental structural inefficiencies. Loyalty programs remain siloed, transaction histories are opaque, and centralized databases introduce single points of failure that are vulnerable to fraud, data corruption, and administrative manipulation. At scale, these systems also suffer from high operational costs and limited interoperability across brands.&lt;/p&gt;

&lt;p&gt;To address these challenges, I built a &lt;strong&gt;Hybrid Retail Blockchain System&lt;/strong&gt;  an architecture that combines the &lt;strong&gt;speed and reliability of traditional databases&lt;/strong&gt; with the &lt;strong&gt;immutability and auditability of blockchain&lt;/strong&gt;, without sacrificing real-time user experience.&lt;/p&gt;

&lt;p&gt;Rather than forcing retail transactions directly on-chain (which is impractical due to latency and gas costs), this system adopts a &lt;strong&gt;database-first, blockchain-anchored design&lt;/strong&gt; suitable for real-world commerce.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Blockchain and Why &lt;em&gt;Hybrid&lt;/em&gt;?
&lt;/h2&gt;

&lt;p&gt;Blockchains are powerful, but they are not designed for sub-second transactional workloads. Public networks like Ethereum introduce unavoidable latency due to block times and probabilistic finality.&lt;/p&gt;

&lt;p&gt;Retail systems, on the other hand, require:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Low-latency DB-first confirmation&lt;/li&gt;
&lt;li&gt;Deterministic correctness&lt;/li&gt;
&lt;li&gt;High throughput during peak hours&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This creates the &lt;strong&gt;finality–latency tradeoff&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Solution: Dual-State Architecture
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;PostgreSQL&lt;/strong&gt; serves as the &lt;em&gt;hot state&lt;/em&gt; for real-time transactions&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ethereum&lt;/strong&gt; acts as an immutable &lt;em&gt;audit ledger&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;The system is DB-first, the API returns only after PostgreSQL commit, and can optionally write to Ethereum during the same request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This preserves the UX guarantees of traditional systems while gaining the trust and transparency benefits of Web3.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Blockchain Brings to Retail (When Used Correctly)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Immutability:&lt;/strong&gt; Transaction records are cryptographically anchored and tamper-proof&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transparency:&lt;/strong&gt; Transaction proofs are verifiable on-chain when enabled, loyalty balances are stored off-chain in PostgreSQL with deterministic rules.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security:&lt;/strong&gt; No single point of failure for historical data&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interoperability:&lt;/strong&gt; Enables future cross-brand loyalty ecosystems&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Blockchain becomes a &lt;strong&gt;trust layer&lt;/strong&gt;, not a performance bottleneck.&lt;/p&gt;




&lt;h2&gt;
  
  
  Technology Stack
&lt;/h2&gt;

&lt;p&gt;The system is designed for correctness, scalability, and operational resilience:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;FastAPI&lt;/strong&gt; – Async Python backend with high-throughput request handling&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PostgreSQL&lt;/strong&gt; – ACID-compliant transactional datastore&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Redis&lt;/strong&gt; –  Idempotency middleware cache&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Solidity&lt;/strong&gt; – Smart contracts for immutable transaction anchoring&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ethereum / Ganache / Sepolia&lt;/strong&gt; – Development and test networks&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Web3.py&lt;/strong&gt; – Blockchain interaction and transaction signing&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;solcx&lt;/strong&gt; – Dynamic Solidity compilation&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Docker&lt;/strong&gt; – Environment-consistent deployment&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  High-Level System Architecture
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[POS / Frontend]
        |
        |  POST /transactions (Idempotency-Key)
        v
[FastAPI Backend]
        |
        +-- Redis (Idempotency Lock)
        |
        +-- PostgreSQL (ACID Transaction)
        |       - Create Sale Record
        |       - Update Loyalty Balance
        |
        +-- Blockchain Anchor (Async)
                - Convert INR → Wei (cached + emergency fallback)
                - Sign &amp;amp; Broadcast TX
                - Wait for receipt (current implementation)
                - Persist txId + txHash back into PostgreSQL

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

&lt;/div&gt;



&lt;p&gt;The customer receives an immediate response after the PostgreSQL write. When blockchain is enabled, the endpoint currently waits for the on-chain receipt before responding.&lt;/p&gt;




&lt;h2&gt;
  
  
  Core Backend Services
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Transaction Manager&lt;/strong&gt;&lt;br&gt;
Ensures atomic DB writes and maps internal transaction IDs to blockchain hashes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Idempotency Guard (Redis-based)&lt;/strong&gt;&lt;br&gt;
Prevents duplicate charges during retries, crashes, or network failures.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Loyalty Engine&lt;/strong&gt;&lt;br&gt;
Deterministic, precision-safe loyalty calculation using Decimal + ROUND_CEILING, implemented in PostgreSQL-backed logic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Blockchain Anchor Service&lt;/strong&gt;&lt;br&gt;
Posts transaction metadata to Ethereum when enabled, the current implementation waits for the receipt before returning.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Currency Conversion Module&lt;/strong&gt;&lt;br&gt;
Multi-tier fallback (cached ≤ 60s → live CoinGecko refresh → emergency fixed rate) to ensure uptime under API failures.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;⚡ Low-latency DB-first confirmation&lt;/li&gt;
&lt;li&gt;🔒 Retry-safe execution via Redis-backed idempotency middleware&lt;/li&gt;
&lt;li&gt;📜 Immutable blockchain audit trail&lt;/li&gt;
&lt;li&gt;🎯 Deterministic loyalty rewards&lt;/li&gt;
&lt;li&gt;🔁 Retry-safe APIs&lt;/li&gt;
&lt;li&gt;📊 Swagger &amp;amp; ReDoc auto-generated documentation&lt;/li&gt;
&lt;li&gt;🐳 Dockerized, reproducible setup&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Example API Usage
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Record a Transaction
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;POST&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;/transactions/record&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;(Idempotency-Key)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"orderid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ORD-ABC123"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"customeraddress"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0x..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"amountINR"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;1500.75&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

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

&lt;/div&gt;



&lt;p&gt;The response is immediate after the PostgreSQL write, when blockchain is enabled, the API currently waits for the on-chain receipt before responding.&lt;/p&gt;




&lt;h2&gt;
  
  
  Local Development Setup
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Python 3.8+&lt;/li&gt;
&lt;li&gt;Docker &amp;amp; Docker Compose&lt;/li&gt;
&lt;li&gt;Ganache CLI&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Run Locally
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/shushantrishav/Blockchain_In_Retail.git
&lt;span class="nb"&gt;cd &lt;/span&gt;Blockchain_In_Retail

&lt;span class="nb"&gt;cp&lt;/span&gt; .env.example .env
pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt

npx ganache-cli &lt;span class="nt"&gt;-d&lt;/span&gt;
uvicorn app.main:app &lt;span class="nt"&gt;--reload&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Deployment Notes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Switch to Sepolia / Mainnet via Infura or Alchemy&lt;/li&gt;
&lt;li&gt;Persist deployed contract addresses&lt;/li&gt;
&lt;li&gt;Secure private keys via environment variables or secret managers&lt;/li&gt;
&lt;li&gt;Never hardcode credentials&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Lessons Learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Blockchain should &lt;strong&gt;anchor&lt;/strong&gt;, not block, retail workflows&lt;/li&gt;
&lt;li&gt;Idempotency is non-negotiable for financial systems&lt;/li&gt;
&lt;li&gt;Floating-point math has no place in money or rewards&lt;/li&gt;
&lt;li&gt;Async design is the difference between demos and production systems&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Business Impact
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;📈 Increased customer trust via transparent loyalty systems&lt;/li&gt;
&lt;li&gt;🔁 Higher retention due to predictable rewards&lt;/li&gt;
&lt;li&gt;🤝 Foundation for cross-brand loyalty partnerships&lt;/li&gt;
&lt;li&gt;🛡️ Auditability without operational slowdown&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Roadmap
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Zero-Knowledge Proofs for private loyalty validation&lt;/li&gt;
&lt;li&gt;L2 batching with Merkle roots (99% gas reduction)&lt;/li&gt;
&lt;li&gt;WalletConnect &amp;amp; MetaMask integration&lt;/li&gt;
&lt;li&gt;Admin analytics dashboard&lt;/li&gt;
&lt;li&gt;Multi-chain support (Polygon, Avalanche)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;This project demonstrates how &lt;strong&gt;Web2 reliability and Web3 trust&lt;/strong&gt; can coexist in real-world systems. By respecting the constraints of both domains, we can build retail infrastructure that is fast, transparent, and future-proof.&lt;/p&gt;

&lt;p&gt;🔍 &lt;strong&gt;Project&lt;/strong&gt;: &lt;a href="https://github.com/shushantrishav/Blockchain_In_Retail" rel="noopener noreferrer"&gt;https://github.com/shushantrishav/Blockchain_In_Retail&lt;/a&gt;&lt;br&gt;
🧪 &lt;strong&gt;Live Demo&lt;/strong&gt;: &lt;a href="https://block-cart.vercel.app" rel="noopener noreferrer"&gt;https://block-cart.vercel.app&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;⭐ If you found this useful, consider starring the repo or contributing!&lt;/p&gt;

</description>
      <category>python</category>
      <category>fastapi</category>
      <category>blockchain</category>
      <category>docker</category>
    </item>
    <item>
      <title>From Long URLs to Lightning Fast Links: A Go-Powered Shortener Explained</title>
      <dc:creator>Shushant Rishav</dc:creator>
      <pubDate>Sun, 27 Jul 2025 15:56:49 +0000</pubDate>
      <link>https://forem.com/shushantrishav/from-long-urls-to-lightning-fast-links-a-go-powered-shortener-explained-4jln</link>
      <guid>https://forem.com/shushantrishav/from-long-urls-to-lightning-fast-links-a-go-powered-shortener-explained-4jln</guid>
      <description>&lt;p&gt;In today's fast-paced digital world, long and complicated URLs can be a real headache. They're difficult to share, hard to remember, and often look messy in print or on social media. This common problem led me to build the Go Distributed &amp;amp; Scalable Link Shortener API – a service designed to transform those unwieldy links into short, memorable, and trackable ones, all while ensuring speed, security, and scalability.&lt;/p&gt;

&lt;p&gt;This project isn't just about shortening links; it's about providing a reliable, high-performance API with essential features like automatic expiration, robust validation, and intelligent rate limiting to prevent misuse.&lt;/p&gt;

&lt;p&gt;Let's dive into how it's built and why these choices were made.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Powerhouse Behind the Links: Our Technology Stack
&lt;/h2&gt;

&lt;p&gt;Choosing the right tools is crucial for any scalable application. Here's what powers our link shortener and the rationale behind each choice:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Go (Golang):&lt;/strong&gt; Go's strengths in concurrency management, rapid compilation, static typing, and performance make it ideal for high-concurrency services. Its built-in HTTP server is fast and reliable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Redis:&lt;/strong&gt; Used as the primary datastore. Its in-memory design ensures fast read/write, and TTL (Time-To-Live) simplifies auto-expiration. Atomic operations make it great for rate limiting.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Docker:&lt;/strong&gt; Provides containerized environments that ensure consistent development and production deployments.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Gorilla Mux:&lt;/strong&gt; A versatile router that handles routing, path variables, and method matching effectively in Go.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Upstash Redis:&lt;/strong&gt; A managed, serverless Redis solution that simplifies deployment and maintenance with built-in TLS and scalability.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Architectural Blueprint: How It All Connects
&lt;/h2&gt;

&lt;p&gt;The service operates as a stateless microservice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+------------------+     HTTPS     +---------------------+     HTTP/S     +-------------------+
|   Client Device  | &amp;lt;------------&amp;gt;|   Render (Proxy)    | &amp;lt;-------------&amp;gt;|   Go API Service  |
| (Browser/cURL)   |               | (HTTPS Termination) |                | (Docker Container)|
+------------------+               +---------------------+                +--------+----------+
                                                                                   |
                                                                                   | TLS
                                                                                   |
                                                                           +-------+--------+
                                                                           | Upstash Redis  |
                                                                           | (Data Storage, |
                                                                           | Rate Limiting) |
                                                                           +----------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Workflow at a Glance:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Request Ingress:&lt;/strong&gt; Client sends HTTP/HTTPS requests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Render Proxy:&lt;/strong&gt; Handles HTTPS and forwards to Go service.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Go API Service:&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Rate Limiting:&lt;/strong&gt; Redis checks IP-based usage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;URL Validation:&lt;/strong&gt; Ensures HTTPS and no malicious input.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Duplicate Check:&lt;/strong&gt; Returns existing short URL if already stored.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Short Code Generation:&lt;/strong&gt; Creates or verifies custom short code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Redis Storage:&lt;/strong&gt; Stores mappings with 7-day TTL.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Response:&lt;/strong&gt; Returns short URL and remaining rate limit.

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Redirection:&lt;/strong&gt; Resolves short URL to long URL using Redis and sends a 301 redirect.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Redis Connectivity:&lt;/strong&gt; All interactions are TLS-encrypted.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Key Features That Make a Difference
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Link Shortening:&lt;/strong&gt; Converts long URLs to concise versions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optional Custom Shorts:&lt;/strong&gt; User-defined short paths are supported.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automatic Expiration (TTL):&lt;/strong&gt; Links expire in 7 days.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Duplicate Handling:&lt;/strong&gt; Existing links return the same short URL and renew the TTL.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Strict HTTPS Validation:&lt;/strong&gt; Validates incoming URLs to ensure security.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rate Limiting:&lt;/strong&gt; Max 15 requests per 2 minutes per IP.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enhanced API Response:&lt;/strong&gt; &lt;code&gt;/shorten&lt;/code&gt; endpoint includes remaining rate limit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dockerized Deployment:&lt;/strong&gt; Simplifies setup and scaling.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Environment Config:&lt;/strong&gt; All settings handled via &lt;code&gt;.env&lt;/code&gt; variables.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TLS-Secured Redis Connection:&lt;/strong&gt; Fully encrypted communication with Redis.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CORS Support:&lt;/strong&gt; Manages cross-origin requests with secure defaults.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  API Usage: Getting Started
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Base URLs:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Local HTTP: &lt;code&gt;http://localhost:8080&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Local HTTPS: &lt;code&gt;https://localhost:8443&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Render Deployment: &lt;code&gt;https://your-render-service-name.onrender.com&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  1. Shorten a URL
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;POST /shorten&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Request Body (JSON)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"long_url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://example.com/very/long/path"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"custom_short"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"optional-custom-code"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example curl
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-k&lt;/span&gt; &lt;span class="nt"&gt;-X&lt;/span&gt; POST &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{"long_url": "https://github.com/golang/go"}'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
     https://localhost:8443/shorten
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Success Response
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"short_url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/s/AbC12X"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"long_url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://github.com/golang/go"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"limit_remaining"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"URL shortened successfully"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Redirect from Short URL
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;GET /s/{short}&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Example curl
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-k&lt;/span&gt; &lt;span class="nt"&gt;-L&lt;/span&gt; https://localhost:8443/s/AbC12X
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Returns an HTTP 301 redirect to the long URL.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Health Check
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;GET /health&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl http://localhost:8080/health
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Returns &lt;code&gt;200 OK&lt;/code&gt; with message &lt;code&gt;OK&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Local Setup
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Prerequisites:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Go 1.22+&lt;/li&gt;
&lt;li&gt;Docker + Docker Compose&lt;/li&gt;
&lt;li&gt;OpenSSL&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Steps:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/shushantrishav/Go_URL_Shortner.git
&lt;span class="nb"&gt;cd &lt;/span&gt;Go_URL_Shortner
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create &lt;code&gt;.env&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;REDIS_ADDR=localhost:6379
REDIS_PASSWORD=your_redis_password
REDIS_DB=0
HTTP_PORT=8080
HTTPS_PORT=8443
TLS_CERT_PATH=/app/localhost.crt
TLS_KEY_PATH=/app/localhost.key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Generate Self-Signed Certificates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;openssl req &lt;span class="nt"&gt;-x509&lt;/span&gt; &lt;span class="nt"&gt;-newkey&lt;/span&gt; rsa:4096 &lt;span class="nt"&gt;-nodes&lt;/span&gt; &lt;span class="nt"&gt;-keyout&lt;/span&gt; localhost.key &lt;span class="nt"&gt;-out&lt;/span&gt; localhost.crt &lt;span class="nt"&gt;-days&lt;/span&gt; 365 &lt;span class="nt"&gt;-subj&lt;/span&gt; &lt;span class="s2"&gt;"/CN=localhost"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go mod tidy
docker-compose up &lt;span class="nt"&gt;--build&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Seamless Deployment on Render
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Push to GitHub&lt;/li&gt;
&lt;li&gt;Create a new Web Service in Render&lt;/li&gt;
&lt;li&gt;Choose Docker as runtime&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Set env variables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;PORT=8080&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;REDIS_ADDR&lt;/code&gt;, &lt;code&gt;REDIS_PASSWORD&lt;/code&gt;, &lt;code&gt;REDIS_DB&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Render handles HTTPS automatically. No TLS certs required in code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Important Notes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Never hardcode secrets like &lt;code&gt;REDIS_PASSWORD&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Local HTTPS uses self-signed certs. Use &lt;code&gt;curl -k&lt;/code&gt; to bypass warnings.&lt;/li&gt;
&lt;li&gt;CORS config must be production-aware&lt;/li&gt;
&lt;li&gt;Rate limit by IP; can be adjusted for users behind proxies&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Future Improvements
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;User Auth for managing personal links&lt;/li&gt;
&lt;li&gt;Custom Domain Support&lt;/li&gt;
&lt;li&gt;Analytics: Clicks, referrers, geolocation&lt;/li&gt;
&lt;li&gt;QR Code generation&lt;/li&gt;
&lt;li&gt;Admin dashboard&lt;/li&gt;
&lt;li&gt;Advanced rate limiting strategies&lt;/li&gt;
&lt;li&gt;Database abstraction for metadata&lt;/li&gt;
&lt;li&gt;Monitoring &amp;amp; graceful shutdowns&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;🔍 Explore the Project&lt;br&gt;
🧪 Live Demo: &lt;a href="https://web.cutlink.in/" rel="noopener noreferrer"&gt;Cutlink&lt;/a&gt;&lt;br&gt;
💻 GitHub Repo: &lt;a href="https://github.com/shushantrishav/Go_URL_Shortner" rel="noopener noreferrer"&gt;Go_URL_Shortner&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Thanks for reading!&lt;/p&gt;

&lt;p&gt;👉 Like this project? Drop a star on &lt;a href="https://github.com/shushantrishav/Go_URL_Shortner" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;br&gt;
💬 Have questions or feedback? Let’s connect in the comments!&lt;/p&gt;

&lt;p&gt;Feel free to contribute or ask questions!&lt;/p&gt;

</description>
      <category>go</category>
      <category>docker</category>
      <category>redis</category>
      <category>api</category>
    </item>
  </channel>
</rss>
