<?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: CodeWithIshwar</title>
    <description>The latest articles on DEV Community by CodeWithIshwar (@codewithishwar).</description>
    <link>https://dev.to/codewithishwar</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%2F3690229%2Ffa0ea320-b80d-4411-b8a0-d6a018840c2c.png</url>
      <title>DEV Community: CodeWithIshwar</title>
      <link>https://dev.to/codewithishwar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codewithishwar"/>
    <language>en</language>
    <item>
      <title>`setTimeout()` Is Not Actually JavaScript</title>
      <dc:creator>CodeWithIshwar</dc:creator>
      <pubDate>Fri, 08 May 2026 17:18:46 +0000</pubDate>
      <link>https://dev.to/codewithishwar/settimeout-is-not-actually-javascript-1j49</link>
      <guid>https://dev.to/codewithishwar/settimeout-is-not-actually-javascript-1j49</guid>
      <description>&lt;p&gt;One of the biggest misconceptions I had early in my career was believing JavaScript itself handled things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;timers&lt;/li&gt;
&lt;li&gt;network requests&lt;/li&gt;
&lt;li&gt;DOM events&lt;/li&gt;
&lt;li&gt;file system operations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It turns out…&lt;/p&gt;

&lt;p&gt;JavaScript engines like V8 don’t actually implement any of those features.&lt;/p&gt;

&lt;p&gt;Take this example:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```js id="g7q2vn"&lt;br&gt;
setTimeout(() =&amp;gt; {&lt;br&gt;
  console.log("Hello");&lt;br&gt;
}, 2000);&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


Most developers assume:

&amp;gt; JavaScript starts a timer and waits 2 seconds.

But that’s not what happens.

---

# What V8 Actually Does

V8 only handles:

* parsing JavaScript
* compiling JavaScript
* executing JavaScript

That’s it.

It has no built-in understanding of:

* timers
* HTTP requests
* mouse clicks
* file systems
* sockets

Those capabilities are provided by the runtime environment around V8.

Depending on where your code runs, that runtime could be:

* the browser
* Node.js
* Deno
* Bun

---

# So who handles `setTimeout()`?

When you call:



```js id="dx9s1f"
setTimeout(fn, 2000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;the flow looks roughly like this:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="5ww7ik"&lt;br&gt;
JavaScript&lt;br&gt;
   ↓&lt;br&gt;
V8 Engine&lt;br&gt;
   ↓&lt;br&gt;
Runtime Bindings&lt;br&gt;
   ↓&lt;br&gt;
Native C/C++ APIs&lt;br&gt;
   ↓&lt;br&gt;
Operating System&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


The runtime delegates the timer to native code.

In browsers:

* Web APIs handle timers internally

In Node.js:

* libuv handles timers and async I/O

The operating system performs the actual waiting.

Once complete:

1. the callback enters a queue
2. the event loop notices it
3. JavaScript eventually executes it

Which means:

➡️ the timer itself never ran inside JavaScript.

---

# This Explains Why JS Can Be Non-Blocking

JavaScript is single-threaded.

Yet it still handles:

* timers
* networking
* file reading
* user events
* streaming

without freezing constantly.

Why?

Because the expensive work happens outside the JS engine entirely.

JavaScript delegates async work to native systems and later receives completed tasks back through the event loop.

That mental model made async JavaScript finally “click” for me.

---

# The Bigger Insight

Most APIs developers use daily are not part of ECMAScript itself.

Examples:

| API                  | Provided by                      |
| -------------------- | -------------------------------- |
| `fetch()`            | Browser/Runtime networking layer |
| `addEventListener()` | Browser event system             |
| `console.log()`      | Native stdout implementation     |
| `fs.readFile()`      | Node.js runtime                  |
| Timers               | Browser APIs / libuv             |

JavaScript alone is actually a very small language.

The real power comes from the runtime surrounding it.

And once you understand that distinction:

* event loops make more sense
* async/await becomes clearer
* performance debugging improves
* Node.js architecture feels less “magical”

Understanding runtimes changed the way I think about JavaScript completely.

What runtime/internal concept gave you the biggest “aha” moment?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>productivity</category>
    </item>
    <item>
      <title>`setTimeout()` Is NOT Part of JavaScript</title>
      <dc:creator>CodeWithIshwar</dc:creator>
      <pubDate>Fri, 08 May 2026 17:17:37 +0000</pubDate>
      <link>https://dev.to/codewithishwar/settimeout-is-not-part-of-javascript-52ef</link>
      <guid>https://dev.to/codewithishwar/settimeout-is-not-part-of-javascript-52ef</guid>
      <description>&lt;p&gt;Most developers write this code every day:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```js id="e9u2xa"&lt;br&gt;
setTimeout(() =&amp;gt; {&lt;br&gt;
  console.log("Hello");&lt;br&gt;
}, 2000);&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


and assume JavaScript is responsible for the timer.

But that’s not actually true.

## The surprising reality

JavaScript engines like V8 do **not** have built-in timer functionality.

V8 only knows how to:

* parse JavaScript
* compile JavaScript
* execute JavaScript

That’s it.

Functions like:

* `setTimeout()`
* `fetch()`
* `addEventListener()`
* `console.log()`

are **not provided by JavaScript itself**.

They come from the runtime environment:

* Browsers
* Node.js
* Native system libraries

---

# What happens when `setTimeout()` runs?

When you execute:



```js id="n5lf4v"
setTimeout(callback, 2000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;the flow is roughly:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```text id="38dxux"&lt;br&gt;
JavaScript&lt;br&gt;
   ↓&lt;br&gt;
V8 Engine&lt;br&gt;
   ↓&lt;br&gt;
Runtime Bindings&lt;br&gt;
   ↓&lt;br&gt;
Native C/C++ APIs&lt;br&gt;
   ↓&lt;br&gt;
Operating System&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


The runtime delegates the timer to native code.

In browsers:

* Web APIs handle timers

In Node.js:

* libuv handles timers and async I/O

The OS performs the actual waiting.

Once the timer completes:

1. The callback enters the task queue
2. The event loop detects it
3. JavaScript executes it when the call stack is empty

---

# Simplified internal implementation

Browser/runtime internals conceptually look like this:



```cpp id="8b45pi"
void SetTimeoutCallback(args) {
  StartTimer(delay, [=]() {
    task_queue.push(jsCallback);
  });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important takeaway:&lt;/p&gt;

&lt;p&gt;➡️ The timer itself never runs inside JavaScript.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why JavaScript feels asynchronous
&lt;/h1&gt;

&lt;p&gt;JavaScript is single-threaded.&lt;/p&gt;

&lt;p&gt;So how can it handle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;timers&lt;/li&gt;
&lt;li&gt;networking&lt;/li&gt;
&lt;li&gt;file systems&lt;/li&gt;
&lt;li&gt;user events&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;without blocking?&lt;/p&gt;

&lt;p&gt;Because the expensive work happens outside the JS engine entirely.&lt;/p&gt;

&lt;p&gt;JavaScript delegates async operations to native runtime systems.&lt;/p&gt;

&lt;p&gt;The event loop simply coordinates completed work back into JS execution.&lt;/p&gt;




&lt;h1&gt;
  
  
  This architecture powers almost everything
&lt;/h1&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;API&lt;/th&gt;
&lt;th&gt;Backed by&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;fetch()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Native networking stack&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;addEventListener()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Browser event system&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;console.log()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Native stdout handling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;fs.readFile()&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;OS file system calls&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Timers&lt;/td&gt;
&lt;td&gt;Browser APIs / libuv&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h1&gt;
  
  
  Why understanding this matters
&lt;/h1&gt;

&lt;p&gt;Once you understand this model, concepts like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Event Loop&lt;/li&gt;
&lt;li&gt;Async/Await&lt;/li&gt;
&lt;li&gt;Promises&lt;/li&gt;
&lt;li&gt;Node.js internals&lt;/li&gt;
&lt;li&gt;Browser APIs&lt;/li&gt;
&lt;li&gt;Performance bottlenecks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;become much easier to reason about.&lt;/p&gt;

&lt;p&gt;One of the biggest mindset shifts in JavaScript is realizing:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;JavaScript itself is actually a very small language.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Most of the “magic” developers use daily comes from the runtime around it.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>browser</category>
    </item>
    <item>
      <title>Understanding JavaScript Internals (What Most Developers Miss)</title>
      <dc:creator>CodeWithIshwar</dc:creator>
      <pubDate>Wed, 29 Apr 2026 17:20:33 +0000</pubDate>
      <link>https://dev.to/codewithishwar/understanding-javascript-internals-what-most-developers-miss-4lpn</link>
      <guid>https://dev.to/codewithishwar/understanding-javascript-internals-what-most-developers-miss-4lpn</guid>
      <description>&lt;p&gt;Most developers think they know JavaScript.&lt;/p&gt;

&lt;p&gt;I thought the same.&lt;/p&gt;

&lt;p&gt;Until I realized… I only knew the syntax—not what’s happening underneath.&lt;/p&gt;

&lt;p&gt;⚡ Why JavaScript Feels Confusing&lt;/p&gt;

&lt;p&gt;It’s not random.&lt;/p&gt;

&lt;p&gt;It’s just misunderstood.&lt;/p&gt;

&lt;p&gt;JavaScript is powerful because of how it behaves under the hood, not just its features.&lt;/p&gt;

&lt;p&gt;🧠 Functions are First-Class&lt;/p&gt;

&lt;p&gt;You can pass, return, and store functions anywhere.&lt;/p&gt;

&lt;p&gt;That’s why:&lt;/p&gt;

&lt;p&gt;callbacks&lt;br&gt;
middleware&lt;br&gt;
hooks&lt;/p&gt;

&lt;p&gt;…are even possible.&lt;/p&gt;

&lt;p&gt;🔁 Closures = Functions with Memory&lt;/p&gt;

&lt;p&gt;A function doesn’t forget its scope.&lt;/p&gt;

&lt;p&gt;Even after execution, it remembers where it came from.&lt;/p&gt;

&lt;p&gt;This powers:&lt;/p&gt;

&lt;p&gt;data privacy&lt;br&gt;
encapsulation&lt;br&gt;
patterns used in modern frameworks&lt;br&gt;
⏳ Event Loop = Async Explained&lt;/p&gt;

&lt;p&gt;JavaScript is single-threaded.&lt;/p&gt;

&lt;p&gt;But still handles async smoothly.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because of:&lt;/p&gt;

&lt;p&gt;call stack&lt;br&gt;
callback queue&lt;br&gt;
microtask queue&lt;/p&gt;

&lt;p&gt;👉 That’s why Promise runs before setTimeout&lt;/p&gt;

&lt;p&gt;🧩 Prototypes (Real Inheritance)&lt;/p&gt;

&lt;p&gt;Objects inherit from other objects.&lt;/p&gt;

&lt;p&gt;Classes?&lt;/p&gt;

&lt;p&gt;Just syntactic sugar.&lt;/p&gt;

&lt;p&gt;⚡ Type Coercion (Helpful… Until It’s Not)&lt;br&gt;
[] + {} // "[object Object]"&lt;/p&gt;

&lt;p&gt;If you don’t understand coercion, bugs feel random.&lt;/p&gt;

&lt;p&gt;🧠 Almost Everything is an Object&lt;/p&gt;

&lt;p&gt;Functions, arrays, even primitives (via wrappers)&lt;/p&gt;

&lt;p&gt;Once you see this, JavaScript starts feeling consistent.&lt;/p&gt;

&lt;p&gt;💡 The Shift That Matters&lt;/p&gt;

&lt;p&gt;Beginner:&lt;br&gt;
“I know JavaScript syntax”&lt;/p&gt;

&lt;p&gt;Advanced:&lt;br&gt;
“I understand how JavaScript behaves”&lt;/p&gt;

&lt;p&gt;🔥 Final Thought&lt;/p&gt;

&lt;p&gt;JavaScript doesn’t get easier when you memorize more.&lt;/p&gt;

&lt;p&gt;It gets easier when you understand the patterns underneath.&lt;/p&gt;

&lt;p&gt;💬 What concept made JavaScript finally “click” for you?&lt;/p&gt;

&lt;p&gt;🏷️ Tags&lt;/p&gt;

&lt;h1&gt;
  
  
  javascript #webdev #programming #frontend #coding #softwareengineering #asyncjavascript #closures #eventloop #codewithishwar
&lt;/h1&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
      <category>beginners</category>
    </item>
    <item>
      <title>JavaScript Internals Most Developers Ignore</title>
      <dc:creator>CodeWithIshwar</dc:creator>
      <pubDate>Wed, 29 Apr 2026 17:18:22 +0000</pubDate>
      <link>https://dev.to/codewithishwar/javascript-internals-most-developers-ignore-2k78</link>
      <guid>https://dev.to/codewithishwar/javascript-internals-most-developers-ignore-2k78</guid>
      <description>&lt;p&gt;Most developers think they know JavaScript.&lt;/p&gt;

&lt;p&gt;They don’t.&lt;/p&gt;

&lt;p&gt;They know syntax…&lt;br&gt;
but miss the real power behind it.&lt;/p&gt;

&lt;p&gt;⚡ JavaScript isn’t powerful because of features&lt;/p&gt;

&lt;p&gt;It’s powerful because of how it behaves under the hood&lt;/p&gt;

&lt;p&gt;🧠 1. Functions are First-Class Citizens&lt;/p&gt;

&lt;p&gt;You can pass, return, and store functions anywhere.&lt;/p&gt;

&lt;p&gt;function greet(name) {&lt;br&gt;
  return &lt;code&gt;Hello, ${name}&lt;/code&gt;;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;const sayHi = greet;&lt;br&gt;
console.log(sayHi("Ishwar"));&lt;/p&gt;

&lt;p&gt;👉 This is why callbacks, middleware, and hooks exist.&lt;/p&gt;

&lt;p&gt;🔁 2. Closures (The Silent Superpower)&lt;/p&gt;

&lt;p&gt;Functions remember their scope—even after execution.&lt;/p&gt;

&lt;p&gt;function createCounter() {&lt;br&gt;
  let count = 0;&lt;/p&gt;

&lt;p&gt;return function () {&lt;br&gt;
    count++;&lt;br&gt;
    return count;&lt;br&gt;
  };&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;const counter = createCounter();&lt;br&gt;
counter(); // 1&lt;br&gt;
counter(); // 2&lt;/p&gt;

&lt;p&gt;👉 Used for:&lt;/p&gt;

&lt;p&gt;Data privacy&lt;br&gt;
Encapsulation&lt;br&gt;
React hooks&lt;br&gt;
⏳ 3. Event Loop (Non-Blocking Magic)&lt;/p&gt;

&lt;p&gt;JavaScript is single-threaded but handles async efficiently.&lt;/p&gt;

&lt;p&gt;console.log("Start");&lt;/p&gt;

&lt;p&gt;setTimeout(() =&amp;gt; console.log("Timeout"), 0);&lt;/p&gt;

&lt;p&gt;Promise.resolve().then(() =&amp;gt; console.log("Promise"));&lt;/p&gt;

&lt;p&gt;console.log("End");&lt;/p&gt;

&lt;p&gt;// Output:&lt;br&gt;
// Start → End → Promise → Timeout&lt;/p&gt;

&lt;p&gt;👉 Powered by:&lt;/p&gt;

&lt;p&gt;Call stack&lt;br&gt;
Callback queue&lt;br&gt;
Microtask queue&lt;br&gt;
🧩 4. Prototypal Inheritance&lt;/p&gt;

&lt;p&gt;Objects inherit directly from other objects.&lt;/p&gt;

&lt;p&gt;const animal = {&lt;br&gt;
  eat() {&lt;br&gt;
    console.log("eating");&lt;br&gt;
  },&lt;br&gt;
};&lt;/p&gt;

&lt;p&gt;const dog = Object.create(animal);&lt;br&gt;
dog.bark = function () {&lt;br&gt;
  console.log("barking");&lt;br&gt;
};&lt;/p&gt;

&lt;p&gt;dog.eat();&lt;br&gt;
dog.bark();&lt;/p&gt;

&lt;p&gt;👉 Classes are just syntactic sugar over prototypes.&lt;/p&gt;

&lt;p&gt;⚡ 5. Dynamic Typing &amp;amp; Coercion&lt;/p&gt;

&lt;p&gt;Flexible—but can be tricky.&lt;/p&gt;

&lt;p&gt;[] + {}        // "[object Object]"&lt;br&gt;
"5" - 2        // 3&lt;br&gt;
"5" + 2        // "52"&lt;/p&gt;

&lt;p&gt;👉 Understanding coercion prevents unexpected bugs.&lt;/p&gt;

&lt;p&gt;🧠 6. Almost Everything is an Object&lt;br&gt;
function fn() {}&lt;br&gt;
typeof fn; // "function"&lt;/p&gt;

&lt;p&gt;const arr = [1, 2, 3];&lt;br&gt;
typeof arr; // "object"&lt;/p&gt;

&lt;p&gt;(42).toFixed(2); // "42.00"&lt;/p&gt;

&lt;p&gt;👉 Even primitives behave like objects via wrappers.&lt;/p&gt;

&lt;p&gt;💡 What Most Developers Miss&lt;/p&gt;

&lt;p&gt;JavaScript rewards understanding…&lt;br&gt;
and punishes assumptions.&lt;/p&gt;

&lt;p&gt;🚀 The Real Shift&lt;/p&gt;

&lt;p&gt;Beginner:&lt;br&gt;
“I know JavaScript syntax”&lt;/p&gt;

&lt;p&gt;Advanced:&lt;br&gt;
“I understand how JavaScript behaves”&lt;/p&gt;

&lt;p&gt;🔥 Final Thought&lt;/p&gt;

&lt;p&gt;Once you understand this:&lt;/p&gt;

&lt;p&gt;You stop debugging blindly&lt;br&gt;
You start predicting outcomes&lt;br&gt;
💬 Let’s Discuss&lt;/p&gt;

&lt;p&gt;What concept made JavaScript finally “click” for you?&lt;/p&gt;

&lt;p&gt;🏷️ Tags&lt;/p&gt;

&lt;h1&gt;
  
  
  javascript #webdev #programming #frontend #coding #softwareengineering #asyncjavascript #closures #eventloop #codewithishwar
&lt;/h1&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
      <category>javascript</category>
    </item>
    <item>
      <title>⚠️ Why a Simple Integer Breaks in Concurrency</title>
      <dc:creator>CodeWithIshwar</dc:creator>
      <pubDate>Mon, 27 Apr 2026 17:07:51 +0000</pubDate>
      <link>https://dev.to/codewithishwar/why-a-simple-integer-breaks-in-concurrency-1j2o</link>
      <guid>https://dev.to/codewithishwar/why-a-simple-integer-breaks-in-concurrency-1j2o</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;A small example that completely changed how I think about shared state.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🧠 The Scenario
&lt;/h2&gt;

&lt;p&gt;Consider a shared integer accessed by two threads:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Thread A increments (+1)&lt;/li&gt;
&lt;li&gt;Thread B decrements (-1)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Expected
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Actual
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;❌ Unpredictable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ❗ The Hidden Problem
&lt;/h2&gt;

&lt;p&gt;At first glance, this looks safe:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```java id="u3q9mp"&lt;br&gt;
value++;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


But this is **not atomic**.

It actually involves three steps:

1. Read
2. Modify
3. Write

Now imagine this execution order:



```id="s7k1ye"
Thread A → Read (0)
Thread B → Read (0)
Thread A → Write (1)
Thread B → Write (-1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Final result: &lt;strong&gt;-1 instead of 0&lt;/strong&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  ⚠️ Race Condition
&lt;/h2&gt;

&lt;p&gt;This is a &lt;strong&gt;race condition&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multiple threads access shared data&lt;/li&gt;
&lt;li&gt;At least one modifies it&lt;/li&gt;
&lt;li&gt;No synchronization is applied&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Result:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Inconsistent state&lt;/li&gt;
&lt;li&gt;Unpredictable output&lt;/li&gt;
&lt;li&gt;Subtle, hard-to-debug bugs&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  💻 Java Example
&lt;/h2&gt;



&lt;p&gt;```java id="kz9r2a"&lt;br&gt;
class Counter {&lt;br&gt;
    int value = 0;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void increment() {
    value++; // not atomic
}

void decrement() {
    value--; // not atomic
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;public class Main {&lt;br&gt;
    public static void main(String[] args) throws Exception {&lt;br&gt;
        Counter counter = new Counter();&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    Thread t1 = new Thread(() -&amp;gt; {
        for (int i = 0; i &amp;lt; 10000; i++) counter.increment();
    });

    Thread t2 = new Thread(() -&amp;gt; {
        for (int i = 0; i &amp;lt; 10000; i++) counter.decrement();
    });

    t1.start();
    t2.start();

    t1.join();
    t2.join();

    System.out.println(counter.value); // ❌ unpredictable
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


---

## ✅ Approaches to Fix

### 1. synchronized

* Simple and reliable
* Ensures mutual exclusion
* ❌ Can reduce concurrency

---

### 2. AtomicInteger

* Lock-free
* Efficient for counters



```java id="6m2y8t"
import java.util.concurrent.atomic.AtomicInteger;

AtomicInteger counter = new AtomicInteger(0);
counter.incrementAndGet();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Locks (ReentrantLock)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Fine-grained control&lt;/li&gt;
&lt;li&gt;Useful for advanced cases&lt;/li&gt;
&lt;li&gt;❌ More complex&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  🌐 JavaScript Perspective
&lt;/h2&gt;

&lt;p&gt;Even in JavaScript, async operations can introduce similar issues:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;```javascript id="r4t8zn"&lt;br&gt;
let counter = 0;&lt;/p&gt;

&lt;p&gt;async function increment() {&lt;br&gt;
  let temp = counter;&lt;br&gt;
  await Promise.resolve();&lt;br&gt;
  counter = temp + 1;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;async function decrement() {&lt;br&gt;
  let temp = counter;&lt;br&gt;
  await Promise.resolve();&lt;br&gt;
  counter = temp - 1;&lt;br&gt;
}&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


---

## 🔐 Coordinating Async Access (Mutex Pattern)



```javascript id="g2w9xp"
class Mutex {
  constructor() {
    this.locked = false;
    this.queue = [];
  }

  lock() {
    return new Promise(resolve =&amp;gt; {
      if (!this.locked) {
        this.locked = true;
        resolve();
      } else {
        this.queue.push(resolve);
      }
    });
  }

  unlock() {
    if (this.queue.length &amp;gt; 0) {
      const next = this.queue.shift();
      next();
    } else {
      this.locked = false;
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🎯 Key Takeaway
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Concurrency bugs rarely fail loudly.&lt;br&gt;
They fail silently—and that’s what makes them dangerous.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🚀 Closing Thought
&lt;/h2&gt;

&lt;p&gt;This small example highlights a deeper principle:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Shared state + concurrency = risk unless carefully managed.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🏷️ Suggested Tags
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;concurrency&lt;/code&gt; &lt;code&gt;multithreading&lt;/code&gt; &lt;code&gt;java&lt;/code&gt; &lt;code&gt;javascript&lt;/code&gt; &lt;code&gt;backend&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  📌 Author
&lt;/h2&gt;

&lt;p&gt;Sharing practical backend learnings.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;#CodeWithIshwar&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>ai</category>
      <category>productivity</category>
    </item>
    <item>
      <title>⚠️ Why a Simple Integer Breaks in Concurrency (Race Condition Explained)</title>
      <dc:creator>CodeWithIshwar</dc:creator>
      <pubDate>Mon, 27 Apr 2026 17:06:35 +0000</pubDate>
      <link>https://dev.to/codewithishwar/why-a-simple-integer-breaks-in-concurrency-race-condition-explained-3g28</link>
      <guid>https://dev.to/codewithishwar/why-a-simple-integer-breaks-in-concurrency-race-condition-explained-3g28</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Even a simple shared integer can produce unpredictable results.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🧠 The Scenario
&lt;/h2&gt;

&lt;p&gt;Let’s say we have a shared variable:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One thread increments (+1)&lt;/li&gt;
&lt;li&gt;Another thread decrements (-1)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Expected result:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Actual result:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;❌ Unpredictable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ❗ What’s Going Wrong?
&lt;/h2&gt;

&lt;p&gt;At first glance, this looks harmless:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;++;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But this is &lt;strong&gt;NOT atomic&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It actually involves three steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Read&lt;/li&gt;
&lt;li&gt;Modify&lt;/li&gt;
&lt;li&gt;Write&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now imagine two threads executing this at the same time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Thread A → Read (0)
Thread B → Read (0)
Thread A → Write (1)
Thread B → Write (-1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Final result: &lt;strong&gt;-1 instead of 0&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ Race Condition
&lt;/h2&gt;

&lt;p&gt;This is a classic &lt;strong&gt;race condition&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multiple threads access shared data&lt;/li&gt;
&lt;li&gt;At least one modifies it&lt;/li&gt;
&lt;li&gt;No proper synchronization&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Result:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inconsistent data&lt;/li&gt;
&lt;li&gt;Unpredictable behavior&lt;/li&gt;
&lt;li&gt;Hard-to-debug issues&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  💻 Java Example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Counter&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;++;&lt;/span&gt; &lt;span class="c1"&gt;// not atomic&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;decrement&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;--;&lt;/span&gt; &lt;span class="c1"&gt;// not atomic&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Counter&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Counter&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="nc"&gt;Thread&lt;/span&gt; &lt;span class="n"&gt;t1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;increment&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="o"&gt;});&lt;/span&gt;

        &lt;span class="nc"&gt;Thread&lt;/span&gt; &lt;span class="n"&gt;t2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="o"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++)&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;decrement&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="o"&gt;});&lt;/span&gt;

        &lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;start&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;start&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="n"&gt;t1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;join&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;t2&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;join&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// ❌ unpredictable&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ✅ Fixes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. synchronized
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Easy to use&lt;/li&gt;
&lt;li&gt;Ensures mutual exclusion&lt;/li&gt;
&lt;li&gt;❌ Can block threads
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;synchronized&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;++;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  2. AtomicInteger
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Lock-free and efficient&lt;/li&gt;
&lt;li&gt;Ideal for counters
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;java.util.concurrent.atomic.AtomicInteger&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;AtomicInteger&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AtomicInteger&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;incrementAndGet&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  3. Locks (ReentrantLock)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;More control&lt;/li&gt;
&lt;li&gt;Useful for complex cases&lt;/li&gt;
&lt;li&gt;❌ More verbose&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🌐 JavaScript Version (Async Race Condition)
&lt;/h2&gt;

&lt;p&gt;Even though JavaScript is single-threaded, async operations can still create race conditions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;decrement&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🔐 JavaScript Fix (Mutex)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Mutex&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;locked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;queue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;lock&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;locked&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;locked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;unlock&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;locked&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🎯 Key Takeaway
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Concurrency bugs don’t fail loudly.&lt;br&gt;
They fail silently.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And that’s what makes them dangerous.&lt;/p&gt;




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

&lt;p&gt;This small example completely changed how I think about shared state.&lt;/p&gt;

&lt;p&gt;If you’re working in backend or distributed systems, this is something you must understand deeply.&lt;/p&gt;




&lt;h2&gt;
  
  
  🏷️ Tags (add on DEV)
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;#java&lt;/code&gt; &lt;code&gt;#javascript&lt;/code&gt; &lt;code&gt;#concurrency&lt;/code&gt; &lt;code&gt;#backend&lt;/code&gt; &lt;code&gt;#programming&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  📌 About Me
&lt;/h2&gt;

&lt;p&gt;Sharing what I learn as I grow.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;#CodeWithIshwar&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>opensource</category>
      <category>cleancode</category>
    </item>
    <item>
      <title>Memory Is the Bottleneck We Notice Too Late</title>
      <dc:creator>CodeWithIshwar</dc:creator>
      <pubDate>Mon, 20 Apr 2026 16:48:58 +0000</pubDate>
      <link>https://dev.to/codewithishwar/memory-is-the-bottleneck-we-notice-too-late-1ok0</link>
      <guid>https://dev.to/codewithishwar/memory-is-the-bottleneck-we-notice-too-late-1ok0</guid>
      <description>&lt;p&gt;In many backend systems, performance issues are often blamed on CPU or inefficient logic.&lt;/p&gt;

&lt;p&gt;But in practice, memory is frequently the real constraint.&lt;/p&gt;

&lt;p&gt;The tricky part?&lt;br&gt;&lt;br&gt;
It doesn’t fail loudly.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ What I’ve Observed
&lt;/h2&gt;

&lt;p&gt;Systems usually degrade gradually:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Increased response times
&lt;/li&gt;
&lt;li&gt;Random slowdowns
&lt;/li&gt;
&lt;li&gt;Occasional crashes under load
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And when you investigate, it often traces back to memory usage patterns.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚨 Common Patterns That Cause It
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Over-fetching Data
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// ❌ Loads everything into memory&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getAllUsers&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Large Responses by Default&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;APIs returning more data than necessary increase both memory and network overhead.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Memory Leaks
Long-lived references
Uncleaned event listeners
Open connections&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These issues don’t show immediately but accumulate over time.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Lack of Caching&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Repeated computation or database calls create unnecessary pressure.&lt;/p&gt;

&lt;p&gt;🧠 A Small Shift That Helped Me&lt;/p&gt;

&lt;p&gt;Instead of asking:&lt;/p&gt;

&lt;p&gt;"How do I make this work?"&lt;/p&gt;

&lt;p&gt;I started asking:&lt;/p&gt;

&lt;p&gt;"Do I really need this in memory?"&lt;/p&gt;

&lt;p&gt;That one question changed:&lt;/p&gt;

&lt;p&gt;How I design APIs&lt;br&gt;
How I fetch data&lt;br&gt;
How I think about lifecycle&lt;br&gt;
⚡ Why This Matters&lt;/p&gt;

&lt;p&gt;Memory-efficient systems:&lt;/p&gt;

&lt;p&gt;Stay stable under load&lt;br&gt;
Scale more predictably&lt;br&gt;
Are easier to debug&lt;br&gt;
🤝 Open Question&lt;/p&gt;

&lt;p&gt;How do you approach memory in your systems?&lt;/p&gt;

&lt;p&gt;Do you actively design for it early,&lt;br&gt;
or treat it as an optimization later?&lt;/p&gt;

&lt;p&gt;Always curious to learn how others handle this.&lt;/p&gt;

&lt;p&gt;— CodeWithIshwar | Ishwar Chandra Tiwari&lt;/p&gt;




&lt;h3&gt;
  
  
  🔥 Why this works on Forem
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Feels like a &lt;strong&gt;community discussion&lt;/strong&gt;, not a lecture
&lt;/li&gt;
&lt;li&gt;Includes &lt;strong&gt;real code + experience&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Ends with a question → encourages replies
&lt;/li&gt;
&lt;li&gt;Fits open-source / dev culture tone
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;If you want next step:&lt;br&gt;
I can help you turn all these into a &lt;strong&gt;consistent cross-platform content system&lt;/strong&gt; so you don’t have to think every day.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>productivity</category>
      <category>memorymanagement</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>Memory: The Silent Bottleneck in Backend Systems</title>
      <dc:creator>CodeWithIshwar</dc:creator>
      <pubDate>Mon, 20 Apr 2026 16:44:31 +0000</pubDate>
      <link>https://dev.to/codewithishwar/memory-the-silent-bottleneck-in-backend-systems-322k</link>
      <guid>https://dev.to/codewithishwar/memory-the-silent-bottleneck-in-backend-systems-322k</guid>
      <description>&lt;h1&gt;
  
  
  🧠 Memory: The Silent Bottleneck in Backend Systems
&lt;/h1&gt;

&lt;p&gt;When performance issues show up, most developers look at CPU or inefficient logic.&lt;/p&gt;

&lt;p&gt;But in many real-world systems, the actual problem is &lt;strong&gt;memory usage&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚨 Why Memory Matters
&lt;/h2&gt;

&lt;p&gt;Memory issues don’t fail loudly.&lt;/p&gt;

&lt;p&gt;Your system:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Works fine in development&lt;/li&gt;
&lt;li&gt;Passes initial testing&lt;/li&gt;
&lt;li&gt;Then starts slowing down under real traffic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s when memory becomes a bottleneck.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚠️ Common Mistakes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Loading Too Much Data
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// ❌ Bad&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getAllUsers&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;// ✅ Better&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getUsers&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Large API Payloads&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Sending unnecessary data increases:&lt;/p&gt;

&lt;p&gt;Memory usage&lt;br&gt;
Network latency&lt;/p&gt;

&lt;p&gt;Fix: Return only required fields.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Memory Leaks&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Objects that are not released properly keep consuming memory over time.&lt;/p&gt;

&lt;p&gt;Example causes:&lt;/p&gt;

&lt;p&gt;Unclosed connections&lt;br&gt;
Global references&lt;br&gt;
Event listeners not cleaned up&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;No Caching Strategy&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Repeated heavy operations increase load.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Example with caching&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cached&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user:1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;cached&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;redis&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user:1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;⚡ Real Impact&lt;/p&gt;

&lt;p&gt;Optimizing memory leads to:&lt;/p&gt;

&lt;p&gt;Better performance&lt;br&gt;
Fewer crashes&lt;br&gt;
Improved scalability&lt;/p&gt;

&lt;p&gt;🧠 Key Mindset&lt;/p&gt;

&lt;p&gt;Most developers ask:&lt;/p&gt;

&lt;p&gt;"How do I make this work?"&lt;/p&gt;

&lt;p&gt;Better question:&lt;/p&gt;

&lt;p&gt;"Do I really need this in memory?"&lt;/p&gt;

&lt;p&gt;✅ Conclusion&lt;/p&gt;

&lt;p&gt;Good engineers write code that works.&lt;br&gt;
Great engineers write code that is efficient.&lt;/p&gt;

&lt;p&gt;Memory may not be visible at first,&lt;/p&gt;

&lt;p&gt;but it’s often the reason systems fail at scale.&lt;/p&gt;

&lt;p&gt;💬 Have you faced memory issues in production?&lt;br&gt;
Would love to hear your experience.&lt;/p&gt;

&lt;h1&gt;
  
  
  backend #systemdesign #performance #programming
&lt;/h1&gt;




&lt;h3&gt;
  
  
  🔥 Why this works on dev.to
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Clean structure (important there)
&lt;/li&gt;
&lt;li&gt;Includes code examples
&lt;/li&gt;
&lt;li&gt;Practical, not motivational
&lt;/li&gt;
&lt;li&gt;Invites discussion
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;If you want next level:&lt;br&gt;
I can turn this into a &lt;strong&gt;multi-part dev.to series&lt;/strong&gt; (memory, caching, DB scaling, queues) so you grow faster as a backend creator.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>productivity</category>
      <category>architecture</category>
    </item>
    <item>
      <title>You’re Probably Underestimating Redis</title>
      <dc:creator>CodeWithIshwar</dc:creator>
      <pubDate>Fri, 17 Apr 2026 16:46:20 +0000</pubDate>
      <link>https://dev.to/codewithishwar/youre-probably-underestimating-redis-51p9</link>
      <guid>https://dev.to/codewithishwar/youre-probably-underestimating-redis-51p9</guid>
      <description>&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%2Fjnf1ho4350mjgy24nfpt.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%2Fjnf1ho4350mjgy24nfpt.png" alt=" " width="800" height="658"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Redis Isn’t Just a Cache - It’s a Data Structure Engine
&lt;/h2&gt;

&lt;p&gt;When I first started using Redis, I thought of it as just a fast key-value store.&lt;/p&gt;

&lt;p&gt;But that’s only part of the story.&lt;/p&gt;

&lt;p&gt;Under the hood, Redis is built on top of multiple powerful data structures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Strings&lt;/strong&gt; → simple key-value storage&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hashes&lt;/strong&gt; → structured objects&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lists&lt;/strong&gt; → queues and stacks&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sets&lt;/strong&gt; → unique collections&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sorted Sets&lt;/strong&gt; → ranking systems&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why This Design Matters
&lt;/h2&gt;

&lt;p&gt;Each data structure is optimized for a specific type of problem.&lt;/p&gt;

&lt;p&gt;This makes Redis incredibly versatile for use cases like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;caching&lt;/li&gt;
&lt;li&gt;real-time leaderboards&lt;/li&gt;
&lt;li&gt;job queues&lt;/li&gt;
&lt;li&gt;session storage&lt;/li&gt;
&lt;li&gt;analytics&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The Bigger Lesson
&lt;/h2&gt;

&lt;p&gt;The real takeaway isn’t just about Redis.&lt;/p&gt;

&lt;p&gt;It’s about system design.&lt;/p&gt;

&lt;p&gt;Good systems are not just fast —&lt;br&gt;
they are built on choosing the &lt;strong&gt;right data structure for the problem&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thought
&lt;/h2&gt;

&lt;p&gt;Redis isn’t just a cache.&lt;/p&gt;

&lt;p&gt;It’s a &lt;strong&gt;data structure engine&lt;/strong&gt; that helps you think differently about solving problems.&lt;/p&gt;




&lt;p&gt;#redis #dsa #systemdesign #backend #programming&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Redis Isn’t Just a Cache - It’s a Data Structure Engine</title>
      <dc:creator>CodeWithIshwar</dc:creator>
      <pubDate>Fri, 17 Apr 2026 16:44:03 +0000</pubDate>
      <link>https://dev.to/codewithishwar/redis-isnt-just-a-cache-its-a-data-structure-engine-3bkd</link>
      <guid>https://dev.to/codewithishwar/redis-isnt-just-a-cache-its-a-data-structure-engine-3bkd</guid>
      <description>&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%2Fqcatbf4lob2ieke9vff9.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%2Fqcatbf4lob2ieke9vff9.png" alt=" " width="800" height="658"&gt;&lt;/a&gt;&lt;br&gt;
At first, Redis looks like a simple key-value store.&lt;/p&gt;

&lt;p&gt;But once you go deeper, you realize it’s built around multiple optimized data structures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Strings&lt;/strong&gt; → simple key-value&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hashes&lt;/strong&gt; → object-like storage&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lists&lt;/strong&gt; → queues / stacks&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sets&lt;/strong&gt; → unique collections&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sorted Sets&lt;/strong&gt; → ranking / leaderboards&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why This Matters
&lt;/h2&gt;

&lt;p&gt;Each data structure is designed for a specific use case.&lt;/p&gt;

&lt;p&gt;That’s why Redis is widely used for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;caching&lt;/li&gt;
&lt;li&gt;real-time leaderboards&lt;/li&gt;
&lt;li&gt;job queues&lt;/li&gt;
&lt;li&gt;session storage&lt;/li&gt;
&lt;li&gt;analytics&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The Real Insight
&lt;/h2&gt;

&lt;p&gt;The real power of Redis is not just speed.&lt;/p&gt;

&lt;p&gt;It’s the ability to choose the &lt;strong&gt;right data structure for the problem&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead of thinking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Where do I store this?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Start thinking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What structure fits this use case best?”&lt;/p&gt;
&lt;/blockquote&gt;




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

&lt;p&gt;Redis is not just a cache.&lt;/p&gt;

&lt;p&gt;It’s a &lt;strong&gt;data structure engine&lt;/strong&gt; that helps you design better systems.&lt;/p&gt;




&lt;h1&gt;
  
  
  redis #dsa #systemdesign #backend #programming
&lt;/h1&gt;

</description>
      <category>programming</category>
      <category>opensource</category>
      <category>redis</category>
      <category>coding</category>
    </item>
    <item>
      <title>🚨 Java &amp; JavaScript Are NOT Call by Reference</title>
      <dc:creator>CodeWithIshwar</dc:creator>
      <pubDate>Wed, 15 Apr 2026 17:16:28 +0000</pubDate>
      <link>https://dev.to/codewithishwar/-java-javascript-are-not-call-by-reference-33el</link>
      <guid>https://dev.to/codewithishwar/-java-javascript-are-not-call-by-reference-33el</guid>
      <description>&lt;p&gt;This is one of those concepts that seems obvious… until it breaks your code.&lt;/p&gt;

&lt;p&gt;Many developers believe:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Objects are passed by reference in Java or JavaScript”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;❌ That’s incorrect.&lt;/p&gt;

&lt;p&gt;👉 Both Java and JavaScript are strictly &lt;strong&gt;call by value&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Why This Feels Wrong
&lt;/h2&gt;

&lt;p&gt;If you’ve ever done this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function update(user):
    user.name = "Ishwar"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;…and seen the change reflected outside,&lt;br&gt;
it &lt;em&gt;feels&lt;/em&gt; like pass by reference.&lt;/p&gt;

&lt;p&gt;But then this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function reset(user):
    user = new Object()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Does nothing to the original.&lt;/p&gt;

&lt;p&gt;So what’s really going on?&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚙️ What’s Actually Happening
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Variables store &lt;strong&gt;values&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;For objects → that value is a &lt;strong&gt;reference (memory address)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 When calling a function:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;copy of that value&lt;/strong&gt; is passed&lt;/li&gt;
&lt;li&gt;Not the original variable&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔍 The Key Insight
&lt;/h2&gt;

&lt;p&gt;Inside the function:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You get a &lt;strong&gt;copy of the reference&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Both point to the same object → mutation works&lt;/li&gt;
&lt;li&gt;But reassignment only affects the local copy&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔁 Mental Model
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;original variable → copy value → function parameter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 You never get direct access to the original variable&lt;/p&gt;




&lt;h2&gt;
  
  
  📦 Stack vs Heap (Quick View)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Stack → variables (copies live here)&lt;/li&gt;
&lt;li&gt;Heap → actual objects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 You copy the &lt;strong&gt;reference value&lt;/strong&gt;, not the object&lt;/p&gt;




&lt;h2&gt;
  
  
  🌍 Applies Beyond Just Java
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Language&lt;/th&gt;
&lt;th&gt;Behavior&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Java&lt;/td&gt;
&lt;td&gt;Call by Value&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JavaScript&lt;/td&gt;
&lt;td&gt;Call by Value&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Python&lt;/td&gt;
&lt;td&gt;Call by Value (object ref)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C#&lt;/td&gt;
&lt;td&gt;Call by Value (default)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  💡 Final Takeaway
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Everything is pass by value.&lt;br&gt;
Some values just happen to be references.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🚀 Why This Matters
&lt;/h2&gt;

&lt;p&gt;This concept shows up in real-world bugs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Unexpected object mutations&lt;/li&gt;
&lt;li&gt;State issues in frontend apps&lt;/li&gt;
&lt;li&gt;Backend data inconsistencies&lt;/li&gt;
&lt;li&gt;API transformation bugs&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🤔 Discussion
&lt;/h2&gt;

&lt;p&gt;When did this finally click for you?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Early learning phase&lt;/li&gt;
&lt;li&gt;On the job&lt;/li&gt;
&lt;li&gt;Or after debugging something painful 😅&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Built for devs who like understanding &lt;em&gt;why&lt;/em&gt;, not just &lt;em&gt;what&lt;/em&gt;.&lt;br&gt;
More deep dives coming.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>opensource</category>
      <category>learning</category>
    </item>
    <item>
      <title>🚨 Java &amp; JavaScript Are NOT Call by Reference (Let’s Break This Myth)</title>
      <dc:creator>CodeWithIshwar</dc:creator>
      <pubDate>Wed, 15 Apr 2026 17:14:43 +0000</pubDate>
      <link>https://dev.to/codewithishwar/java-javascript-are-not-call-by-reference-lets-break-this-myth-2i3o</link>
      <guid>https://dev.to/codewithishwar/java-javascript-are-not-call-by-reference-lets-break-this-myth-2i3o</guid>
      <description>&lt;p&gt;One of the most common misconceptions in programming:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Objects are passed by reference in Java or JavaScript”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;❌ That’s not true.&lt;/p&gt;

&lt;p&gt;👉 Both &lt;strong&gt;Java&lt;/strong&gt; and &lt;strong&gt;JavaScript&lt;/strong&gt; are &lt;strong&gt;call by value&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Why the Confusion?
&lt;/h2&gt;

&lt;p&gt;Because when you pass objects into a function, changes sometimes reflect outside.&lt;/p&gt;

&lt;p&gt;That behavior &lt;em&gt;feels like&lt;/em&gt; call by reference… but it’s not.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚙️ What Actually Happens
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Every variable stores a &lt;strong&gt;value&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;For primitives → actual data&lt;/li&gt;
&lt;li&gt;For objects → &lt;strong&gt;memory address (reference)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 During a function call:&lt;br&gt;
➡️ A &lt;strong&gt;copy of that value&lt;/strong&gt; is passed&lt;/p&gt;




&lt;h2&gt;
  
  
  🔍 Two Cases That Explain Everything
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ✅ Case 1: Mutation (Works)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;change&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Ishwar&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// ✅ affects original&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✔️ Both variables point to the same object in memory&lt;br&gt;
✔️ Changes are visible&lt;/p&gt;




&lt;h3&gt;
  
  
  ❌ Case 2: Reassignment (Does NOT Work)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;reassign&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;New&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt; &lt;span class="c1"&gt;// ❌ does NOT affect original&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;❌ Only the local copy changes&lt;br&gt;
❌ Original remains unchanged&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚙️ The Algorithm Behind It
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Variable stores a value&lt;/li&gt;
&lt;li&gt;Function is called&lt;/li&gt;
&lt;li&gt;A new stack frame is created&lt;/li&gt;
&lt;li&gt;Parameters receive &lt;strong&gt;copy of argument values&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Function works on copied values&lt;/li&gt;
&lt;li&gt;Stack frame is destroyed&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🔁 Mental Model
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Caller Variable → Copy Value → Function Parameter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 No direct access to original variable&lt;br&gt;
👉 Only a copy is used&lt;/p&gt;




&lt;h2&gt;
  
  
  📦 Stack vs Heap (Simple View)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stack&lt;/strong&gt; → variables (copies live here)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Heap&lt;/strong&gt; → actual objects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 You copy the &lt;strong&gt;reference value&lt;/strong&gt;, not the object&lt;/p&gt;




&lt;h2&gt;
  
  
  🌍 Applies to Multiple Languages
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Language&lt;/th&gt;
&lt;th&gt;Behavior&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Java&lt;/td&gt;
&lt;td&gt;Call by Value&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JavaScript&lt;/td&gt;
&lt;td&gt;Call by Value&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Python&lt;/td&gt;
&lt;td&gt;Call by Value (object ref)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C#&lt;/td&gt;
&lt;td&gt;Call by Value (default)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  💡 Final Rule
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;“Everything is pass by value.&lt;br&gt;
Some values just happen to be references.”&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🚀 Why This Matters
&lt;/h2&gt;

&lt;p&gt;This concept helps avoid bugs in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Backend APIs&lt;/li&gt;
&lt;li&gt;State management (React, Redux)&lt;/li&gt;
&lt;li&gt;Object mutation issues&lt;/li&gt;
&lt;li&gt;System design&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🤔 Question for You
&lt;/h2&gt;

&lt;p&gt;When did this concept finally click for you?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;College?&lt;/li&gt;
&lt;li&gt;First job?&lt;/li&gt;
&lt;li&gt;Or after debugging a weird bug? 😅&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;💬 If this helped, drop a comment or share with someone who still thinks it's call by reference 😉&lt;/p&gt;

&lt;p&gt;#java #javascript #programming #coding #softwareengineering #webdev #beginners #devtips&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>coding</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
