<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aboorva on Medium]]></title>
        <description><![CDATA[Stories by Aboorva on Medium]]></description>
        <link>https://medium.com/@abookannan567?source=rss-25de47af916b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*tjdNh_kLx3GkTr7P</url>
            <title>Stories by Aboorva on Medium</title>
            <link>https://medium.com/@abookannan567?source=rss-25de47af916b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 08:48:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abookannan567/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[When Do You Actually Need Django Signals?]]></title>
            <link>https://medium.com/@abookannan567/when-do-you-actually-need-django-signals-da2b499018bf?source=rss-25de47af916b------2</link>
            <guid isPermaLink="false">https://medium.com/p/da2b499018bf</guid>
            <dc:creator><![CDATA[Aboorva]]></dc:creator>
            <pubDate>Sun, 28 Dec 2025 10:51:31 GMT</pubDate>
            <atom:updated>2025-12-28T10:51:31.756Z</atom:updated>
            <content:encoded><![CDATA[<p>Django signals often create confusion.</p><p>Some developers use them everywhere.<br>Others avoid them completely.</p><p>So the real question is not <em>how to use signals</em>, but:</p><blockquote><strong><em>When do Django signals actually make sense?</em></strong></blockquote><p>This article explains that in a <strong>simple, practical way.</strong></p><h3>What Is a Django Signal?</h3><p>A Django signal is a way to say:</p><blockquote><em>“When something happens, let other code react to it.”</em></blockquote><p>For example:</p><ul><li>a record is saved</li><li>a record is deleted</li><li>a user logs in</li></ul><p>Django broadcasts that event, and any interested piece of code can listen and respond.</p><p>Think of it as a notification system inside your application.<br>One part of your app does something, and other parts <em>optionally</em> react.</p><h3>The One Rule That Matters</h3><p><strong>Signals are meant for side effects, not main logic.</strong></p><p>Here’s a simple test to decide whether a signal is appropriate:</p><blockquote>If this code does not run, will my application still work correctly?</blockquote><ul><li>If the answer is <strong>yes</strong> → a signal might be fine</li><li>If the answer is <strong>no</strong> → don’t use a signal</li></ul><h3>Situations Where Signals Work Well</h3><h3>1️⃣ Logging and Audit History</h3><p>Recording changes is important, but it should not block normal work.</p><p>Example:</p><ul><li>saving a record must succeed</li><li>logging that save is secondary</li></ul><p>Signals keep secondary logic out of your main workflow.</p><h3>2️⃣ Analytics and Tracking</h3><p>Things like:</p><ul><li>counting signups</li><li>tracking feature usage</li><li>sending events to analytics tools</li></ul><p>If analytics services fail or slow down, users shouldn’t be affected.</p><p>Using signals allows your main flow to continue without waiting on analytics code.</p><h3>3️⃣ Notifications That Are Not Critical</h3><p>Examples:</p><ul><li>sending emails</li><li>sending in-app notifications</li><li>triggering background jobs</li></ul><p>If a notification fails, the user action should still succeed.</p><p>Signals allow this extra behavior without slowing things down.</p><h3>4️⃣ Keeping Apps Independent</h3><p>In larger Django projects, different apps often handle different responsibilities:</p><ul><li>one app manages users</li><li>another handles reports</li><li>another manages notifications</li></ul><p>Signals allow these apps to react to events <strong>without tightly depending on each other</strong>.</p><p>This keeps your architecture cleaner and makes future changes easier.</p><h3>5️⃣ System-Level Hooks</h3><p>Some parts of Django already use signals for good reasons:</p><ul><li>actions after migrations</li><li>login or logout events</li><li>request start and end</li></ul><p>These are framework-level events where decoupling behavior is beneficial.</p><h3>When Signals Are the Wrong Choice</h3><p>Avoid signals for:</p><ul><li>core business rules</li><li>required data creation</li><li>payment processing</li><li>critical state changes</li></ul><p>If something is <strong>expected and important</strong>, it should be:</p><ul><li>clearly visible in the code flow</li><li>called explicitly</li><li>easy to trace and debug</li></ul><h3>Final Thoughts</h3><p>Django signals aren’t good or bad — they’re <strong>contextual tools</strong>.</p><p>They are excellent for reacting to events,<br> but dangerous when used to hide important logic.</p><p>Use signals when you want <strong>reactions</strong>, not <strong>responsibilities</strong>.</p><p>When used thoughtfully, they keep your code clean and decoupled.<br> When overused, they make your system unpredictable.</p><p>The key isn’t avoiding signals — <br> it’s knowing <strong>when not to use them</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da2b499018bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Idempotency in APIs — The Thing Most Devs Know, But Rarely Implement]]></title>
            <link>https://medium.com/@abookannan567/idempotency-in-apis-the-thing-most-devs-know-but-rarely-implement-3204c13e70c6?source=rss-25de47af916b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3204c13e70c6</guid>
            <dc:creator><![CDATA[Aboorva]]></dc:creator>
            <pubDate>Sun, 21 Dec 2025 13:10:20 GMT</pubDate>
            <atom:updated>2025-12-21T13:10:20.056Z</atom:updated>
            <content:encoded><![CDATA[<h3>I<strong>dempotency in APIs </strong>— The Thing Most Devs Know, But Rarely Implement</h3><p>If you’ve been building APIs for a while, you’ve probably heard the word <strong>idempotency</strong> many times. Most developers know what idempotency means, but very few implement it.</p><p>And honestly, that’s understandable.</p><p>When you’re working on simple CRUD or internal dashboards, everything seems fine — the database is clean, endpoints behave normally, and duplicate actions feel unlikely.</p><p>But once your API hits the real world — flaky mobile networks, retries, or payment systems— idempotency becomes the difference between:</p><blockquote>one payment vs <strong>double payment</strong></blockquote><blockquote>one booking vs <strong>duplicate booking</strong></blockquote><blockquote>one notification vs <strong>spam</strong></blockquote><p>So let’s quickly break down what idempotency is, why people skip it, and how to implement it properly in Django REST Framework.</p><h3>What is Idempotency, Really?</h3><p>Idempotency means:</p><blockquote><strong><em>If the same request is sent multiple times with the same key, the server should perform the action only once.</em></strong></blockquote><p>Instead of repeating the operation, the server returns the previously stored result.</p><p>✔ First request → perform the operation<br> ✔ Retry request → return the saved response<br> ❌ Never run the operation twice<br> ❌ Never create duplicates</p><p>This simple idea prevents a huge list of disasters in production, especially in payment, booking, and notification systems.</p><h3>Why Most Developers Ignore Idempotency</h3><p>Let’s be honest — idempotency is one of those concepts everyone knows from interviews, but rarely implements unless something goes wrong.</p><p>Here’s why people skip it:</p><h4>1️⃣ “I never had duplicate issues in my CRUD apps.”</h4><p>True. Basic admin-side CRUD usually doesn’t need idempotency.</p><p>But real-world payment and booking APIs face <strong>automatic retries</strong> from mobile SDKs, background jobs, or network infrastructure.</p><h4>2️⃣ “The frontend won’t retry.”</h4><p>Mobile SDKs often <strong>retry requests automatically</strong> if they detect a timeout or network failure. Reverse proxies or load balancers may also retry requests in some setups.<br>You cannot control this.</p><h4>3️⃣ “It’s extra work.”</h4><p>Yes — but worth it to prevent costly duplicates.</p><h4>4️⃣ “I thought unique constraints were enough.”</h4><p>Not for real-world APIs.</p><p>A payment can succeed twice, a booking can duplicate, or a notification can be sent multiple times without violating database constraints.</p><h3>How Idempotency Works</h3><p>The client sends a header:</p><pre>Idempotency-Key: abc123</pre><p>Design the client or process initiating the action to generate a unique Idempotency-Key for each operation, ensuring the same key is reused if the request is retried.</p><p>Server logic becomes:</p><ol><li>Check if this key exists</li><li>If yes → return stored response</li><li>If no → process request and store response</li></ol><p>Simple, predictable, safe.</p><h3>Implementing Idempotency in Django REST Framework</h3><p>We’ll use:</p><ul><li>a model to store request results</li><li>a helper function</li><li>a DRF mixin</li></ul><h3>1. Model to store responses</h3><pre><br>class IdempotencyStore(models.Model):<br>    key = models.CharField(max_length=255, unique=True)<br>    response = models.JSONField()<br>    status_code = models.IntegerField()<br>    created_at = models.DateTimeField(auto_now_add=True)</pre><h3>2. Helper to manage logic</h3><pre><br>from django.db import transaction<br>from .models import IdempotencyStore<br><br>def idempotent_request(key, create_func):<br>    try:<br>        store = IdempotencyStore.objects.get(key=key)<br>        return store.response, store.status_code, True<br>    except IdempotencyStore.DoesNotExist:<br>        pass<br><br>    with transaction.atomic():<br>        data, status_code = create_func()<br>        IdempotencyStore.objects.create(<br>            key=key,<br>            response=data,<br>            status_code=status_code<br>        )<br>        return data, status_code, False</pre><h3>3. DRF Mixin for create endpoints</h3><pre><br>class IdempotencyMixin:<br>    idempotency_header = &quot;Idempotency-Key&quot;<br><br>    def create(self, request, *args, **kwargs):<br>        key = request.headers.get(self.idempotency_header)<br><br>        if not key:<br>            return super().create(request, *args, **kwargs)<br><br>        def process_create():<br>            response = super(IdempotencyMixin, self).create(request, *args, **kwargs)<br>            return response.data, response.status_code<br><br>        data, status_code, reused = idempotent_request(key, process_create)<br><br>        return Response(data, status=status_code)</pre><p>Use it like this:</p><pre>class PaymentViewSet(IdempotencyMixin, ModelViewSet):<br>    queryset = Payment.objects.all()<br>    serializer_class = PaymentSerializer</pre><p>And you’re done — idempotency handled.</p><p>Idempotency keys don’t need to live forever — just keep them for 24–72 hours and let a cron job or Redis TTL clean them up.<br>Also, don’t overuse idempotency: GET/PUT/PATCH/DELETE already behave idempotently, so only apply it to POST endpoints that create new records.</p><h3>Final Thoughts</h3><p>Idempotency isn’t only for payment systems.<br>Any endpoint that <em>creates</em> something — tasks, messages, bookings, submissions — benefits from it.</p><p>Because at the end of the day:</p><p><strong>A single network glitch shouldn’t create duplicate data.</strong><br>Your API should be predictable, safe, and user-friendly.</p><p>Most developers know idempotency.<br>Very few implement it.<br>With Django REST Framework, it’s surprisingly easy to add — and once you do, you’ll wonder why you didn’t earlier.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3204c13e70c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Undo Feature in Rails 7 with Turbo Streams: No Background Jobs Needed]]></title>
            <link>https://medium.com/@abookannan567/undo-feature-in-rails-7-with-turbo-streams-no-background-jobs-needed-4f25cac48504?source=rss-25de47af916b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f25cac48504</guid>
            <category><![CDATA[rails-7]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[stimulusjs]]></category>
            <category><![CDATA[turbo-stream]]></category>
            <dc:creator><![CDATA[Aboorva]]></dc:creator>
            <pubDate>Sun, 29 Jun 2025 12:03:11 GMT</pubDate>
            <atom:updated>2025-06-29T12:03:11.775Z</atom:updated>
            <content:encoded><![CDATA[<p>Undo is one of those delightful features that users love. Whether it’s Gmail’s “Undo Send” or Trello’s “Undo Archive”, giving users a second chance makes your app feel modern, thoughtful, and safe.</p><p>But in Rails? It’s often skipped because it feels complicated — requiring jobs, timers, or frontend state.</p><p>Let’s change that.</p><h3>What We’ll Build</h3><p>We’ll create a simple comments interface where:</p><ul><li>A user can delete a comment.</li><li>The comment disappears instantly using Turbo Streams.</li><li>An “Undo” alert appears and stays visible for 3 seconds.</li><li>If clicked in time, the comment is restored — otherwise, the alert auto-hides.</li></ul><p>No background jobs.<br>No unnecessary complexity.</p><h3>Step 1: Setup Your App</h3><p>Generate a new Rails 7 app:</p><pre>rails new undo_demo -css=bootstrap<br>cd undo_demo<br>rails g model Comment body:string deleted_at:datetime<br>rails db:migrate</pre><pre># db/seeds.rb<br>Comment.create!(body: &quot;First comment&quot;)<br>Comment.create!(body: &quot;Second comment&quot;)</pre><h3>Step 2: Routes &amp; Controller Logic</h3><p>Define routes with an extra undo action:</p><pre># config/routes.rb<br>Rails.application.routes.draw do<br>  root &quot;comments#index&quot;<br>  resources :comments, only: [:index, :destroy] do<br>    post :undo, on: :member<br>  end<br>end</pre><p>Basic controller with soft-delete logic:</p><pre># app/controllers/comments_controller.rb<br>class CommentsController &lt; ApplicationController<br>  def index<br>    @comments = Comment.where(deleted_at: nil)<br>  end<br><br>  def destroy<br>    @comment = Comment.find(params[:id])<br>    @comment.update(deleted_at: Time.current)<br><br>    respond_to do |format|<br>      format.turbo_stream<br>    end<br>  end<br><br>  def undo<br>    @comment = Comment.find(params[:id])<br>    @comment.update(deleted_at: nil)<br><br>    respond_to do |format|<br>      format.turbo_stream<br>    end<br>  end<br>end</pre><h3>Step 3: Create the Views</h3><h4>Index Page</h4><pre>&lt;!-- app/views/comments/index.html.erb --&gt;<br>&lt;div class=&quot;container mt-4&quot;&gt;<br>  &lt;h1 class=&quot;h3 mb-3&quot;&gt;Comments&lt;/h1&gt;<br>  <br>  &lt;%= turbo_frame_tag &quot;comments&quot; do %&gt;<br>    &lt;%= render @comments %&gt;<br>  &lt;% end %&gt;<br><br>  &lt;div id=&quot;undo_zone&quot; class=&quot;mt-3&quot;&gt;&lt;/div&gt;<br>&lt;/div&gt;</pre><h4>Comment Partial</h4><pre>&lt;!-- app/views/comments/_comment.html.erb --&gt;<br>&lt;div id=&quot;comment_&lt;%= comment.id %&gt;&quot; class=&quot;card mb-3&quot;&gt;<br>  &lt;div class=&quot;card-body d-flex justify-content-between align-items-center&quot;&gt;<br>    &lt;div&gt;&lt;%= comment.body %&gt;&lt;/div&gt;<br>    &lt;%= button_to &quot;Delete&quot;, comment_path(comment), method: :delete, data: { turbo_stream: true }, class: &quot;btn btn-sm btn-outline-danger&quot; %&gt;<br>  &lt;/div&gt;<br>&lt;/div&gt;</pre><h3>Step 4: Turbo Stream Delete Response</h3><pre>&lt;!-- app/views/comments/destroy.turbo_stream.erb --&gt;<br>&lt;turbo-stream action=&quot;remove&quot; target=&quot;comment_&lt;%= @comment.id %&gt;&quot;&gt;&lt;/turbo-stream&gt;<br><br>&lt;turbo-stream action=&quot;update&quot; target=&quot;undo_zone&quot;&gt;<br>  &lt;template&gt;<br>    &lt;div data-controller=&quot;undo&quot; class=&quot;alert alert-warning d-flex justify-content-between align-items-center&quot;&gt;<br>      &lt;span&gt;Comment deleted.&lt;/span&gt;<br>      &lt;%= button_to &quot;Undo&quot;, undo_comment_path(@comment), method: :post, data: { turbo_stream: true }, class: &quot;btn btn-sm btn-link&quot; %&gt;<br>    &lt;/div&gt;<br>  &lt;/template&gt;<br>&lt;/turbo-stream&gt;</pre><h3>Step 5: Turbo Stream Undo Response</h3><pre>&lt;!-- app/views/comments/undo.turbo_stream.erb --&gt;<br>&lt;turbo-stream action=&quot;append&quot; target=&quot;comments&quot;&gt;<br>  &lt;template&gt;<br>    &lt;%= render partial: &quot;comment&quot;, formats: [:html], locals: { comment: @comment } %&gt;<br>  &lt;/template&gt;<br>&lt;/turbo-stream&gt;<br><br>&lt;turbo-stream action=&quot;update&quot; target=&quot;undo_zone&quot;&gt;<br>  &lt;template&gt;&lt;/template&gt;<br>&lt;/turbo-stream&gt;</pre><h3>Step 6: Auto-Hide the Alert Using Stimulus</h3><pre>// app/javascript/controllers/undo_controller.js<br>import { Controller } from &quot;@hotwired/stimulus&quot;<br><br>export default class extends Controller {<br>  connect() {<br>    setTimeout(() =&gt; {<br>      this.element.remove()<br>    }, 3000)<br>  }<br>}</pre><h3>Final UX</h3><ul><li>User deletes a comment → it disappears instantly</li><li>An “Undo” alert appears → stays visible for 3 seconds.</li><li>If “Undo” is clicked → the comment is restored</li><li>If not → the alert disappears quietly, no extra work needed</li></ul><h3>Wrapping Up</h3><p>We’ve just built a fully functional, user-friendly <strong>undo feature</strong> in Rails 7 using only <strong>Turbo Streams</strong> and a lightweight <strong>Stimulus controller</strong> — with zero background jobs, no external libraries, and minimal JavaScript.</p><p>This approach provides:</p><ul><li>A responsive and modern UX</li><li>Clear separation: Turbo for UI, Stimulus for timing</li><li>A fully Rails-native solution that’s easy to maintain and extend</li></ul><p>Best of all, it’s flexible — you can reuse this exact pattern for soft-deleting records, archiving items, toggling statuses, and more.</p><blockquote><em>💡 If you’re building Hotwire-based apps, this is one of the most practical enhancements you can add to improve user trust and interaction.</em></blockquote><p>So the next time you wonder, <em>‘Is Undo worth the effort?’</em> — remember: with Turbo and Stimulus, it’s not just possible, it’s elegant.</p><p><strong>Have feedback or questions?</strong><br>Drop a comment below or reach out to me on <a href="http://www.linkedin.com/in/aboorva-kannan-50500a220">LinkedIn</a>! I’d love to hear your thoughts or help if you’re trying this out.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f25cac48504" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>