<?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"><channel><title><![CDATA[My Blog]]></title><description><![CDATA[I am a software engineer focused on building lightweight tools, including the microblogging platform Axe. Read my blog for practical technical knowledge.]]></description><link>https://eidcoder.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/6ade243629153b0948cab0a2/006e30ba-f7e9-43a5-9f95-8603257546c1.png</url><title>My Blog</title><link>https://eidcoder.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Tue, 24 Nov 2026 12:54:31 GMT</lastBuildDate><atom:link href="https://eidcoder.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Why I'm Migrating Axion from MongoDB to Postgres]]></title><description><![CDATA[Hey guys! 👋🏻 I wanted to share a big backend decision I made for my microforum, Axion. I'm migrating the database from MongoDB to Postgres. While MongoDB…]]></description><link>https://eidcoder.hashnode.dev/why-i-m-migrating-axion-from-mongodb-to-postgres</link><guid isPermaLink="true">https://eidcoder.hashnode.dev/why-i-m-migrating-axion-from-mongodb-to-postgres</guid><dc:creator><![CDATA[Seif Eid]]></dc:creator><pubDate>Tue, 24 Nov 2026 11:27:25 GMT</pubDate><content:encoded><![CDATA[<p>Hey guys! 👋🏻</p>
<p>I wanted to share a big backend decision I made for my microforum, Axion. I'm migrating the database from MongoDB to Postgres.</p>
<p>While MongoDB worked fine to get started, I realized I was fighting against how the database was actually designed to work. Here is why I'm making the switch now:</p>
<p><strong>MongoDB Was Never Built for Deeply Relational Data.</strong> Microforums are relational by nature—posts have comments and reactions, and users have posts. MongoDB operates on the mindset of <em>"if X is related to Y, keep them together."</em></p>
<p>Postgres, on the other hand, was built specifically for relational data. Its JOINs are optimized, whereas doing relational queries in MongoDB feels like a workaround.</p>
<p><strong>Automatic Cleanup Instead of Manual Work.</strong> Right now, when a post gets deleted in Axion, I've to handle the cleanup manually:</p>
<ul>
<li>Start a transaction</li>
<li>Run a <code>deleteOne</code> operation to remove the post</li>
<li>Run a <code>deleteMany</code> operation to remove the comments</li>
<li>Run another <code>deleteMany</code> operation to remove the likes</li>
</ul>
<p>It's not that the code is messy, it's just completely manual. Every time I add a new post-related feature—like bookmarks—I've to remember to update the deletion logic to clean those up too. <em>(Note: Since Axion is meant to be small, instant cleanup isn't an issue yet, though for massive scale, this cleanup architecture won't work</em> 🙃). With Postgres, cascade deletions automate the process and remove related records for me.</p>
<p><strong>The Cost of Migration Is Low.</strong> Right now, I've no real users, no production data, and Axion isn't even hosted online yet. Everything in my database is just test data I don't care about. That means I can finish this migration in a day or two without risking data corruption.</p>
<p><strong>Using the Right Tools for Specific Problems.</strong> Even though these issues aren't hurting Axion at its current small scale, making the jump now sets the app up to scale comfortably into mid-size without technical debt. To keep some of the developer experience I liked with MongoDB, I'm going to pair Postgres with Prisma.</p>
<p>Have you ever migrated databases mid-project? Let's talk in the comments below. See you next time! 🌟</p>
]]></content:encoded></item><item><title><![CDATA[Preventing Timing Attacks in Axion's Login Route with Dummy Hashes]]></title><description><![CDATA[Hey guys! 👋🏻 I wanted to share a good security fix I applied to my microforum, Axion. It's about stopping attackers from finding out which usernames…]]></description><link>https://eidcoder.hashnode.dev/preventing-timing-attacks-in-axion-s-login-route-with-dummy-hashes</link><guid isPermaLink="true">https://eidcoder.hashnode.dev/preventing-timing-attacks-in-axion-s-login-route-with-dummy-hashes</guid><dc:creator><![CDATA[Seif Eid]]></dc:creator><pubDate>Wed, 18 Nov 2026 19:52:47 GMT</pubDate><content:encoded><![CDATA[<p>Hey guys! 👋🏻</p>
<p>I wanted to share a good security fix I applied to my microforum, Axion. It's about stopping attackers from finding out which usernames exist through timing attacks.</p>
<p><strong>Why Timing Attacks Happen in Login Routes.</strong> When you're building a login route for a platform like Axion, the normal flow looks simple: find the user by their username, and if they exist, compare the password they typed with their saved hash.</p>
<p>The problem is that password hashing takes heavy CPU work. Because of that, an attacker can measure how long each login request takes to finish, and two different things happen:</p>
<ul>
<li><strong>Wrong username:</strong> There is no hash to compare, so the server uses less CPU time. This gives a faster response, which tells the attacker the username doesn't exist.</li>
<li><strong>Right username:</strong> There is a password hash to compare, so the server uses more CPU time. This gives a slower response, which tells the attacker the username exists.</li>
</ul>
<p>Just by checking the time difference between login requests, an attacker can figure out which accounts are real. 🙃</p>
<p><strong>My Fix: Calculating a Dummy Hash.</strong> The fix was pretty simple. Instead of returning an error right away when a username isn't found, I force the server to calculate and compare a dummy hash anyway:</p>
<pre><code class="language-javascript">export async function login(req, res) {
    const { username, password } = req.data;
    const user = await models.Users.findOne({ username }).select("password").lean();
    
    // The constant variable is declared at the top of the file!
    const hash = user ? user.password : DUMMY_HASH;
    const isMatch = await bcrypt.compare(password, hash);

    if (!user || !isMatch) {
        return res.status(401).json({ error: errors.INVALID_CREDENTIALS() });
    }

    await initSession(req, user._id);
    return res.status(200).json({ success: true });
}
</code></pre>
<p>The cool part about this fix is that both cases now do the exact same amount of CPU work. Whether the username is right or wrong, the response takes the same time, so the attacker can't use timing differences to guess valid usernames anymore.</p>
<p>How do you keep your login routes safe from timing attacks? Let's talk in the comments below. See you next time! 🌟</p>
]]></content:encoded></item><item><title><![CDATA[Fixing Session Leaks in Axion's MongoDB Transactions]]></title><description><![CDATA[Hey friends! 👋🏻 I lately implemented a great backend fix in my microforum, Axion. It involved MongoDB transactions, session management, and taking…]]></description><link>https://eidcoder.hashnode.dev/fixing-session-leaks-in-axion-s-mongodb-transactions</link><guid isPermaLink="true">https://eidcoder.hashnode.dev/fixing-session-leaks-in-axion-s-mongodb-transactions</guid><dc:creator><![CDATA[Seif Eid]]></dc:creator><pubDate>Mon, 09 Nov 2026 11:55:01 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6ade243629153b0948cab0a2/53ac866b-1f5a-4b9e-8471-3fe2e70bb2c9.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hey friends! 👋🏻</p>
<p>I lately implemented a great backend fix in my microforum, Axion. It involved MongoDB transactions, session management, and taking advantage of Express 5's upgraded error handling to keep my code clean.</p>
<p><strong>Why Use Transactions in the First Place?</strong> When you're building a platform like Axion, some actions require multiple database operations to happen together. For example, in the post-deletion route, I need to remove related documents like bookmarks, likes, and comments all at once.</p>
<p>Transactions act as a way to execute a set of database operations where if a single operation fails, everything rolls back and no operations execute afterwards. This guarantees data consistency.</p>
<p><strong>The Bug I Encountered: Session Leaks.</strong> When running a transaction in MongoDB, you must start a client session and end it when you are finished. My code was written sequentially, assuming it would always reach the cleanup phase at the bottom. But if my <code>withTransaction</code> block crashed early, <code>session.endSession()</code> wouldn't get called. This left some sessions running in the background, which slowly drained resources and caused memory leaks.</p>
<p><strong>My Solution: Using</strong> <code>try/finally</code> <strong>in Express 5.</strong> The fix was straightforward, but I wanted to implement it without adding unnecessary boilerplate code. I wrapped the session management inside a <code>try/finally</code> block:</p>
<pre><code class="language-javascript">const session = await mongoose.startSession();
try {
  await session.withTransaction(async () =&gt; {
    // My atomic database operations...
  });
} finally {
  await session.endSession();
}
</code></pre>
<p>The beauty of the <code>finally</code> block is its absolute guarantee: no matter what happens inside the <code>try</code> block, the code inside <code>finally</code> is always executed. This ensures <code>session.endSession()</code> runs every time, eliminating the session leak problem.</p>
<p>Oh, yeah, and since I'm using Express 5, any exception thrown inside an async route is automatically caught by Express and routed to my global error-handling middleware. I no longer need those repetitive <code>catch</code> blocks!</p>
<p>Thanks for hanging out and reading through! How do you structure your database transactions to keep them clean and leak-free? Let's talk in the comments below. See you next time! 🌟</p>
]]></content:encoded></item><item><title><![CDATA[How I Used Aggregation Pipelines to Fix No-Op Updates and Keep Error Clarity in Axion]]></title><description><![CDATA[Hey friends! 👋🏻 I wanted to share a cool backend fix I implemented while adding the comments editing feature to my microforum, Axion. It's about handling…]]></description><link>https://eidcoder.hashnode.dev/how-i-used-aggregation-pipelines-to-fix-no-op-updates-and-keep-error-clarity-in-axion</link><guid isPermaLink="true">https://eidcoder.hashnode.dev/how-i-used-aggregation-pipelines-to-fix-no-op-updates-and-keep-error-clarity-in-axion</guid><dc:creator><![CDATA[Seif Eid]]></dc:creator><pubDate>Mon, 09 Nov 2026 10:37:13 GMT</pubDate><content:encoded><![CDATA[<p>Hey friends! 👋🏻</p>
<p>I wanted to share a cool backend fix I implemented while adding the comments editing feature to my microforum, Axion. It's about handling no-op updates cleanly without breaking error handling.</p>
<p>In the past, some of my editing routes would update the content unconditionally. Even if the old and new content were exactly the same, the database would still run the update, hit the disk, and change the timestamps. It was inefficient honestly.</p>
<p>And letting MongoDB update the timestamps on identical content breaks data integrity. It lies to you—saying the last update happened at X time when nothing actually changed. Plus, it would return <code>modifiedCount === 1</code> just because a timestamp field got changed, which ruins the tracking of actual content changes.</p>
<p>When adding comment updates, I wanted to avoid this behavior entirely.</p>
<p><strong>The Naive Approach.</strong> I could have simply used <code>{ content: { $ne: content } }</code>. But this creates a blindspot in my logic. If the database returns 0 matched documents, you can't differentiate between two completely different scenarios:</p>
<ol>
<li>Does the document actually exist and belong to the logged-in user?</li>
<li>Did the query just fail because the new content matches the old content?</li>
</ol>
<p>To give a proper response to the client, I needed to know the difference.</p>
<p><strong>My Solution: Aggregation Pipeline Updates.</strong> Instead of a basic update, I relied on an aggregation pipeline inside the update operation. And that's my logic:</p>
<ol>
<li>It first finds a document created by the current logged-in user where the <code>_id</code> matches the given comment ID.</li>
<li>If found, it updates the content and timestamps only if the old content differs from the new content.</li>
<li>Finally, it checks <code>matchedCount === 0</code>. If it's 0, we know that the document wasn't found (or the user doesn't own it) and can throw a proper 404 error here.</li>
</ol>
<p>Oh, yeah, and to end this cleanly, I included a <code>changed</code> field in the HTTP response, setting its value to <code>modifiedCount !== 0</code>. This tells the frontend exactly whether an actual database write occurred or if it was a harmless no-op.</p>
<p><strong>Handling the "(Edited)" Badge Properly.</strong> While doing this, I also needed a way for the frontend to show an "(Edited)" badge on updated comment cards.</p>
<p>I didn't want to rely on a single boolean like <code>isEdited: true</code> because it doesn't provide the metadata of <em>when</em> the update happened if I ever need it. I also rejected the idea of just comparing <code>createdAt</code> against <code>updatedAt</code>. Like, what if a background script or admin tool ever modifies a document for maintenance? <code>updatedAt</code> changes, and the system would falsely tell users the comment was edited when it wasn't.</p>
<p>So, I came up with a cleaner approach: adding a third field called <code>editedAt</code>. For non-edited comments, it stays <code>null</code>. The moment a real edit happens, it stores the exact timestamp of that edit. Maybe I don't show the edit timestamp to users right now, but if I ever want to in the future, the data will be there. It's a matter of handling "what if" scenarios cleanly from day one.</p>
<p>At the end of the day, losing precise error handling isn't worth saving a few lines of code.</p>
<p>Thanks for hanging out and reading through! How do you handle these annoying no-op updates and edit tracking in your backend? Let's talk in the comments below. See you next time! 🌟</p>
]]></content:encoded></item></channel></rss>