<?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: Neha Sharma </title>
    <description>The latest articles on DEV Community by Neha Sharma  (@hellonehha).</description>
    <link>https://dev.to/hellonehha</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%2F118962%2F382c4db7-91d3-4e27-9cd5-a1e0331587b0.jpg</url>
      <title>DEV Community: Neha Sharma </title>
      <link>https://dev.to/hellonehha</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hellonehha"/>
    <language>en</language>
    <item>
      <title>How to Improve JavaScript Code's Performance</title>
      <dc:creator>Neha Sharma </dc:creator>
      <pubDate>Fri, 19 Dec 2025 07:56:11 +0000</pubDate>
      <link>https://dev.to/hellonehha/how-to-improve-javascript-codes-performance-2i7i</link>
      <guid>https://dev.to/hellonehha/how-to-improve-javascript-codes-performance-2i7i</guid>
      <description>&lt;p&gt;High-performance JavaScript is about predictability. Write code that is boring for humans but delightful for the JIT compiler.&lt;/p&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Performance is not magic. It's mechanical sympathy.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;p&gt;JavaScript performance optimization is not about micro-tweaks or premature cleverness. It's about understanding how the JavaScript engine, memory model, and runtime environment behave under pressure. This article focuses on high-impact optimizations grounded in engine internals, execution patterns, and production-grade scenarios.&lt;/p&gt;

&lt;h2&gt;
  
  
  1 . Understand the JavaScript Execution Model
&lt;/h2&gt;

&lt;p&gt;Modern JavaScript engines (V8, SpiderMonkey, JavaScriptCore) rely on Just-In-Time (JIT) compilation, Inline caching, Hidden classes / shapes ,Speculative optimizations&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Avoid De-Optimization Triggers&lt;/strong&gt;&lt;br&gt;
Engines optimize functions based on observed types. Changing types mid-execution forces de-optimization.&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;// Avoid this&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;sum&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="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;       &lt;span class="c1"&gt;// optimized for numbers&lt;/span&gt;
&lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// de-optimizes&lt;/span&gt;

&lt;span class="c1"&gt;// Do this&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Number&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&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;
  
  
  2 . Shape Stability and Object Access
&lt;/h2&gt;

&lt;p&gt;JavaScript objects use hidden classes. Mutating object structure dynamically prevents property access optimization. When iterating over large datasets, stable shapes can yield 20–50% performance improvements.&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;// Avoid this&lt;/span&gt;
&lt;span class="kd"&gt;const&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="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;Alice&lt;/span&gt;&lt;span class="dl"&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;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&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;isAdmin&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="c1"&gt;// Do this&lt;/span&gt;
&lt;span class="kd"&gt;const&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;Alice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;isAdmin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3 . Minimize Garbage Collection Pressure
&lt;/h2&gt;

&lt;p&gt;Garbage Collection (GC) pauses execution. High allocation rates cause frequent GC cycles. Avoid Unnecessary Allocations in Hot Paths&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;// Excessive Allocation&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;items&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="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
  &lt;span class="p"&gt;}));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Object Reuse&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;process&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;items&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;result&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;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;for &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;i&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="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&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="nx"&gt;result&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;
  
  
  4 . Prefer Iterative Loops Over Abstractions in Hot Code
&lt;/h2&gt;

&lt;p&gt;Functional methods (map, reduce, filter) are expressive-but slower in critical paths.&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;// Avoid this&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;prices&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;1.2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Optimized Loop&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;total&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;for &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;i&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="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;prices&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;prices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&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="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;1.2&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;
  
  
  5 . Async Performance: Avoid Accidental Serialization
&lt;/h2&gt;

&lt;p&gt;async/await can introduce hidden performance bottlenecks when misused. This change alone can reduce execution time from O(n × latency) to O(max latency).&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;// Serialized Execution&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;fetchAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;urls&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;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
  &lt;span class="k"&gt;for &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;url&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;urls&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;results&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="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&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="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Parallel Execution&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;fetchAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;urls&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="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;urls&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fetch&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;
  
  
  6 . Memoization and Cache Invalidation
&lt;/h2&gt;

&lt;p&gt;Avoid recomputation for deterministic, expensive functions. Memoization must be paired with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cache size limits&lt;/li&gt;
&lt;li&gt;Clear invalidation rules&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Otherwise, memory leaks will offset performance gains&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;cache&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;Map&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;expensiveCalc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&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="nx"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;cache&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="nx"&gt;n&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;result&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;for &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;i&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="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="nx"&gt;e6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&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="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;cache&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="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;result&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;
  
  
  7 . DOM and Browser Performance: Batch Everything
&lt;/h2&gt;

&lt;p&gt;DOM access is orders of magnitude slower than pure JS.&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;// Avoid this (Layout Thrashing)&lt;/span&gt;
&lt;span class="nx"&gt;elements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;offsetWidth&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;px&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// Do this ; This prevents forced synchronous reflows.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;widths&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;elements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;offsetWidth&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;elements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;widths&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;px&lt;/span&gt;&lt;span class="dl"&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;
  
  
  8 . Measure, Don't Guess
&lt;/h2&gt;

&lt;p&gt;There are tools, and API available to measure performance. These will give engineer context what to fix. Optimization without measurement is cargo cult engineering .Use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;performance.now()&lt;/li&gt;
&lt;li&gt;Chrome DevTools Performance tab&lt;/li&gt;
&lt;li&gt;Node.js --prof&lt;/li&gt;
&lt;li&gt;Flamegraphs
&lt;/li&gt;
&lt;/ul&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;start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;performance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// critical code&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;performance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Execution: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;ms`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your code either cooperates with these systems or actively fights them. Stable types, stable shapes, controlled memory allocation, and intentional async behavior allow engines to optimize aggressively.&lt;/p&gt;




&lt;p&gt;If you liked this then you will like my other writings too. If you found something to be fixed/added then let me know in comments. Don’t be a stranger and say hi — &lt;a href="https://www.linkedin.com/in/nehha/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt; , &lt;a href="https://x.com/hellonehha" rel="noopener noreferrer"&gt;X&lt;/a&gt; and &lt;a href="https://nehasharma.dev/" rel="noopener noreferrer"&gt;NehaSharma.dev&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>performance</category>
      <category>programming</category>
    </item>
    <item>
      <title>I Passed the AWS AI Practitioner Exam!</title>
      <dc:creator>Neha Sharma </dc:creator>
      <pubDate>Mon, 08 Dec 2025 19:06:54 +0000</pubDate>
      <link>https://dev.to/hellonehha/i-passed-the-aws-ai-practitioner-exam-14ni</link>
      <guid>https://dev.to/hellonehha/i-passed-the-aws-ai-practitioner-exam-14ni</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Yay! I passed the AWS AI Practitioner exam.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Every year I set a few personal goals and try my best to hit them. For 2025, one of my goals was to get 2–3 certifications. That didn’t quite happen (hello, procrastination 👀), so before 2025 ends I was determined to at least get one done.&lt;/p&gt;

&lt;p&gt;With all the AI buzz around me, the AWS GenAI Practitioner felt like the perfect place to start.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preparing for the Exam
&lt;/h2&gt;

&lt;p&gt;I started with the official website of AWS certification to understand exam’s outline, areas of topics with percentage to focus on.&lt;/p&gt;

&lt;p&gt;Once I knew what to expect, I used the following study materials:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://youtu.be/WZeZZ8_W-M4?si=jVhkI-MXLbHQl_8l" rel="noopener noreferrer"&gt;Freecodecamp YouTube Video by Andrew Brown&lt;/a&gt; watched 2 times&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.udemy.com/course/practice-exams-aws-certified-ai-practitioner" rel="noopener noreferrer"&gt;Udemy mock exam&lt;/a&gt; from Stéphane Maarek&lt;/li&gt;
&lt;li&gt;ChatGPT (my beloved teacher)&lt;/li&gt;
&lt;li&gt;Hands-on (optional)&lt;/li&gt;
&lt;li&gt;Internal office videos&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How I Studied With a Full-Time Job (Without Losing Sleep)
&lt;/h2&gt;

&lt;p&gt;I already had some background in AI, LLMs, and transformer architecture, which definitely worked in my favour.&lt;/p&gt;

&lt;p&gt;The most important thing I did was — I booked the exam date. (&lt;em&gt;In Amazon we have the leadership principle of “working backwards&lt;/em&gt;”); this approach has always worked great for me. Once the date was locked in, I had a clear deadline, a stronger reason to focus, and a deadline to finish my content.&lt;/p&gt;

&lt;h2&gt;
  
  
  My Daily Study Routine
&lt;/h2&gt;

&lt;p&gt;I dedicated 30 mins to 1 hour daily to watch the YouTube Video. Spent 1–2 weeks to digest the concepts (I was not able to digest the content 100% ). So, I moved to taking mock exams.&lt;/p&gt;

&lt;h2&gt;
  
  
  First Mock Test (Reality Check)
&lt;/h2&gt;

&lt;p&gt;I took my first Udemy mock test and scored 60% which meant I failed. Instead of getting discouraged, I reviewd all the wrong questions, I used chatGPT, or youtube to get my concepts clear. I started passing the mock exam (good sign). This was my routine.&lt;/p&gt;

&lt;p&gt;A few weeks ago before exam date, I got access to internal videos on GenAI. These videos helped me in revising the all concepts and I made lot of notes.&lt;/p&gt;

&lt;p&gt;The day before the exam, I took the 4th Udemy mock test (which I had intentionally saved for the end), just to see where I stood and I passed that too. For extra confidence, I even did one more random mock after that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Timelines
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Sep&lt;/strong&gt; : started but was not consistent&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Oct and Nov&lt;/strong&gt; :I try to be consistent with my study. I went on 2 weeks travel and then fall sick for a week. So I basically lost around 3 weeks in between&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Exam Scheduled for 7th Dec&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Study 30 mins to 1 hr daily&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Exam Day
&lt;/h2&gt;

&lt;p&gt;Initially, I booked my exam for 7th December, but due to travel I brought it forward by a week and took it from home 29th Nov.&lt;/p&gt;

&lt;p&gt;There were 65 questions and mix of mult-choice, and match the right options. For me time management is not any issue. So, I was not concerned about the time.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;tip: please login 30 mins before. They put you in the queue to scan your docs, and rooms.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Exam was straight forward. Questions were aligned to Udemy mock exams. No surprise there at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Now what?
&lt;/h2&gt;

&lt;p&gt;Celebration and relaxation for now. Will start preparing for a new certificate soon.&lt;/p&gt;

&lt;p&gt;Have questions? or just want to say? You can connect with me at &lt;a href="http://www.x.com/hellonehha" rel="noopener noreferrer"&gt;X&lt;/a&gt; or &lt;a href="https://www.linkedin.com/in/nehha/" rel="noopener noreferrer"&gt;Linkedln&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>aws</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Object-Oriented JavaScript: A Practical Guide with Examples</title>
      <dc:creator>Neha Sharma </dc:creator>
      <pubDate>Sat, 20 Sep 2025 20:41:00 +0000</pubDate>
      <link>https://dev.to/hellonehha/object-oriented-javascript-a-practical-guide-with-examples-10d</link>
      <guid>https://dev.to/hellonehha/object-oriented-javascript-a-practical-guide-with-examples-10d</guid>
      <description>&lt;p&gt;If you’ve been programming for a decade or you’re just getting started, you’ve probably heard of OOP (Object-Oriented Programming). It’s a powerful paradigm that support many modern programming languages, from Java to C#.&lt;/p&gt;

&lt;p&gt;But when it comes to JavaScript, things are interesting. JavaScript wasn’t originally built with classes in mind—it was designed as a lightweight scripting language for browsers. Over time, as web applications became more complex, JavaScript evolved. Today, with ES6 and beyond, it supports OOP-like patterns while still being fundamentally prototype-based under the hood.&lt;/p&gt;

&lt;p&gt;In this blog, we’ll explore:&lt;/p&gt;

&lt;p&gt;1 . What OOP is&lt;/p&gt;

&lt;p&gt;2 . The core concepts of OOP&lt;/p&gt;

&lt;p&gt;3 . How OOP is implemented in JavaScript&lt;/p&gt;

&lt;p&gt;4 . A real-world example you probably already use&lt;/p&gt;

&lt;h2&gt;
  
  
  What is OOP?
&lt;/h2&gt;

&lt;p&gt;Object-Oriented Programming is a paradigm that organizes code around objects. &lt;em&gt;An object represents a real-world entity (like a user, product, or order) and bundles both data (properties) and behavior (methods) together.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;In programming, we treat every thing :&lt;/p&gt;

&lt;p&gt;As a JavaScript developer, you can think of an object as a collection of related &lt;em&gt;data&lt;/em&gt; and &lt;em&gt;behavior&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;An object is made up of:&lt;/p&gt;

&lt;p&gt;1 . &lt;strong&gt;Properties (data)&lt;/strong&gt;: key–value pairs (like variables inside the object).&lt;/p&gt;

&lt;p&gt;2 . &lt;strong&gt;Methods (behavior)&lt;/strong&gt;: functions stored as properties, which define what the object can do.&lt;/p&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;In simple terms: A property describes what it has and a method describes what it does.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Benefits of OOP:
&lt;/h3&gt;

&lt;p&gt;1 . &lt;strong&gt;Reusability:&lt;/strong&gt; Write once, use across projects.&lt;/p&gt;

&lt;p&gt;2 . &lt;strong&gt;Encapsulation:&lt;/strong&gt; Hide implementation details, expose only what matters.&lt;/p&gt;

&lt;p&gt;3 . &lt;strong&gt;Maintainability:&lt;/strong&gt; Easier to update and extend.&lt;/p&gt;

&lt;p&gt;4 . &lt;strong&gt;Abstraction:&lt;/strong&gt; Focus on “what” an object does, not “how” it does it.&lt;/p&gt;

&lt;p&gt;5 . &lt;strong&gt;Polymorphism:&lt;/strong&gt; Same method name, different behavior depending on context.&lt;/p&gt;

&lt;h2&gt;
  
  
  Concpets in OOP
&lt;/h2&gt;

&lt;p&gt;1 . Object&lt;/p&gt;

&lt;p&gt;2 . Class &amp;amp; constructors&lt;/p&gt;

&lt;p&gt;3 . Inheritance&lt;/p&gt;

&lt;p&gt;4 . Polymorphism &lt;/p&gt;

&lt;p&gt;5 . Abstraction&lt;/p&gt;

&lt;p&gt;6 . Encapsulation&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript and OOPs concept
&lt;/h2&gt;

&lt;p&gt;In Modern JavaScript, we can implement OOP concepts. As an engineer, you should have the goal of using OOP for various benefits. Eg: for reusability, encapsulation, inheritance, and so on. Remember these are the programming goals you should as an progarmmer you should have goals.&lt;/p&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Do we need to implement all these concepts? No..but as needed.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

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

&lt;p&gt;Objects are the foundation of OOP. In JavaScript, before modern JavaScript we used to refer JavaScript as prototypal scripting language. As everything used to be done through prototype.  In JavaScript, we make an object like this. Now, from JS pov, why this is important. As it helps in have a strucuture your code , data, properties and methods.&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;// creating an object in JavaScript&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;brand&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tesla&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// data&lt;/span&gt;
  &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Model 3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// data &lt;/span&gt;
  &lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// method &lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&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;brand&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;model&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is driving...`&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="nx"&gt;car&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Tesla Model 3 is driving...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The “Car” example explains OOP well, but it doesn’t feel very connected to everyday JavaScript work. So let’s model something practical—a carousel. In JavaScript, we can represent a carousel as an object.&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;// Creating a Carousel using object&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Carousel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;images&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;image1.jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;image2.jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;image3.jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; 
  &lt;span class="na"&gt;style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;default&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                                   

  &lt;span class="nf"&gt;createCarousel&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;                                  
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Carousel created with images:&lt;/span&gt;&lt;span class="dl"&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;images&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;

  &lt;span class="nf"&gt;nextImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Showing:&lt;/span&gt;&lt;span class="dl"&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;images&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;index&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;images&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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="c1"&gt;// Using the object&lt;/span&gt;
&lt;span class="nx"&gt;Carousel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createCarousel&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  2 . Classes &amp;amp; Constructors
&lt;/h3&gt;

&lt;p&gt;Before ES6, JavaScript didn’t have the &lt;code&gt;class&lt;/code&gt; or &lt;code&gt;constructor&lt;/code&gt; keywords.&lt;br&gt;&lt;br&gt;
Developers who came from languages like Java or PHP often mimicked these concepts using functions and prototypes.  &lt;/p&gt;

&lt;p&gt;With ES6, JavaScript introduced the &lt;code&gt;class&lt;/code&gt; syntax.  &lt;/p&gt;

&lt;p&gt;It doesn’t add new functionality under the hood — classes are &lt;strong&gt;syntactic sugar over prototypes&lt;/strong&gt; — but it makes object-oriented code more readable and familiar.  &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;constructor&lt;/code&gt; is a special method that runs automatically when you create a new instance of a class.  &lt;/p&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;Class&lt;/code&gt; and &lt;code&gt;constructors&lt;/code&gt; form the foundation for the rest of the OOP concepts we’ll cover — from inheritance to abstraction.&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;
&lt;br&gt;
&lt;/blockquote&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;Car&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="nx"&gt;brand&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;model&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;brand&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;brand&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;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&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;brand&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;model&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is driving...`&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myCar&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;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tesla&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Model Y&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;myCar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Tesla Model Y is driving...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;Car&lt;/code&gt; is a class, and the constructor sets up its properties. When we call new Car("Tesla", "Model Y"), the constructor runs automatically.&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;class&lt;/span&gt; &lt;span class="nc"&gt;Carousel&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="nx"&gt;items&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;items&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;currentIndex&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="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;showCurrent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Showing: &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;items&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;currentIndex&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="s2"&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;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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentIndex&lt;/span&gt; &lt;span class="o"&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;currentIndex&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="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;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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="nf"&gt;showCurrent&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;prev&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;currentIndex&lt;/span&gt; &lt;span class="o"&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;currentIndex&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&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;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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="nf"&gt;showCurrent&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;goTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;index&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="nx"&gt;index&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="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&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;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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;currentIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;index&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="nf"&gt;showCurrent&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Invalid index&lt;/span&gt;&lt;span class="dl"&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="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;carousel&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;Carousel&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;img1.jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;img2.jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;img3.jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="nx"&gt;carousel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;showCurrent&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
&lt;span class="nx"&gt;carousel&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="nx"&gt;carousel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;goTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;      

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

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;Carousel&lt;/code&gt; organizes state (&lt;code&gt;items&lt;/code&gt;, &lt;code&gt;currentIndex&lt;/code&gt;) and exposes methods to control the slideshow. The constructor ensures every new carousel starts in a valid state.&lt;/p&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Classes and constructors in ES6 make object-oriented JavaScript cleaner and more intuitive, while still being powered by the prototype system under the hood.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  3 . Inheritance (Prototypes)
&lt;/h3&gt;

&lt;p&gt;Inheritance allows a child class to reuse and extend functionality from a parent class.  It supports the DRY (Don’t Repeat Yourself) principle by letting you share code instead of duplicating it.  &lt;/p&gt;

&lt;p&gt;In JavaScript, inheritance was originally implemented using &lt;strong&gt;prototypes&lt;/strong&gt;.  Since ES6, we have the &lt;code&gt;class&lt;/code&gt; syntax, which makes inheritance much more intuitive though under the hood, it still uses prototypes.&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;class&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&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="nx"&gt;type&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;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&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;type&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is starting...`&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&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="nx"&gt;brand&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Car&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// call parent constructor&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;brand&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;brand&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// method overriding&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&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;brand&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;type&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is revving up!`&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myCar&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;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Tesla&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;myCar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Tesla Car is revving up!&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;Car&lt;/code&gt; inherits from &lt;code&gt;Vehicle&lt;/code&gt; and reuses its constructor logic. It also overrides the &lt;code&gt;start()&lt;/code&gt; method to provide custom behavior.&lt;/p&gt;

&lt;p&gt;Suppose we have a base &lt;code&gt;Carousel&lt;/code&gt; class. We can extend it to create specialized carousels with extra features like styles or auto-scroll.&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;class&lt;/span&gt; &lt;span class="nc"&gt;Carousel&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="nx"&gt;items&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;items&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;currentIndex&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="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;showCurrent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Showing: &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;items&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;currentIndex&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="s2"&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;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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;currentIndex&lt;/span&gt; &lt;span class="o"&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;currentIndex&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="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;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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="nf"&gt;showCurrent&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ImageCarousel&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Carousel&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="nx"&gt;images&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;default&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;images&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// call parent constructor&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;style&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;showCurrent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// override method&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="s2"&gt;`Displaying image [&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;style&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; style]: &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;items&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;currentIndex&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="s2"&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;imgCarousel&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;ImageCarousel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;img1.jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;img2.jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;img3.jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dark&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;imgCarousel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;showCurrent&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
&lt;span class="nx"&gt;imgCarousel&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;ImageCarousel&lt;/code&gt; extends &lt;code&gt;Carousel&lt;/code&gt;, reusing its logic for navigation, but overrides &lt;code&gt;showCurrent()&lt;/code&gt; to add styling context.&lt;/p&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Inheritance lets you reuse and extend base functionality. Overriding allows subclasses to adapt behavior to their needs.&lt;br&gt;
Even with ES6 classes, JavaScript’s inheritance model is still prototype based under the hood.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  4 . Polymorphism
&lt;/h3&gt;

&lt;p&gt;Polymorphism allows different classes to define their own versions of the same method. In practice, a child class can &lt;strong&gt;override&lt;/strong&gt; a method from its parent class to provide specialized behavior.&lt;/p&gt;

&lt;p&gt;Polymorphism and inheritance often go hand in hand:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Inheritance&lt;/strong&gt; lets you reuse a base structure (&lt;code&gt;Vehicle&lt;/code&gt; → &lt;code&gt;Car&lt;/code&gt;, &lt;code&gt;Bike&lt;/code&gt;).  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Polymorphism&lt;/strong&gt; lets each subclass override behavior to suit its needs.  &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you’re ever confused:  &lt;em&gt;Inheritance = reusing code&lt;/em&gt; and &lt;em&gt;Polymorphism = redefining behavior.&lt;/em&gt;&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;class&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;This vehicle is moving...&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Car is driving on the road...&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Bike&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bike is zooming through traffic...&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myCar&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;Car&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;myBike&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;Bike&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;myCar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Car is driving on the road...&lt;/span&gt;
&lt;span class="nx"&gt;myBike&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Bike is zooming through traffic...&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In our caraousel example&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;class&lt;/span&gt; &lt;span class="nc"&gt;Carousel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Showing carousel item...&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ImageCarousel&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Carousel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Displaying an image slide...&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;VideoCarousel&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Carousel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Playing a video slide...&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;imgCarousel&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;ImageCarousel&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;vidCarousel&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;VideoCarousel&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;imgCarousel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Displaying an image slide...&lt;/span&gt;
&lt;span class="nx"&gt;vidCarousel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Playing a video slide...&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Here, both &lt;code&gt;ImageCarousel&lt;/code&gt; and &lt;code&gt;VideoCarousel&lt;/code&gt; extend the same &lt;code&gt;Carousel&lt;/code&gt; base class, but each redefines the &lt;code&gt;show()&lt;/code&gt; method — this is polymorphism in action.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Abstraction
&lt;/h3&gt;

&lt;p&gt;Abstraction is about &lt;strong&gt;hiding implementation details&lt;/strong&gt; and exposing only what’s necessary.  It lets you define a &lt;em&gt;contract&lt;/em&gt; (what methods must exist) without forcing subclasses to care about &lt;em&gt;how&lt;/em&gt; they’re implemented.  &lt;/p&gt;

&lt;p&gt;JavaScript doesn’t have native &lt;a href="https://www.w3schools.com/java/java_abstract.asp" rel="noopener noreferrer"&gt;abstract classes&lt;/a&gt; like Java or C#, but we can simulate abstraction by: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Throwing errors in base methods that must be overridden.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using documentation or patterns to enforce a contract.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&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;Vehicle&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Method 'start()' must be implemented&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Car engine started...&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Bike&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Vehicle&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bike engine started...&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myCar&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;Car&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;myBike&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;Bike&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;myCar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Car engine started...&lt;/span&gt;
&lt;span class="nx"&gt;myBike&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Bike engine started...&lt;/span&gt;


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

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;Vehicle&lt;/code&gt; enforces that every subclass must define &lt;code&gt;start()&lt;/code&gt;, but the actual implementation is left to &lt;code&gt;Car&lt;/code&gt; and &lt;code&gt;Bike&lt;/code&gt;.&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;class&lt;/span&gt; &lt;span class="nc"&gt;BaseCarousel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Method 'render()' must be implemented&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ImageCarousel&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;BaseCarousel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Rendering image carousel...&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;VideoCarousel&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;BaseCarousel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Rendering video carousel...&lt;/span&gt;&lt;span class="dl"&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;imgCarousel&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;ImageCarousel&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;vidCarousel&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;VideoCarousel&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;imgCarousel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Rendering image carousel...&lt;/span&gt;
&lt;span class="nx"&gt;vidCarousel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Rendering video carousel...&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;BaseCarousel&lt;/code&gt; defines the abstract method &lt;code&gt;render()&lt;/code&gt;. Every type of carousel must implement it, but how it renders (images, videos, etc.) is up to the subclass.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Encapsulation
&lt;/h3&gt;

&lt;p&gt;Encapsulation is about &lt;strong&gt;hiding internal details&lt;/strong&gt; and exposing only what’s necessary through a public API.  It prevents direct access to an object’s state, which makes code more secure, modular, and maintainable.  &lt;/p&gt;

&lt;p&gt;In modern JavaScript (ES2022+), we can achieve encapsulation using &lt;strong&gt;private fields&lt;/strong&gt; (denoted by &lt;code&gt;#&lt;/code&gt;), getters, and setters.&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;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;fuel&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="c1"&gt;// private field&lt;/span&gt;

  &lt;span class="nf"&gt;refuel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;liters&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="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;fuel&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;liters&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Added &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;liters&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;L of fuel.`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;drive&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="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;fuel&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;fuel&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Car is driving...&lt;/span&gt;&lt;span class="dl"&gt;"&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;No fuel left!&lt;/span&gt;&lt;span class="dl"&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;getFuelLevel&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;fuel&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myCar&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;Car&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;myCar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;refuel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;myCar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drive&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Car is driving...&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myCar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getFuelLevel&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="c1"&gt;// myCar.#fuel (Error: private field)&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The car’s fuel state is hidden. You can only change it through &lt;code&gt;refuel()&lt;/code&gt; and check it with &lt;code&gt;getFuelLevel()&lt;/code&gt;.&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;class&lt;/span&gt; &lt;span class="nc"&gt;Carousel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;currentIndex&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="c1"&gt;// private field&lt;/span&gt;

  &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;items&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;;&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;currentIndex&lt;/span&gt; &lt;span class="o"&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="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;currentIndex&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="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;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;prev&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="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;currentIndex&lt;/span&gt; &lt;span class="o"&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="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;currentIndex&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&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;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Showing: &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;items&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="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;currentIndex&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;&lt;span class="s2"&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;getCurrentIndex&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;currentIndex&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;carousel&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;Carousel&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;img1.jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;img2.jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;img3.jpg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="nx"&gt;carousel&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="c1"&gt;// Showing: img2.jpg&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;carousel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getCurrentIndex&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="c1"&gt;// carousel.#currentIndex ❌ (Error: private field)&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The carousel’s internal state (&lt;code&gt;#currentIndex&lt;/code&gt;) is private. Consumers can only change slides via &lt;code&gt;next()&lt;/code&gt; / &lt;code&gt;prev()&lt;/code&gt; and can’t tamper with the internals directly.&lt;/p&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Encapsulation protects internal state and provides a clear, safe API for interaction. This reduces bugs and makes codebases easier to evolve without breaking consumers.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Bringing It All Together
&lt;/h2&gt;

&lt;p&gt;Let’s combine what we’ve learned so far: &lt;strong&gt;classes, constructors, inheritance, and polymorphism&lt;/strong&gt; into one example.&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;class&lt;/span&gt; &lt;span class="nc"&gt;User&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="nx"&gt;name&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;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hello, I’m &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;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Admin&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// method overriding (polymorphism)&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`👋 Admin &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;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; here. I manage the system.`&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;normalUser&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;User&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alice&lt;/span&gt;&lt;span class="dl"&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;adminUser&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;Admin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;normalUser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// Hello, I’m Alice&lt;/span&gt;
&lt;span class="nx"&gt;adminUser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;  &lt;span class="c1"&gt;// 👋 Admin Bob here. I manage the system.&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Real world example
&lt;/h2&gt;

&lt;p&gt;If you’ve worked with React, you’ve already used OOP principles. Before hooks become popular, we were using OOPs to make class based components. If you are someone who is working in building libraries or polyfills then you will be using OOPs a lot.&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Base Component&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Button&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;render&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&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;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Specialized Component (Inheritance + Polymorphism)&lt;/span&gt;
&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;IconButton&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;render&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="p"&gt;(&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt; &lt;span class="nx"&gt;role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;img&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;aria&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;icon&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="err"&gt;🔍&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&amp;gt;{" "&lt;/span&gt;&lt;span class="err"&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;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&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="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt; &lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Click Me&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;IconButton&lt;/span&gt; &lt;span class="nx"&gt;label&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Search&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;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;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;OOPs in JavaScript are important to write clean and maintainable code. OOPs also promotes Solid prinicples of programming. &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;OOP concept&lt;/th&gt;
&lt;th&gt;What/Why&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Object&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A collection of related data (properties) and behavior (methods). Organizes code into real-world entities. Promotes Single Responsiblity Model (SRE) and Keep it simple silly (KISS)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Class &amp;amp; Constructor&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A blueprint for creating objects. The constructor sets initial state when creating an instance.Provides structure, consistency, and easier instantiation of objects.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Inheritance&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A child class reuses and extends functionality from a parent class. Promotes DRY principle, code reuse, and logical hierarchies.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Polymorphism&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Child classes override or redefine parent methods with their own behavior. Flexibility: same method name, different outcomes depending on context.Promotes Open/Closed Principle&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Abstraction&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Hides implementation details and exposes only required functionality. Simulated in JS via base classes that throw errors. Defines clear contracts while allowing flexible implementations. Promotes KISS, and Interface Segregation Principle&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Encapsulation&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Restricting direct access to internal state; exposing it through public methods.Improves maintainability, security, and prevents unintended interference. Promotes SRP, Low Coupling / High Cohesion&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;I hope this help you to write your clean, and better code in your next project. If you like it then do share to your social media - &lt;a href="https://x.com/hellonehha" rel="noopener noreferrer"&gt;X&lt;/a&gt;, &lt;a href="https://www.linkedin.com/in/nehha/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;. &lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>AI vs ML vs MLOps: A Developer’s Roadmap to Getting Started</title>
      <dc:creator>Neha Sharma </dc:creator>
      <pubDate>Sat, 30 Aug 2025 14:56:47 +0000</pubDate>
      <link>https://dev.to/hellonehha/ai-vs-ml-vs-mlops-a-developers-roadmap-to-getting-started-14pi</link>
      <guid>https://dev.to/hellonehha/ai-vs-ml-vs-mlops-a-developers-roadmap-to-getting-started-14pi</guid>
      <description>&lt;p&gt;If you’re asking yourself, “Where do I even start in AI engineering?” — you’re not alone. The landscape is crowded with buzzwords (AI, ML, DL, GenAI, MLOps), and it’s easy to feel lost. A few months ago, I had the same question: &lt;em&gt;Where should I begin — AI, ML, or infrastructure?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So, I went back to step zero to get clarity. In today’s blog, we’ll unpack the differences between AI and ML, and how to decide where to start.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Big Picture: AI, ML, and DL
&lt;/h2&gt;

&lt;p&gt;You’ve probably seen the classic diagram that looks like nested circles. To understand from where to start in AI domain understanding this diagram will help you a lot. Let’s put some meaning behind it:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmwrp0bupwgy60cus1cuh.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%2Fmwrp0bupwgy60cus1cuh.png" alt=" " width="706" height="722"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. AI (Artificial Intelligence)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;From a 10,000-foot view, AI is about building systems that mimic human-like intelligence. This includes everything from rule based expert systems companies used to today’s generative AI models.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. ML (Machine Learning)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A subset of AI. Instead of writing explicit rules, ML systems learn from data to make predictions or classifications. &lt;em&gt;eg, predicting house prices based on location, size, and historical sales.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. DL (Deep Learning)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A subset of ML that uses artificial neural networks with multiple layers. Deep learning shines when you have massive datasets and GPU/TPU hardware. &lt;em&gt;eg, computer vision (image recognition), natural language processing (chatbots, LLMs), and speech recognition.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4kd0a5wnc7nzpfv02gtg.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%2F4kd0a5wnc7nzpfv02gtg.png" alt=" " width="800" height="651"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The common thread across all three? &lt;strong&gt;Data.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No matter which path you choose — AI applications, ML models, or deep neural networks — everything starts with clean, structured, and sufficient data. In short: data is the new oil.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Developer’s Perspective
&lt;/h2&gt;

&lt;p&gt;As engineers, the question becomes: which domain should you pick — AI, ML, or DL? To decide, let’s break it down layer by layer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. AI → Application Layer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Leveraging pre-trained or foundation models (OpenAI GPT, Claude, Gemini, Llama 3, etc.) to build intelligent applications. Most GenAI startups fall into this category.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tech stack examples:&lt;/strong&gt; LangChain, LlamaIndex, Pinecone, FAISS, Hugging Face APIs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. ML/DL → Model Building Layer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Training your own models from scratch or fine-tuning existing ones. This requires understanding algorithms, data preprocessing, feature engineering, and evaluation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tech stack examples:&lt;/strong&gt; Scikit-learn, TensorFlow, PyTorch, Hugging Face Transformers, Weights &amp;amp; Biases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. MLOps → Infra → Scaling Layer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Making sure models don’t just work on your laptop but actually run in production at scale. Think data pipelines, CI/CD, model monitoring, GPU clusters, and distributed systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tech stack examples:&lt;/strong&gt; Kubernetes, Airflow, MLflow, Kubeflow, Amazon SageMaker, Ray, Docker.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fohwyu9klmcbotqm3xtrb.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%2Fohwyu9klmcbotqm3xtrb.png" alt=" " width="800" height="919"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing Your Path
&lt;/h2&gt;

&lt;p&gt;Here’s the practical decision-making guide:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Want to build cool apps quickly?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start with AI (application layer). You’ll work with APIs, prompt engineering, and frameworks like LangChain to turn pre-trained models into usable apps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fascinated by algorithms, optimisation, and math?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Go deeper into ML/DL. You’ll learn to design neural networks, tune hyperparameters, and explore architectures like CNNs, RNNs, and Transformers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Love DevOps, cloud, and distributed systems?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Explore MLOps / infra. This path is about ensuring reliability, scalability, and automation of AI/ML workflows.&lt;/p&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;You don’t need to learn ML/DL before touching AI applications. In fact, many developers jump straight into building AI-powered apps first, then circle back to ML theory once they want more control.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhriw7t4kedkl6klqop31.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%2Fhriw7t4kedkl6klqop31.png" alt=" " width="800" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How day-to-day work looks?
&lt;/h2&gt;

&lt;p&gt;Let’s break down the day-to-day work across each role.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. AI Engineering (Application Layer)
&lt;/h3&gt;

&lt;p&gt;You have a product idea (eg, builiding a chatbot that answers customer queries by combining OpenAI GPT with your company’s documents (RAG pipeline).) and now as an AI engineer you will: &lt;/p&gt;

&lt;p&gt;1 . Choosing and integrating pre-trained models (GPT, Stable Diffusion, Whisper).&lt;/p&gt;

&lt;p&gt;2 . Building workflows around LLMs (RAG, agents, tool use).&lt;/p&gt;

&lt;p&gt;3 . Handling prompt engineering, context windows, embeddings, and vector databases.&lt;/p&gt;

&lt;p&gt;4 . Scaling apps to handle real-world usage.&lt;/p&gt;

&lt;p&gt;5 . Considering hardware and latency constraints (e.g., running on GPU vs CPU, on-device inference).&lt;/p&gt;

&lt;h3&gt;
  
  
  2. ML/DL Engineering (Model Building Layer)
&lt;/h3&gt;

&lt;p&gt;You are building, training, and testing models (&lt;em&gt;e.g, Train a deep learning model to classify writing into shakespear vs not-shakespear using PyTorch and fine-tuning ResNet.&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;1 . Collecting, cleaning, and annotating datasets.&lt;/p&gt;

&lt;p&gt;2 . Splitting data into train/validation/test sets.&lt;/p&gt;

&lt;p&gt;3 . Feature engineering (normalisation, categorical encoding).&lt;/p&gt;

&lt;p&gt;4 . Training models (RandomForest, Logistic Regression, or Transformers).&lt;/p&gt;

&lt;p&gt;5 . Hyperparameter tuning (Grid Search, Bayesian optimisation).&lt;/p&gt;

&lt;p&gt;6 . Evaluating with metrics (accuracy, F1, ROC-AUC, BLEU).&lt;/p&gt;

&lt;p&gt;7 . Optimising for inference speed and resource usage.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. MLOps / Infra Engineering (Scaling Layer)
&lt;/h3&gt;

&lt;p&gt;You are an engineer who is working with DL or AI engineers. &lt;em&gt;eg Build an ML training pipeline with Airflow that trains models nightly, logs metrics to MLflow, and deploys the best-performing version to Kubernetes.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;1 . Automating data ingestion with ETL pipelines.&lt;/p&gt;

&lt;p&gt;2 . Containerising models with Docker.&lt;/p&gt;

&lt;p&gt;3 . Orchestrating workflows with Airflow or Prefect.&lt;/p&gt;

&lt;p&gt;4 . Deploying models to Kubernetes or SageMaker endpoints.&lt;/p&gt;

&lt;p&gt;5 . Monitoring for data drift and model degradation.&lt;/p&gt;

&lt;p&gt;6 . Handling distributed training (Horovod, Ray).&lt;/p&gt;

&lt;p&gt;7 . Ensuring reproducibility (MLflow, DVC, GitHub Actions).&lt;/p&gt;

&lt;h2&gt;
  
  
  The Hardware Angle
&lt;/h2&gt;

&lt;p&gt;Another important dimension is compute infrastructure:&lt;/p&gt;

&lt;p&gt;1 . &lt;strong&gt;AI Applications:&lt;/strong&gt; Often run on cloud APIs. You don’t worry much about GPUs, unless you want to self-host.&lt;/p&gt;

&lt;p&gt;2 . &lt;strong&gt;ML/DL Models:&lt;/strong&gt; Training deep networks can require powerful GPUs/TPUs (NVIDIA A100, H100, TPU v5).&lt;/p&gt;

&lt;p&gt;3 . &lt;strong&gt;MLOps:&lt;/strong&gt; Involves managing GPU clusters, storage, and networking (think: Kubernetes, Proxmox, or cloud GPU farms).&lt;/p&gt;

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

&lt;p&gt;Think of it this way:&lt;/p&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;If you’ve got an product idea today → &lt;em&gt;start with AI applications.&lt;/em&gt; Build a working prototype fast. This is where software engineers will shine. &lt;/p&gt;

&lt;p&gt;If you’re curious about how models work under the hood → &lt;em&gt;dive into ML/DL.&lt;/em&gt; This path requires programming skills and a solid foundation in math.&lt;/p&gt;

&lt;p&gt;If you enjoy infrastructure and scaling challenges → &lt;em&gt;focus on MLOps / infra.&lt;/em&gt; This requires expertise in cloud systems, networking, and automation.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;p&gt;The ecosystem is huge and evolving fast. You don’t need to master everything at once. Pick the layer that excites you most, get hands-on, and then branch out as your curiosity grows.&lt;/p&gt;

&lt;p&gt;At the end of the day, all three paths are connected — many engineers eventually end up wearing multiple hats. Start where you are most comfortable, and build from there.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Finally Completed Designing Data Intensive Application Book</title>
      <dc:creator>Neha Sharma </dc:creator>
      <pubDate>Thu, 29 May 2025 09:44:38 +0000</pubDate>
      <link>https://dev.to/hellonehha/finally-completed-designing-data-intensive-application-book-45j4</link>
      <guid>https://dev.to/hellonehha/finally-completed-designing-data-intensive-application-book-45j4</guid>
      <description>&lt;p&gt;I Finally Finished Reading DDIA – Here’s What I Learned&lt;/p&gt;

&lt;p&gt;I’ve finally completed Designing Data-Intensive Applications (DDIA). This book is one of the most popular and recommended book for engineers, and I now understand why it’s considered essential reading for anyone building scalable, resilient systems.&lt;/p&gt;

&lt;p&gt;It took me three months of reading to complete this book, balancing a full-time job, personal commitments, and the occasional bout of procrastination.&lt;/p&gt;

&lt;h2&gt;
  
  
  Do watch my YT video on it
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fke96nia0jftmhuwoc1g5.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%2Fke96nia0jftmhuwoc1g5.png" alt="DDIA image" width="800" height="450"&gt;&lt;/a&gt;(&lt;a href="https://youtu.be/4IkIyrQQoVU)" rel="noopener noreferrer"&gt;https://youtu.be/4IkIyrQQoVU)&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  why I recommend this book to engineers, architects, and tech leads alike:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1 . Data Systems Demystified&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The book begins by grounding readers in the fundamentals of data systems—storage engines, indexes, logs, and databases.&lt;/p&gt;

&lt;p&gt;It dives deep into the trade-offs between different system designs (e.g., OLTP vs. OLAP, document vs. relational databases), helping you make better architecture decisions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2 . Distributed Systems — With Real-World Trade-Offs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the heart of the book. From replication and partitioning to consensus algorithms and failure handling, Kleppmann explains the why behind every design choice.&lt;/p&gt;

&lt;p&gt;You’ll walk away with a strong mental model for designing resilient, fault-tolerant, and eventually consistent systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3 . Batch and Stream Processing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The final section covers data processing pipelines—how data flows from ingestion to analytics, whether in real-time or batches.&lt;/p&gt;

&lt;p&gt;It helped me better understand tools like Kafka, Flink, Hadoop, and how to design systems that evolve over time without losing integrity or availability.&lt;/p&gt;

&lt;h2&gt;
  
  
  My Takeaways
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;No One-Size-Fits-All&lt;/strong&gt;: DDIA reinforces that system design is always about trade-offs. Consistency, availability, and partition tolerance—pick your battles.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You Need to Think in Systems&lt;/strong&gt;: Modern architectures (microservices, event-driven design, etc.) require a solid grasp of distributed thinking, not just language-specific skills.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DB underlying:&lt;/strong&gt; Understanding how databases evolved—from B-trees to LSM-trees to CRDTs—gives you better foresight into current and future trends.&lt;/p&gt;

&lt;h2&gt;
  
  
  Would I Recommend It?
&lt;/h2&gt;

&lt;p&gt;Absolutely. If you’re serious about designing scalable systems—or leading teams that do—this book is non-negotiable. It will challenge your assumptions, solidify your fundamentals, and make you think like a systems designer.&lt;/p&gt;

&lt;p&gt;Yes, it’s dense. Yes, it gets &lt;del&gt;boring&lt;/del&gt; academic at times. But that’s where the value is. It doesn’t teach you a single tool or framework; it teaches you how to think.&lt;/p&gt;

&lt;p&gt;Happy Learning!!&lt;/p&gt;

</description>
      <category>database</category>
      <category>books</category>
      <category>programming</category>
    </item>
    <item>
      <title>Sharding Demystified</title>
      <dc:creator>Neha Sharma </dc:creator>
      <pubDate>Mon, 26 May 2025 19:42:50 +0000</pubDate>
      <link>https://dev.to/hellonehha/sharding-demystified-3cl9</link>
      <guid>https://dev.to/hellonehha/sharding-demystified-3cl9</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%2Fdwny6wywj736d6032kh7.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%2Fdwny6wywj736d6032kh7.png" alt="Image description" width="640" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Following my &lt;a href="https://nehasharma.dev/posts/system-design-roadmaps-for-beginners" rel="noopener noreferrer"&gt;system design&lt;/a&gt; blogs, this is another blog where we will learn about "sharding vs partition". &lt;/p&gt;

&lt;p&gt;A lot of folks assume that sharding and partition are same but they are not. When working with distributed systems, with data intensive applications, and data these 2 concepts will come handy.&lt;/p&gt;

&lt;p&gt;To understand sharding and partition, we will look into a problem and then see how and where these will help.&lt;/p&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;This is a two-part blog series. In this post, we’ll focus on sharding, and in the second post, we’ll learn about partitioning.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Imagine you’ve built a Meetup-style web application. Users can register, browse events, and RSVP to the ones they’re interested in. Initially, everything runs smoothly, the platform uses a single relational database like PostgreSQL or MySQL, and the traffic is manageable.&lt;/p&gt;

&lt;p&gt;But soon, your platform takes off. The user base grows rapidly. Now, thousands of users are:&lt;/p&gt;

&lt;p&gt;1 . Creating and updating profiles&lt;/p&gt;

&lt;p&gt;2 . Browsing through hundreds of upcoming events&lt;/p&gt;

&lt;p&gt;3 . Sending RSVPs in real time&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi8am7rphj78hleez7wak.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%2Fi8am7rphj78hleez7wak.png" alt="sharding-architecture" width="800" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As a result, you start noticing signs of stress in your backend:&lt;/p&gt;

&lt;p&gt;1 . Fetching meetups &lt;strong&gt;takes longer than expected&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;2 . RSVP actions are &lt;strong&gt;delayed or time out&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;3 . &lt;strong&gt;Pages load slowly&lt;/strong&gt;, especially during peak hours&lt;/p&gt;

&lt;p&gt;On deeper inspection, you identify the core issues:&lt;/p&gt;

&lt;p&gt;1 . &lt;strong&gt;Heavy read/write patterns&lt;/strong&gt; on the same database tables (users, meetups, RSVPs)&lt;/p&gt;

&lt;p&gt;2 . &lt;strong&gt;Query latency&lt;/strong&gt; growing with data size; as rows pile up, indexes become bloated and less efficient&lt;/p&gt;

&lt;p&gt;3 . &lt;strong&gt;Write contention&lt;/strong&gt; on hot tables like RSVPs&lt;/p&gt;

&lt;p&gt;4 . &lt;strong&gt;Disk IOPS and CPU usage&lt;/strong&gt; on your database instance hitting their limits&lt;/p&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;It’s clear that your single-database setup isn’t scaling well. You need to rethink how your data is stored and accessed — in a way that distributes the load, reduces contention, and keeps performance fast and consistent as you grow.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;To fix the above issues, partitioning and sharding come in. In this blog we will explore sharding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sharding
&lt;/h2&gt;

&lt;p&gt;Sharding is a process of splitting a large database into smaller, independent pieces called shards, which are distributed across multiple servers. Each shard contains a subset of the data. A shard key determines how the data is distributed.  &lt;/p&gt;

&lt;p&gt;This enables horizontal scaling, allowing the system to handle more traffic and larger datasets by adding more servers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq02htbisqxlh9q3o7ien.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%2Fq02htbisqxlh9q3o7ien.png" alt="sharding" width="800" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages of Sharding:
&lt;/h3&gt;

&lt;p&gt;1 . &lt;strong&gt;Scaling&lt;/strong&gt; : Sharding is "horizontal scaling". It helps in scaling the system well as the shard are distributed across multiple servers. &lt;/p&gt;

&lt;p&gt;2 . &lt;strong&gt;Fault tolrance&lt;/strong&gt; : If one shard fail then this failure won't affect the other shards. The system will continue working as expected and this helps ensure fault tolrance. A trait every architecture should have.&lt;/p&gt;

&lt;p&gt;3 . &lt;strong&gt;Performance&lt;/strong&gt; :  As the data is spread across multiple shard and servers the performance of query is improved and it also reduce the risk of "hot spots".&lt;/p&gt;

&lt;p&gt;4 . &lt;strong&gt;Supports High Concurrency&lt;/strong&gt; : Each shard can process queries independently.&lt;/p&gt;

&lt;p&gt;5 . &lt;strong&gt;Tailored Data Placement&lt;/strong&gt; : Shard based on geography, tenant, or access patterns&lt;/p&gt;

&lt;h3&gt;
  
  
  Types of shard:
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;What?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Range based&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Data is divided based on a continous range of values of the shard key. Eg: users of meetups from IDs 1–100 go to shard A, and so on.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Geo Based&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Data is sharded based on a business rule or real-world division. Eg: users in the USA will go to shard A, users from Asia to shard B and so on.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Hash based&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A hash function is applied to the shard key, and the result determines the shard: hash(user_id) % number_of_shards&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Directory based&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A central lookup table maps each key to a specific shard. Eg: The system maintains a table like user_id → shard_id.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Featured based&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Data is divided based on the feature.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Magic Pill?
&lt;/h3&gt;

&lt;p&gt;Sharding is not the magic pill that will solve all the problems. It comes with a few dis-advantages. basically "trade-offs".  In our meetup problem, Sharding by region helps scale: US → Shard A, EU → Shard B.But users attending events across regions may face latency or cross-shard lookups.&lt;/p&gt;

&lt;p&gt;1 . &lt;strong&gt;Operational Complexity&lt;/strong&gt; : More moving parts: monitoring, backups, and deployments become more complicated.&lt;/p&gt;

&lt;p&gt;2 . &lt;strong&gt;Data Complexity&lt;/strong&gt; : Handling data in sharding is complex as compare to non-sharding solution. You need to get the data and store them to correct shard, as well as manage retrieve the data too.&lt;/p&gt;

&lt;p&gt;3 . &lt;strong&gt;Re-sharding&lt;/strong&gt; : If you have to re-shard then it will be another complexity&lt;/p&gt;

&lt;p&gt;4 . &lt;strong&gt;cross shard queries&lt;/strong&gt; : Queries between shards are not easy. Joins, aggregations, and transactions across shard  are difficult and slower.&lt;/p&gt;

&lt;p&gt;5 . &lt;strong&gt;Inconsistent Load Distribution&lt;/strong&gt; :  Poor shard key choice can lead to "hot shards" with unequal load.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data consistency and sharding
&lt;/h3&gt;

&lt;p&gt;With sharding, we are distrubtuing, storing, and retrieving data from multiple shards distributed across multiple servers. This leads us to question - "How the data consistency will be? - Strong, weak, or eventually". &lt;/p&gt;

&lt;p&gt;In sharding, we will have the &lt;a href="https://nehasharma.dev/posts/eventually-consistency" rel="noopener noreferrer"&gt;eventual consistency&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  How to shard?
&lt;/h3&gt;

&lt;p&gt;Now that we know what sharding is, trade-offs, types time to learn about how to do sharding. For our meetup problem, let's start with:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi6v36wuupn8rglesctyc.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%2Fi6v36wuupn8rglesctyc.png" alt="sharding steps" width="800" height="152"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;1 . &lt;strong&gt;Understand the Data and Workload&lt;/strong&gt; : Which table is large, and gets high read/write. Eg: in Meetup table is it &lt;code&gt;users&lt;/code&gt;, &lt;code&gt;rsvps&lt;/code&gt;, &lt;code&gt;meetups&lt;/code&gt;.  &lt;/p&gt;

&lt;p&gt;2 . &lt;strong&gt;Choose a Shard Key&lt;/strong&gt; : Time to choose a shard key, this determines how data is distributed. It is important to identify the shard key which evenly distributes load, High cardinality (lots of unique values), meet  most common query patterns.  Eg: &lt;code&gt;users&lt;/code&gt; -&amp;gt; &lt;code&gt;user_id&lt;/code&gt; , &lt;code&gt;meetups&lt;/code&gt; -&amp;gt; &lt;code&gt;location&lt;/code&gt; or &lt;code&gt;organizer_id&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;3 . &lt;strong&gt;Pick a Sharding Strategy&lt;/strong&gt; :  what should the sharding strategy be? In our case, we can go with the Geo-based sharding. Eg: when user logs in app identifies user’s region, Routes requests to the correct shard and all operations (fetch meetups, RSVP, etc.) to that shard. Eg: User from USA will go to shard A (having USA data).&lt;/p&gt;

&lt;p&gt;4 . &lt;strong&gt;Update Application Logic&lt;/strong&gt; :  This is where the code will go. Writing Route requests, handle cross-shard queries, etc. &lt;/p&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Once your data is sharded, another important task to take care who decides where the data goes: client (backend application) or server? &lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;What?&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;client side&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The client (usually backend application) contains the logic to determine which shard to read/write from.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;server side&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;The server (or middleware/proxy) handles which shard stores or retrieves data, abstracting this away from the client.Eg: AWS aurora with global DB, MongoDB (mongos router), Vitess etc.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Setup: Code Time
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;PS: The below code examples are only for understanding the sharding concept. These are not "prod ready" code.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Shard config
&lt;/h3&gt;

&lt;p&gt;A configuration file that contains the database connection string against the region. Horizontal scaling is possible (add more regions as shards grow)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// shard-config.js
export const shardMap = {
  US: {
    name: 'Shard A',
    connectionString: 'postgres://user:pass@shard-us.example.com/meetupdb',
  },
  EU: {
    name: 'Shard B',
    connectionString: 'postgres://user:pass@shard-eu.example.com/meetupdb',
  },
  ASIA: {
    name: 'Shard C',
    connectionString: 'postgres://user:pass@shard-asia.example.com/meetupdb',
  },
};

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Shard Router
&lt;/h3&gt;

&lt;p&gt;Router will be responsible for routing the users to the correct shard. Queries are routed only to relevant shards, reducing latency.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// db-router.js
import { shardMap } from './shard-config.js';
import { Client } from 'pg';

export function getShardClient(region) {
  const shard = shardMap[region];
  if (!shard) throw new Error(`No shard found for region: ${region}`);

  const client = new Client({ connectionString: shard.connectionString });
  return client;
}

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  RSVP
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// rsvp.js
import { getShardClient } from './db-router.js';

export async function rsvpToMeetup(region, userId, meetupId) {
  const client = getShardClient(region);
  await client.connect();

  await client.query(`
    INSERT INTO rsvps (user_id, meetup_id) VALUES ($1, $2)
  `, [userId, meetupId]);

  await client.end();
  console.log(`User ${userId} RSVPed to meetup ${meetupId} in ${region}`);
}


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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Tools for Sharding&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1 . &lt;a href="https://vitess.io/" rel="noopener noreferrer"&gt;Vitess (Sharding layer for MySQL)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2 . &lt;a href="https://www.mongodb.com/resources/products/capabilities/sharding" rel="noopener noreferrer"&gt;MongoDB (Built-in sharding)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3 . &lt;a href="https://www.citusdata.com/" rel="noopener noreferrer"&gt;Citus (Scalable Postgres with sharding)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;4 . &lt;a href="https://proxysql.com/" rel="noopener noreferrer"&gt;ProxySQL (MySQL routing/sharding proxy)&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How sharding solves our problem?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After implementing sharding in our meetup project we can see the following improvements:&lt;/p&gt;

&lt;p&gt;1 . Performance improvement &lt;/p&gt;

&lt;p&gt;2 . Low latency&lt;/p&gt;

&lt;p&gt;3 . Scaling&lt;/p&gt;

&lt;p&gt;4 . Fault tolrance (no SPoF)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3jqwrrf1z3wc30b6hoej.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%2F3jqwrrf1z3wc30b6hoej.png" alt="sharding architecture" width="800" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;1 . Sharding = Data Splitting across multiple databases to handle scale, performance, and fault tolerance.&lt;/p&gt;

&lt;p&gt;2 . It's not the same as partitioning—sharding involves physical distribution.&lt;/p&gt;

&lt;p&gt;3 . Sharding improves scalability but adds complexity in querying, consistency, and rebalancing.&lt;/p&gt;

&lt;p&gt;4 . Choosing the right shard key is critical—aim for high cardinality and balanced access patterns.&lt;/p&gt;

&lt;p&gt;5 . Common strategies include geography-based, tenant-based, or feature-based sharding.&lt;/p&gt;

&lt;p&gt;6 . Be aware of challenges like cross-shard queries, re-sharding, and operational overhead.&lt;/p&gt;

&lt;p&gt;7 . Use sharding only when needed—it's powerful, but not a silver bullet.&lt;/p&gt;

&lt;p&gt;Congrats!! you have reached to the end of the blog. If you liked this blog, found a mistake, or just want to say hi then do reach me at my socials. &lt;/p&gt;

&lt;p&gt;Happy Learning!!&lt;/p&gt;

</description>
      <category>database</category>
      <category>systemdesign</category>
      <category>architecture</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Understanding eventually consistency</title>
      <dc:creator>Neha Sharma </dc:creator>
      <pubDate>Sun, 18 May 2025 19:21:00 +0000</pubDate>
      <link>https://dev.to/hellonehha/understanding-eventually-consistency-234j</link>
      <guid>https://dev.to/hellonehha/understanding-eventually-consistency-234j</guid>
      <description>&lt;p&gt;This is from my series of &lt;a href="https://nehasharma.dev/posts/system-design-roadmaps-for-beginners" rel="noopener noreferrer"&gt;System design for Developers&lt;/a&gt; and based on the book I am reading &lt;a href="https://nehasharma.dev/posts/my-2025-reading-list" rel="noopener noreferrer"&gt;"Database Internals"&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Before we jump into understanding eventually consistency. We need to have a clear understanding of 2 questions:&lt;/p&gt;

&lt;p&gt;1 .  What is consistency?&lt;/p&gt;

&lt;p&gt;2 .  Why do we need it?&lt;/p&gt;

&lt;p&gt;For the above questions, let's try to understand by a simple daily life analogy - Coffee shop. &lt;/p&gt;

&lt;h2&gt;
  
  
  Your Coffee Shop Becomes a Chain
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnq4e1nqkii9v48i3keln.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%2Fnq4e1nqkii9v48i3keln.png" alt="Image description" width="800" height="240"&gt;&lt;/a&gt;"&lt;/p&gt;

&lt;p&gt;Imagine you own a local coffee shop that rewards customer through an app. Every time someone buys a coffee, they earn credits.  This means 1 shop, 1 app, 1 database - everything is perfect. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1miuggox7itlc73n37b6.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%2F1miuggox7itlc73n37b6.png" alt="Image description" width="800" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and then your coffee becomes so popular that you expand into a nationwide chain. Now your system needs to scale.&lt;/p&gt;

&lt;p&gt;Suddenly, you’re dealing with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Multiple locations&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;More users logging in, especially during peak hours (mornings &amp;amp; weekends)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This means we have to scale our App to manage the lodas. It means - More databases, load balancers, and monitoring tools and we ended up with the distributed system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now here comes the problem.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A customer buys a coffee in Location A, but doesn’t immediately see their reward points reflected in the app. Is this a bug? &lt;strong&gt;Why?&lt;/strong&gt; is it happening? &lt;/p&gt;

&lt;p&gt;Because in a distributed system, writes (like earning credits) may take time to propagate across replicas.&lt;/p&gt;

&lt;p&gt;This delay is known as the &lt;strong&gt;consistency delay window&lt;/strong&gt; — the time between the data being written and it becoming visible across all nodes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwsdq65gcasxbzfvlby98.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%2Fwsdq65gcasxbzfvlby98.png" alt="Image description" width="611" height="207"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;So, this is not a bug but a trade-offs (we will see this ahead).&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is Consistency?
&lt;/h2&gt;

&lt;p&gt;In databases, consistency means showing the most recent and correct data to the reader. When consistency is guaranteed, users always get the latest view of the data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Do We Need It?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwikcf0d6dfu39k5ts4iu.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%2Fwikcf0d6dfu39k5ts4iu.png" alt="Image description" width="800" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From the example you must have understood that &lt;/p&gt;

&lt;p&gt;To avoid:&lt;/p&gt;

&lt;p&gt;1 . Stale reads (seeing outdated data)&lt;/p&gt;

&lt;p&gt;2 . Confusing user experiences (e.g., missing points or duplicate messages)&lt;/p&gt;

&lt;p&gt;3 . Conflicting writes&lt;/p&gt;

&lt;p&gt;Consistency ensures that your app behaves as expected, especially when it spans multiple systems.&lt;/p&gt;

&lt;p&gt;Now that we understand what consistency is and why it matters, let’s explore eventual consistency.&lt;/p&gt;

&lt;p&gt;Distributed databases often follow one of the following consistency models:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbxwj5kbcmp9adh4a8hbm.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%2Fbxwj5kbcmp9adh4a8hbm.png" alt="Image description" width="800" height="316"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;1 . Strong Consistency – Always shows the latest data.&lt;/p&gt;

&lt;p&gt;2 . Eventual Consistency – Guarantees that, eventually, all replicas will converge to the latest data.&lt;/p&gt;

&lt;p&gt;3 . Loose (or Weak) Consistency – Does not guarantee a consistent view at all times.&lt;/p&gt;

&lt;p&gt;Every model comes with its pros and cons. Eg: Strong consistency will cost performance. So, as an architect one needs to evaluate trade-offs and decide accordingly which consistency model to have. &lt;/p&gt;

&lt;p&gt;This blog will focus on "eventually" consistency. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is Eventual Consistency?
&lt;/h2&gt;

&lt;p&gt;In systems with eventual consistency, the data might be out of sync temporarily (remember delay/inconsistency window??), but it will converge over time.&lt;/p&gt;

&lt;p&gt;Examples: Banking apps (a pending transaction might not show instantly), Social media likes/comments, Messaging apps (seen/read receipts can lag), Shopping carts in e-commerce platforms&lt;/p&gt;

&lt;p&gt;in our coffee app: A user earns credits at Store A. The app may not reflect it instantly across all devices or stores but eventually, once all replicas sync up, the correct balance is shown.&lt;/p&gt;

&lt;p&gt;This model works well for high-traffic systems where availability and scalability are more important than instant consistency.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Do Systems Handle It?
&lt;/h2&gt;

&lt;p&gt;Is eventual consistency a problem? Not necessarily. Like any design decision, “it depends.” As I mentioned earlier, every consistency model has trade-offs. One need to evalaute the trade-offs accordingly.&lt;/p&gt;

&lt;p&gt;For eventually Consistency, goal should be - Minimize inconsistency windows.&lt;/p&gt;

&lt;p&gt;But how can we handle such "inconsitency"? &lt;/p&gt;

&lt;p&gt;1 . &lt;strong&gt;Ensure "read your own write"&lt;/strong&gt; – where the user sees their most recent action. Eg: When the user bought a coffee, in the app we can show coffee is purchase and points are credit (which will eventually in future will synced)&lt;/p&gt;

&lt;p&gt;2 . &lt;strong&gt;Repair data automatically through background sync (active/passive repair)&lt;/strong&gt;: This is a way to repair the replicas - Active repair : running job at scheduled time. If there are any mistamtches in replicas then sync them. Passive repair: App notices missing points at a store and silently fixes it&lt;/p&gt;

&lt;p&gt;3 . &lt;strong&gt;Allow tunable consistency&lt;/strong&gt; – some databases let developers choose the level of consistency per operation (like Cassandra, DynamoDB).&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;When we scale databases across nodes and regions, maintaining consistency becomes harder. Eventually consistent systems trade off immediacy for scalability and availability.&lt;/p&gt;

&lt;p&gt;As a developer, it’s crucial to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Understand the trade-offs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Know your system’s consistency model&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Design features with the delay window in mind&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use monitoring and repair mechanisms wisely&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In short, not all apps need strong consistency—but all developers need to understand consistency.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>systemdesign</category>
      <category>database</category>
      <category>programming</category>
    </item>
    <item>
      <title>Database Replication Strategies</title>
      <dc:creator>Neha Sharma </dc:creator>
      <pubDate>Wed, 23 Apr 2025 16:23:52 +0000</pubDate>
      <link>https://dev.to/hellonehha/database-replication-strategies-4gcj</link>
      <guid>https://dev.to/hellonehha/database-replication-strategies-4gcj</guid>
      <description>&lt;p&gt;If you are a beginner then read my blog : &lt;a href="https://dev.to/hellonehha/introduction-to-database-f1n"&gt;What is Database&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This blog is the part of my series on &lt;a href="https://dev.to/hellonehha/system-design-roadmap-for-beginners-nfi"&gt;System Design Roadmap for Beginners&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In large-scale, high-traffic applications, scaling the database layer is crucial for performance, fault tolerance, and availability. &lt;/p&gt;

&lt;p&gt;One of the core techniques used to achieve this is database replication—the process of copying and maintaining database objects (like records and schemas) in multiple database servers.&lt;/p&gt;

&lt;p&gt;At its core, databases handle two types of operations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Write operations:&lt;/strong&gt; Modifying or inserting new data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Read operations:&lt;/strong&gt; Fetching or querying existing data.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To manage these efficiently under load, replication allows &lt;strong&gt;writes to go to one or more write nodes (leaders)&lt;/strong&gt; and &lt;strong&gt;reads to be served from read-only replicas (followers)&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Do We Need Database Replication?
&lt;/h2&gt;

&lt;p&gt;As applications scale, relying on a single database node can lead to performance bottlenecks, single points of failure, and latency issues for global users. Replication addresses these challenges by distributing data across multiple nodes.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Reasons for Replication:
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1 . High Availability &amp;amp; Fault Tolerance&lt;/strong&gt;&lt;br&gt;
If one node fails, others can take over seamlessly, ensuring the application remains operational.&lt;/p&gt;

&lt;p&gt;2 . &lt;strong&gt;Read Scalability&lt;/strong&gt;&lt;br&gt;
Read-heavy applications benefit from offloading traffic to replicas, reducing latency and improving throughput.&lt;/p&gt;

&lt;p&gt;3 . &lt;strong&gt;Geo-Distributed Access&lt;/strong&gt;&lt;br&gt;
Place replicas closer to end users to minimize latency and enhance performance for global audiences.&lt;/p&gt;

&lt;p&gt;4 . &lt;strong&gt;Backup &amp;amp; Recovery&lt;/strong&gt;&lt;br&gt;
Replicated data can act as live backups, enabling faster disaster recovery and business continuity.&lt;/p&gt;

&lt;p&gt;5 . &lt;strong&gt;Analytics and Reporting&lt;/strong&gt;&lt;br&gt;
Heavy analytical queries can be run on replicas, preventing slowdowns on the primary write node.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pros and Cons of Replication:
&lt;/h2&gt;

&lt;p&gt;It is not like that replication has no cons. There are reasons for using replication but there are a few trade offs too: &lt;/p&gt;

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

&lt;p&gt;1 . Improved Read Performance&lt;/p&gt;

&lt;p&gt;2 . Fault Tolerance&lt;/p&gt;

&lt;p&gt;3 . Horizontal Scalability for Reads&lt;/p&gt;

&lt;p&gt;4 . Redundancy and Backup&lt;/p&gt;

&lt;p&gt;5 . Lower Latency for Global Users&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1 . Replication Lag: Followers might not have the most recent data.&lt;/p&gt;

&lt;p&gt;2 . Conflict Resolution Complexity: Especially in multi-leader and leaderless setups.&lt;/p&gt;

&lt;p&gt;3 . Operational Overhead: More infrastructure and management required.&lt;/p&gt;

&lt;p&gt;4 . Eventual Consistency Risks: Temporary inconsistencies are possible.&lt;/p&gt;




&lt;h2&gt;
  
  
  There are three common replication strategies:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Single-Leader Replication (Primary-Replica or Master-Slave)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In this model, &lt;strong&gt;only one node (leader)&lt;/strong&gt; accepts &lt;strong&gt;write operations&lt;/strong&gt;. All other nodes (followers/replicas) asynchronously or semi-synchronously &lt;strong&gt;replicate&lt;/strong&gt; the data from the leader and serve &lt;strong&gt;read requests&lt;/strong&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pros&lt;/th&gt;
&lt;th&gt;Cons&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Strong consistency on writes&lt;/strong&gt; (since all writes go to one node).&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Single point of failure&lt;/strong&gt;: If the leader fails, failover must happen.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Simpler conflict resolution (as only one node handles writes).&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Write scalability limits&lt;/strong&gt;: All writes go to one node, creating a bottleneck.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Well-supported by traditional RDBMS like PostgreSQL, MySQL.&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Lag in replicas&lt;/strong&gt;: Followers may lag behind the leader, leading to stale reads.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  🛠 Who uses it:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;PostgreSQL&lt;/strong&gt;, &lt;strong&gt;MySQL&lt;/strong&gt;, &lt;strong&gt;MongoDB (Replica Sets)&lt;/strong&gt;, &lt;strong&gt;Oracle RAC&lt;/strong&gt; in primary-replica setups.&lt;/li&gt;
&lt;li&gt;Web applications, CMS platforms, analytics dashboards.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  2. &lt;strong&gt;Multi-Leader Replication (Multi-Master)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this strategy, &lt;strong&gt;multiple nodes act as leaders&lt;/strong&gt;, and can accept write operations. Changes made on one node are propagated to others, often asynchronously.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pros&lt;/th&gt;
&lt;th&gt;Cons&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;High availability and write scalability&lt;/strong&gt;: Clients can write to the nearest or most available leader.&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Conflict resolution is hard&lt;/strong&gt;: If two nodes write conflicting data simultaneously, you need conflict resolution strategies (last-write-wins, custom merge, etc.).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Good for geo-distributed systems&lt;/strong&gt;: Reduces latency by writing locally.&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Eventual consistency&lt;/strong&gt;: Inconsistencies may appear temporarily.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;High availability and resilience critical&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Complex replication logic&lt;/strong&gt;: Increased operational complexity.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  🛠 Who uses it:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CouchDB&lt;/strong&gt;, &lt;strong&gt;Active-Active Redis&lt;/strong&gt;, &lt;strong&gt;MySQL with Galera Cluster&lt;/strong&gt;, &lt;strong&gt;Cassandra (when not using quorum)&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Collaborative apps, CRMs, mobile-backend-as-a-service (MBaaS).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. &lt;strong&gt;Leaderless Replication&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this model, &lt;strong&gt;there’s no central leader&lt;/strong&gt;. All nodes are &lt;strong&gt;equal&lt;/strong&gt; and can accept both reads and writes. Coordination happens via &lt;strong&gt;quorum-based protocols&lt;/strong&gt;, where a write is successful only if it’s acknowledged by a certain number of nodes.&lt;/p&gt;

&lt;p&gt;For example, using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;W = write quorum&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;R = read quorum&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;N = total number of replicas&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The system ensures consistency if &lt;strong&gt;W + R &amp;gt; N&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Let’s say:  N = 3 (Data is replicated on 3 nodes), W = 2 (A write must succeed on 2 out of 3 nodes) , R = 2 (A read must query at least 2 out of 3 nodes).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;On appling the formula: W + R = 2 + 2 = 4&lt;br&gt;
Since 4 &amp;gt; 3 (N) → The quorum condition is satisfied.&lt;/p&gt;

&lt;h3&gt;
  
  
  What This Means?
&lt;/h3&gt;

&lt;p&gt;When a write is acknowledged by 2 nodes, at least 2 nodes have the latest data. When a read queries 2 nodes, it’s guaranteed to intersect with at least one of the nodes that saw the latest write.&lt;/p&gt;

&lt;p&gt;That way, the system can resolve inconsistencies and return the most up-to-date value.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If W + R &amp;lt; N (N = 3, W = R = 1) ; then Consistency is not guaranteed. A read might only hit a stale node that hasn't received the latest write.&lt;/em&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;strong&gt;Pros&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;High fault tolerance&lt;/strong&gt;: Even if some nodes are down, operations can still proceed.&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Eventual consistency&lt;/strong&gt;: Data may be inconsistent across nodes temporarily.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Highly available and partition-tolerant&lt;/strong&gt; (favors AP in CAP theorem).&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Conflict resolution required&lt;/strong&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;Flexible consistency trade-offs&lt;/strong&gt;.&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Write amplification&lt;/strong&gt;: Every write must go to multiple nodes.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  🛠 Who uses it:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Amazon DynamoDB&lt;/strong&gt;, &lt;strong&gt;Apache Cassandra&lt;/strong&gt;, &lt;strong&gt;Riak&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;High-availability, low-latency systems like shopping carts, IoT ingestion, logging platforms.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Choosing the Right Strategy
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Use Case&lt;/th&gt;
&lt;th&gt;Best Strategy&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Read-heavy workloads with strong consistency&lt;/td&gt;
&lt;td&gt;Single-Leader&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Global applications with local writes needed&lt;/td&gt;
&lt;td&gt;Multi-Leader&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;High availability and resilience critical&lt;/td&gt;
&lt;td&gt;Leaderless&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Happy Learning!!&lt;/p&gt;

</description>
      <category>database</category>
      <category>webdev</category>
      <category>programming</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>APIs Are Like Grocery Lists: A Fun Guide to API Design</title>
      <dc:creator>Neha Sharma </dc:creator>
      <pubDate>Sat, 12 Apr 2025 08:10:25 +0000</pubDate>
      <link>https://dev.to/hellonehha/apis-are-like-grocery-lists-a-fun-guide-to-api-design-1lo9</link>
      <guid>https://dev.to/hellonehha/apis-are-like-grocery-lists-a-fun-guide-to-api-design-1lo9</guid>
      <description>&lt;p&gt;This blog is part of my &lt;strong&gt;&lt;a href="https://dev.to/hellonehha/system-design-roadmap-for-beginners-nfi"&gt;System Design&lt;/a&gt;&lt;/strong&gt; series, where I break down key concepts in a simple and practical way. &lt;/p&gt;

&lt;p&gt;Today, we’ll explore &lt;strong&gt;APIs (Application Programming Interfaces)&lt;/strong&gt;—a fundamental part of modern software development.&lt;/p&gt;

&lt;p&gt;At first glance, API design may seem straightforward, but as you dive deeper, you realize it's more complex than it appears. Before we get hands-on, let's first understand the basics of an API.&lt;/p&gt;




&lt;h2&gt;
  
  
  💻 What is an API?
&lt;/h2&gt;

&lt;p&gt;An &lt;strong&gt;API (Application Programming Interface)&lt;/strong&gt; allows different applications to communicate with each other by defining a set of rules for interaction.&lt;/p&gt;

&lt;p&gt;Let's try to understand API with a real world analogy: A Grocery List.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fly99hrpuutsfgif0j0sk.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%2Fly99hrpuutsfgif0j0sk.png" alt="Image description" width="800" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Imagine you ask your mom, *"What should I buy from the grocery store?"&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;She gives you a &lt;strong&gt;grocery list&lt;/strong&gt;—a structured set of instructions specifying what you need to get. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of this &lt;strong&gt;list&lt;/strong&gt; as an API.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;You (the client)&lt;/strong&gt; request information.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Your mom (the server)&lt;/strong&gt; provides a structured response.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The grocery list (the API)&lt;/strong&gt; acts as an intermediary that ensures clear communication.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2laplwsb40t6vpsl9qed.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%2F2laplwsb40t6vpsl9qed.png" alt="Image description" width="800" height="523"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now in digital world, when you browse X (formerly Twitter), an API fetches tweets for your feed. When you check a food delivery app, an API retrieves restaurant listings.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔥 Why Do We Need APIs?
&lt;/h2&gt;

&lt;p&gt;APIs simplify communication between the client (browser, mobile app) and the server. As applications become more data-driven, APIs help manage data by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Fetching, sending, and updating data efficiently.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enforcing structured interactions between different services.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Supporting architectural patterns like &lt;strong&gt;microservices&lt;/strong&gt;, where different components interact through APIs.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In development, APIs are often referred to as &lt;strong&gt;services&lt;/strong&gt; or &lt;strong&gt;contracts&lt;/strong&gt;, emphasizing their role in connecting the &lt;strong&gt;frontend&lt;/strong&gt; and &lt;strong&gt;backend&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  📚 Deep Dive
&lt;/h2&gt;

&lt;p&gt;Now, we know what is API and why we need it. Let's try to understand it more in detail to create, and use them.&lt;/p&gt;

&lt;p&gt;To understand API, we need to understand the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Status code&lt;/strong&gt;  - &lt;em&gt;What happened with the request?&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Communication protocol&lt;/strong&gt; - &lt;em&gt;How the client and server talk to each other?&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;API Data Formats&lt;/strong&gt; - &lt;em&gt;How data is sent or received?&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's explore the above one by one. As the all the above are crucial for API designing. &lt;/p&gt;

&lt;h2&gt;
  
  
  🚀 Status code &lt;em&gt;(What happened with the request?)&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;Now, when you have asked your mom to share the grocery list how you will get to know that request is fulfilled or not? &lt;/p&gt;

&lt;p&gt;If your mom has handover the list then it is successful.&lt;/p&gt;

&lt;p&gt;If you are waiting then how long shall you wait?&lt;/p&gt;

&lt;p&gt;If she rejected then you don't need to do anything and so on. &lt;/p&gt;

&lt;p&gt;These responses are helpful for you to understand what is happening with your request and you can act accordingly. &lt;/p&gt;

&lt;p&gt;Similarly, When an API responds to a request, it includes a &lt;strong&gt;status code&lt;/strong&gt; indicating success or failure. &lt;/p&gt;

&lt;p&gt;Understanding these codes helps developers debug issues effectively.&lt;/p&gt;

&lt;h3&gt;
  
  
  Common Status Codes:
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;CODE&lt;/th&gt;
&lt;th&gt;meaning&lt;/th&gt;
&lt;th&gt;Explanation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;successful&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;td&gt;A new resource was successfully created&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;201&lt;/td&gt;
&lt;td&gt;The client sent an invalid request&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;204&lt;/td&gt;
&lt;td&gt;Authentication is required but missing or incorrect&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Redirection&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;300&lt;/td&gt;
&lt;td&gt;The requested resource was not found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;301&lt;/td&gt;
&lt;td&gt;The client sent an invalid request&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Error&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;403&lt;/td&gt;
&lt;td&gt;The client does not have permission to access the resource&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;404&lt;/td&gt;
&lt;td&gt;The requested resource was not found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Server&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;500 Internal Server Error&lt;/td&gt;
&lt;td&gt;Something went wrong on the server&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;502 - Bad Gateway&lt;/td&gt;
&lt;td&gt;The server received an invalid response from an upstream server&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzdi70bcltzpoy459loit.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%2Fzdi70bcltzpoy459loit.png" alt="Image description" width="800" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fslxt4u8eh6u1zj2g49hu.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%2Fslxt4u8eh6u1zj2g49hu.png" alt="Image description" width="800" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F282f039hc874gojyldtw.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%2F282f039hc874gojyldtw.png" alt="Image description" width="800" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxu9hnovzuy1k03j5t9zk.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%2Fxu9hnovzuy1k03j5t9zk.png" alt="Image description" width="800" height="343"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These codes help developers manage API behavior and improve user experience. &lt;/p&gt;

&lt;h2&gt;
  
  
  📱 API Communication Protocols - &lt;em&gt;(How the client and server talk to each other?)&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;Now, when you have requested the grocery list your mother then how you have communicated? &lt;/p&gt;

&lt;p&gt;Is it you decided to ask the grocery list in one go? or one by one? or you will call her from grocery store and at that time you will start taking the order.&lt;/p&gt;

&lt;p&gt;This is basically how the "communication" will happen. Similarly, we need to define in API this is known as "communication protocols" &lt;/p&gt;

&lt;p&gt;Different APIs use different &lt;strong&gt;communication protocols&lt;/strong&gt; to exchange data. Here are some common ones:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;communication protocol&lt;/th&gt;
&lt;th&gt;explanation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;REST (Representational State Transfer)&lt;/td&gt;
&lt;td&gt;HTTP API&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GraphQL&lt;/td&gt;
&lt;td&gt;Request only what is needed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;gRPC (Google Remote Procedure Call)&lt;/td&gt;
&lt;td&gt;binary-based API protocol&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WebSockets&lt;/td&gt;
&lt;td&gt;Real time&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcgd4oz0wnuhtttfj6o80.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%2Fcgd4oz0wnuhtttfj6o80.png" alt="Image description" width="800" height="268"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;REST (Representational State Transfer) – HTTP API&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The most widely used protocol that follows standard HTTP methods (GET, POST, PUT, DELETE). It uses URLs to access resources and typically exchanges data in JSON or XML.  &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Your mom gives you a &lt;strong&gt;grocery list&lt;/strong&gt; with everything written down at once. You don’t ask for items one by one; you take the list and go shopping.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;2 . &lt;strong&gt;GraphQL&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;Unlike REST, where you get a fixed response, GraphQL allows clients to request only the data they need. This minimizes over-fetching and under-fetching of data.  &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Instead of receiving a full grocery list, you &lt;strong&gt;ask your mom item by item&lt;/strong&gt; (e.g., “What fruits do I need?”). You get exactly what you ask for, nothing more, nothing less.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;3 . &lt;strong&gt;gRPC (Google Remote Procedure Call)&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;A high-performance, binary-based API protocol designed for microservices and inter-service communication. Uses &lt;strong&gt;Protocol Buffers (protobufs)&lt;/strong&gt; instead of JSON.  &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Instead of speaking in full sentences, you and your mom use &lt;strong&gt;secret codes&lt;/strong&gt; to communicate faster (like shorthand). It’s more efficient but requires both sides to understand the codes.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;4 . &lt;strong&gt;WebSockets&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;Enables real-time, two-way communication (e.g., chat apps, live notifications). Unlike REST, which requires repeated requests, WebSockets keep a persistent connection open.  &lt;/p&gt;

&lt;p&gt;&lt;em&gt;You call your mom while shopping, and she updates the list in real-time based on what’s available.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🗒️ API Data Formats - &lt;em&gt;(How data is sent or received?)&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;Now, in which format you want the grocery list to be shared.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fobefp8dxp749yk793onq.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%2Fobefp8dxp749yk793onq.png" alt="Image description" width="800" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When making API requests, data can be exchanged in different formats:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Format&lt;/th&gt;
&lt;th&gt;Usage&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;JSON (JavaScript Object Notation)&lt;/td&gt;
&lt;td&gt;The most commonly used format, lightweight and easy to parse&lt;/td&gt;
&lt;td&gt;A neatly written, structured list&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;XML (eXtensible Markup Language)&lt;/td&gt;
&lt;td&gt;Common in enterprise applications and SOAP APIs&lt;/td&gt;
&lt;td&gt;A detailed, old-fashioned document&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;HTML&lt;/td&gt;
&lt;td&gt;Used when APIs return web page content&lt;/td&gt;
&lt;td&gt;A full-page magazine with images&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Binary  (e.g., images, videos, PDFs)&lt;/td&gt;
&lt;td&gt;For handling multimedia files&lt;/td&gt;
&lt;td&gt;A voice recording of your mom telling you what to buy&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  ❓ How Does an API Look Like?
&lt;/h2&gt;

&lt;p&gt;I am sure now you would be keen to see how API looks like in code. &lt;/p&gt;

&lt;p&gt;In the below example, we have a simple example where the format is JSON and key-value format.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"items"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Apples"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Milk"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Bread"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"vegetables"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"spinach"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"mint"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"peas"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would be the response when you request (GET) the below URL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;GET&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;https://api.example.com/groceries&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The response contains a list of groceries in &lt;strong&gt;JSON format&lt;/strong&gt;, following the communication protocol (HTTP), and returning a status code (&lt;strong&gt;200 OK&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;Similarly, for POST request we have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;POST&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;https://api.example.com/groceries&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;Content-Type:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;application/json&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"items"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Bananas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Oats"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Response (201 Created):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Items added successfully"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"items"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Bananas"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Oats"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






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

&lt;p&gt;APIs are crucial, enabling seamless communication between different systems. Just like a grocery list ensures you get the right items, an API ensures efficient data exchange between applications. &lt;/p&gt;

&lt;p&gt;If you like this blog, please give a like, share in your network, and connect with me at &lt;a href="http://www.x.com/hellonehha" rel="noopener noreferrer"&gt;X&lt;/a&gt; and &lt;a href="https://www.linkedin.com/in/nehha/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>api</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Deploying my ReactJS and HTML5 app to AWS S3</title>
      <dc:creator>Neha Sharma </dc:creator>
      <pubDate>Sun, 30 Mar 2025 16:09:38 +0000</pubDate>
      <link>https://dev.to/hellonehha/deploying-my-reactjs-and-html5-app-to-aws-s3-3laj</link>
      <guid>https://dev.to/hellonehha/deploying-my-reactjs-and-html5-app-to-aws-s3-3laj</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for the &lt;a href="https://dev.to/challenges/pulumi"&gt;Pulumi Deploy and Document Challenge&lt;/a&gt;: Fast Static Website Deployment&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;I wanted to host my ReactJS and HTML5 project to AWS S3. So, I used Pulumi to upload the files from my VSCode CLI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Live Demo Link
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://demopulumiwebapp-13b82eb.s3-website-us-west-2.amazonaws.com/" rel="noopener noreferrer"&gt;HTML 5 web app&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://reactdemoapppulumi-54dc696.s3-website-us-west-2.amazonaws.com/" rel="noopener noreferrer"&gt;ReactJS&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Repo
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/Neha/pulumi-demo" rel="noopener noreferrer"&gt;https://github.com/Neha/pulumi-demo&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  My Journey
&lt;/h2&gt;

&lt;p&gt;Starting with Pulumi was easy because of the documentation. However, for ReactJS and HTML5 web app. I faced a few common issues:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Access to S3&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ES modules issue&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Access to upload to S3 (file vs folder)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Using Pulumi
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;2 files (yaml, and index.js) step up is easy to follow.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I used Pulumi's web integrated AI support. It was not able to provide me guidance that was helpful&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Loved the preview URL generation, and access to the preview is amazing. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>devchallenge</category>
      <category>pulumichallenge</category>
      <category>webdev</category>
      <category>cloud</category>
    </item>
    <item>
      <title>System Design Roadmap for Beginners</title>
      <dc:creator>Neha Sharma </dc:creator>
      <pubDate>Fri, 14 Mar 2025 08:03:45 +0000</pubDate>
      <link>https://dev.to/hellonehha/system-design-roadmap-for-beginners-nfi</link>
      <guid>https://dev.to/hellonehha/system-design-roadmap-for-beginners-nfi</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%2F2xiu5xlp8xrvblgp0z9k.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2xiu5xlp8xrvblgp0z9k.jpg" alt="Image description" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;System design sounds overwhelming. If you are an engineer who has decided to learn system design, this blog will help you start with a structured plan of essential topics.&lt;/p&gt;

&lt;p&gt;An important thing to remember is that system design has nothing to do with the "programming language." System design requires knowledge of the fundamentals of software design, independent of the language you use.&lt;/p&gt;




&lt;h2&gt;
  
  
  Important Concepts
&lt;/h2&gt;

&lt;p&gt;Every system (software) should be designed while keeping in mind the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Performance – Ensuring fast response times and efficiency.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Scalability – Designing systems to handle growing workloads.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reliability – Making sure the system functions correctly under different conditions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Observability – Monitoring system behavior through metrics, logs, and traces.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Maintainability – Ensuring the system is easy to update and debug.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Logging – Capturing important events and errors for troubleshooting.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Telemetry – Collecting and analyzing real-time system data.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These are the goals of every application and software you will design, whether it is front-end or back-end.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Concepts for a Deep Dive&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Once you have a basic understanding, explore these topics in depth:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://dev.to/hellonehha/apis-are-like-grocery-lists-a-fun-guide-to-api-design-1lo9"&gt;API Design&lt;/a&gt;&lt;/strong&gt; – Structuring APIs for scalability and efficiency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Load Balancers&lt;/strong&gt; – Distributing traffic effectively.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Servers&lt;/strong&gt; – Understanding types of servers and their roles.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Caching Strategies&lt;/strong&gt; – Optimizing response times with caching layers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://dev.to/hellonehha/introduction-to-database-f1n"&gt;Databases&lt;/a&gt;&lt;/strong&gt; – SQL vs. NoSQL, indexing, &lt;a href="https://dev.to/hellonehha/database-replication-strategies-4gcj"&gt;replication&lt;/a&gt;, and partitioning.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  How to Start?
&lt;/h2&gt;

&lt;p&gt;Now, you might be thinking, &lt;em&gt;"Oh! This is a lot!"&lt;/em&gt; Yes, it is—but taking small, manageable steps is the key. The best way to start is by training your &lt;strong&gt;system design thinking&lt;/strong&gt;, especially if you're from a non-backend background.&lt;/p&gt;

&lt;h3&gt;
  
  
  System Design Through a Real-World Analogy
&lt;/h3&gt;

&lt;p&gt;Imagine you are a chef at a new restaurant. As a chef, your responsibilities include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Ensuring the kitchen operates without disruptions.&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;System-design concepts: System availability &amp;amp; reliability (CAP Theorem, Fault Tolerance)  &lt;/p&gt;

&lt;p&gt;Just like a kitchen should always function despite small failures (e.g., a missing ingredient or a broken appliance), a system should be designed to be available and resilient even when some parts fail. Concepts like fault tolerance and CAP theorem help achieve this balance.&lt;/p&gt;

&lt;p&gt;2 . &lt;strong&gt;Maintaining harmony among the staff.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;System design concept: Distributed systems and consistency models.&lt;/p&gt;

&lt;p&gt;A well-managed kitchen has different chefs handling various tasks, such as baking, grilling, and plating, yet everything must come together harmoniously. In distributed systems, multiple servers manage data and requests while maintaining consistency to ensure the system functions as one.&lt;/p&gt;

&lt;p&gt;3 . &lt;strong&gt;Keeping ingredients fresh and well-stocked.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;System design concept: Database caching and indexing &lt;/p&gt;

&lt;p&gt;A restaurant ensures essential ingredients are always available and quickly accessible, similar to how databases use caching and indexing to provide fast data retrieval and improve performance.&lt;/p&gt;

&lt;p&gt;4 . &lt;strong&gt;Ensuring customer orders are prepared and served efficiently.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;System design concept: Load balancing and API request handling &lt;/p&gt;

&lt;p&gt;When a restaurant receives multiple orders, chefs must manage them efficiently without overloading any single person. Similarly, load balancers distribute user requests across multiple servers to ensure smooth system performance.&lt;/p&gt;

&lt;p&gt;5 . &lt;strong&gt;Managing customer expectations and handling peak-hour demand.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;System design concept: Auto-scaling and performance optimization.  &lt;/p&gt;

&lt;p&gt;A restaurant must be ready to handle increased customers during peak hours by adding extra staff or prepping ingredients in advance. Similarly, auto-scaling enables a system to handle high traffic by dynamically adjusting resources.&lt;/p&gt;

&lt;p&gt;6 . &lt;strong&gt;Designing a menu that balances variety and efficiency.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;System design concept: Architecting a scalable and maintainable system**  &lt;/p&gt;

&lt;p&gt;A restaurant menu should be carefully designed to offer variety without overwhelming the kitchen. If the menu is too large, it slows down operations. Similarly, system architecture should be structured efficiently to avoid unnecessary complexity while ensuring scalability and maintainability.&lt;/p&gt;

&lt;p&gt;7 . &lt;strong&gt;Setting up an ordering system for seamless customer interactions.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;System design concept: API design and microservices&lt;/p&gt;

&lt;p&gt;Just as customers need a simple way to place orders (dine-in, takeaway, online), applications use well-designed APIs to handle requests efficiently. A well-structured API ensures smooth communication between different system components, just like an ordering system ensures a seamless experience for customers.&lt;/p&gt;




&lt;p&gt;Just like a chef ensures smooth restaurant operations, a system designer ensures a scalable, efficient, and resilient system. By understanding these concepts step by step, you will build a strong foundation in system design.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;System design isn't something you master overnight. Start small, focus on understanding real-world applications, and gradually explore complex architectures. &lt;/p&gt;

&lt;p&gt;Keep learning, building, and experimenting!&lt;/p&gt;

&lt;p&gt;Happy coding! 🚀&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>React Native New Architecture</title>
      <dc:creator>Neha Sharma </dc:creator>
      <pubDate>Sat, 09 Nov 2024 16:47:33 +0000</pubDate>
      <link>https://dev.to/hellonehha/react-native-new-architecture-1hao</link>
      <guid>https://dev.to/hellonehha/react-native-new-architecture-1hao</guid>
      <description>&lt;p&gt;React Native has announced the release of &lt;a href="https://reactnative.dev/blog/2024/10/23/the-new-architecture-is-here" rel="noopener noreferrer"&gt;version 0.76&lt;/a&gt;. With this update, the new architecture will now be enabled by default. Prior to version 0.76, the only way to enable the new architecture was by opting in.&lt;/p&gt;

&lt;p&gt;This blog will focus on what's new in the new architecture. &lt;/p&gt;

&lt;p&gt;The new React Native architecture has been making headlines for over a year, and for all the right reasons. This new architecture, also known as 'Bridgeless'. Why is it called Bridgeless? We’ll explore this in the blog."&lt;/p&gt;

&lt;p&gt;Before we explore the new architecture, let's quickly recap the previous one.&lt;/p&gt;

&lt;h2&gt;
  
  
  📱 Recap of old architecture
&lt;/h2&gt;

&lt;p&gt;a. There are two lands - JavaScript, and Native. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx41bczwoj9r5tupzitqp.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%2Fx41bczwoj9r5tupzitqp.png" alt="Image description" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;b. There are 3 threads: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;JavaScript Thread (JavaScript)&lt;/strong&gt;: Responsible for the JavaScript bundle code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Main, UI Native Thread&lt;/strong&gt; : Responsible for the native modules.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shadow, or background Thread (Yoga)&lt;/strong&gt;: Responsible for the layout. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Femybiq6tk48hcgv8cuqv.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%2Femybiq6tk48hcgv8cuqv.png" alt="Image description" width="800" height="339"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;c. The only way JavaScript and Native code can &lt;strong&gt;communicate to each other is through the Bridge&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;d. Any native component, such as Button or Alert, is serialized into JSON in the JavaScript layer and sent through the bridge to the native thread. In the native thread, this JSON is then converted into a native (iOS or Android) component.&lt;/p&gt;

&lt;p&gt;e. In the native thread, when an event occurs on a native component, it sends the event as JSON to the JavaScript thread through the bridge. This communication is asynchronous, enabling the bridge to facilitate interaction between JavaScript and native components. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg8wy2psmty35bdyoki4k.jpeg" 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%2Fg8wy2psmty35bdyoki4k.jpeg" alt="Image description" width="800" height="638"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🚩 Problems with old Architecture
&lt;/h2&gt;

&lt;p&gt;Communication between the JavaScript and native layers relies on the bridge, which is the main limitation of the old architecture.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5zduclxyofcivugwt00f.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%2F5zduclxyofcivugwt00f.png" alt="Image description" width="800" height="509"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Performance Issues&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Jerky or empty frames&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Duplication of the nodes&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  ✨ Goal of new architecture
&lt;/h2&gt;

&lt;p&gt;The new architecture focuses on resolving the challenges of the previous one. Its goals are to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Fast startup 🥳&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Concurrent rendering 🎟️&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Responsive apps 🧑‍💻&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Support on multiple platforms 🎮 &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Less crashes 🧨&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Better memory management 💃&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Synchronous execution 🎢&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  🆕 New Architecture
&lt;/h2&gt;

&lt;p&gt;The new architecture is a rewrite in C++, which has unlocked two major improvements:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff84jfhqcto6828atg0hb.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%2Ff84jfhqcto6828atg0hb.png" alt="React native" width="800" height="277"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A. Direct communication between JavaScript and native layers without a bridge. This is why the new architecture is commonly known as 'bridgeless.' &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcyc9z7bbx5znh44enud8.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%2Fcyc9z7bbx5znh44enud8.png" alt="Image description" width="800" height="438"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;B. Support for multiple platforms (as long as the platforms are using React Native) &lt;/p&gt;




&lt;h3&gt;
  
  
  🧩 New Architecture's components:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fozx4oqxcnlrsd1jivhuf.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%2Fozx4oqxcnlrsd1jivhuf.png" alt="Image description" width="800" height="557"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. JavaScript Interface (JSI)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;JSI is JavaScript Interface, this is the layer written in C++. Any JS engine can be use with this and this enables the cross platform support - not just on IOS, android but also on smart TVs, smart watches, etc. &lt;/p&gt;

&lt;p&gt;JSI enables the JavaScript to hold a reference to the native module. These enables the JavaScript to communicate directly with native  modules as well as this enables the synchronous communication between JavaScript and Native thread&lt;/p&gt;

&lt;p&gt;PS: Your react native code gets bundle through Metro and goes to the JSI.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. New Native Modules&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;New Native Modules is the new and improved native modules. This is written in C++ and it enables the synchronous access from JS/TS apis to Native. This means that &lt;strong&gt;there will be direct communication between Native, and JavaScript thread without the need of bridge&lt;/strong&gt;.  C++ also enables to write your own native modules for cross platform sharing.&lt;/p&gt;

&lt;p&gt;New native modules allows to handle events, read layout, schedule updates both async, and sync. &lt;/p&gt;

&lt;p&gt;As we learned earlier, JSI keeps the reference of objects in the TurboModules, this will allow JavaScript code to &lt;strong&gt;load each module only when it is required (dynamic loading of modules)&lt;/strong&gt;. This improves the startup time of app as compared to the old architecture. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Codegen&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Codegen is a tool to create the strongly typed contracts. These contracts are helpful for developers by saving their time and make the communication easier between cross programming languages.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcgpgod2s7046rdpoejl3.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%2Fcgpgod2s7046rdpoejl3.png" alt="Image description" width="800" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In React Native, JavaScript and Typescript are not strongly typed language but C++ is strongly typed. To make the communication between JavaScript, and C++ , codegen  generates interfaces (types). This happened at the build time for fast execution at runtime. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Because of the Codegen JSI (JavaScript Interface) directly communicate with Turbo modules without any bridge.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. New Renderer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;New Renderer is known as Fabric. This is also written in &lt;code&gt;C++&lt;/code&gt;. &lt;br&gt;
Remember we have 3 threads in React Native? - &lt;code&gt;JavaScript&lt;/code&gt;, Main/UI Native, and Shadow/background thread. In old architecture, the problem was our main thread used to get blocked and this leads to the:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F90n7epcefxjign2w8rgy.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%2F90n7epcefxjign2w8rgy.png" alt="Image description" width="800" height="646"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;performance issues&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;empty frames (missing 60FPS)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;also, old architecture has to maintain the 2 copy of node and DOM. This leads to the memory issue&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There was no way to interrupt the low priority tasks to give priority to urgent updates. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;In the Fabric these issues were taken care. With new renderer now we can use &lt;code&gt;transition&lt;/code&gt; to interrupt the low priority tasks for urgent.&lt;/strong&gt; This will make the app responsive &amp;amp; Main/UI native thread won't be block. The events will be async execute.  With new renderer system, there will an immutable tree of the view hierarchy. &lt;/p&gt;

&lt;p&gt;Immutable means that it won't be changeable. Benefits of immutable:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;This allow for &lt;strong&gt;thread-safe processing of updates&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This also means there will be &lt;strong&gt;multiple in-progress trees&lt;/strong&gt;, each representing a different version of the user interface.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As there are multiple trees at different version of UI, *&lt;em&gt;updates can be rendered in the background without blocking the UI *&lt;/em&gt;(such as during transitions) or on the main thread (in response to user input)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The new renderer can also &lt;strong&gt;read layout information synchronously&lt;/strong&gt; and across different threads. This enables background computation for low-priority updates and synchronous reads when needed.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🎯 End to End Architecture
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo5umtd6ipybmthv1murk.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%2Fo5umtd6ipybmthv1murk.png" alt="Image description" width="800" height="345"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🎉 Summary
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;New architecture is available by default from 0.76&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;New architecture has introduced:  &lt;strong&gt;JavaScript Interface (JSI)&lt;/strong&gt;, &lt;strong&gt;new native modules (Turbo Modules)&lt;/strong&gt; , &lt;strong&gt;codegen&lt;/strong&gt;, &lt;strong&gt;new renderer system (fabric)&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;JSI is JavaScript Interface&lt;/strong&gt; it is based on C++ and make the JavaScript and Native modules direct communication possible without any need for Bridge&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;New Native modules&lt;/strong&gt; are improved current native modules. Written in C++ and enables lot of benefits: synchronous communication to and fom JavaScript and native without bridge, lazy loading.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Codegen&lt;/strong&gt; generates type interfaces for JavaScript, and C++ to communicate with each other.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;New renderer (Fabric)&lt;/strong&gt; is new renderer system written in C++. This enables the better performance by enabling multiple threading, and interrupting low priority tasks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;New event loop&lt;/strong&gt; to make the react native more closer to DOM &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Good read &lt;a href="https://github.com/facebook/react-native/issues/31469" rel="noopener noreferrer"&gt;GitHub issue&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;❤️ Say Hi!!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://x.com/hellonehha" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="//youtube.com/@hellonehha"&gt;YouTube&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Happy Learning!!&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactnative</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
