<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Shubham Kant</title>
    <description>The latest articles on Forem by Shubham Kant (@shubhamkant_).</description>
    <link>https://forem.com/shubhamkant_</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%2F1142073%2F284940b3-2508-45ef-ac91-648a738c4f88.jpeg</url>
      <title>Forem: Shubham Kant</title>
      <link>https://forem.com/shubhamkant_</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/shubhamkant_"/>
    <language>en</language>
    <item>
      <title>Scaling Systems: Bigger Machine or More Machines?</title>
      <dc:creator>Shubham Kant</dc:creator>
      <pubDate>Sat, 09 May 2026 18:05:50 +0000</pubDate>
      <link>https://forem.com/shubhamkant_/scaling-systems-bigger-machine-or-more-machines-59ie</link>
      <guid>https://forem.com/shubhamkant_/scaling-systems-bigger-machine-or-more-machines-59ie</guid>
      <description>&lt;h2&gt;
  
  
  What is Scalability?
&lt;/h2&gt;

&lt;p&gt;The ability to handle more requests by buying a bigger machine or buying more machines is called scalability.&lt;/p&gt;

&lt;h2&gt;
  
  
  Vertical Scaling
&lt;/h2&gt;

&lt;p&gt;Vertical scaling refers to using a bigger machine and adding more power (like CPU, RAM, network bandwidth or storage) to handle requests much faster.&lt;/p&gt;

&lt;p&gt;For example, let’s say your current system has an 8-core server capacity limit. You can upgrade it to a 32-core server with faster SSD storage.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;It is easier to implement.&lt;/li&gt;
&lt;li&gt;Upgrading hardware is easier than setting up brand-new servers.&lt;/li&gt;
&lt;li&gt;Easier maintenance.&lt;/li&gt;
&lt;li&gt;No load balancer is required because there is only a single machine.&lt;/li&gt;
&lt;li&gt;Data consistency is easier to maintain.&lt;/li&gt;
&lt;li&gt;Communication is inter-process, which is faster.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;We cannot keep making the machine bigger and bigger. Hardware limits come into the picture.&lt;/li&gt;
&lt;li&gt;Single point of failure - if one machine goes down, the entire website/app goes down.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Horizontal Scaling
&lt;/h2&gt;

&lt;p&gt;Horizontal scaling means buying more machines. Requests can be sent to any of these machines, and the workload can be distributed across them.&lt;/p&gt;

&lt;p&gt;Here, you can add four 8-core servers instead of one 32-core server.&lt;/p&gt;

&lt;p&gt;A load balancer is required here.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;If one server/machine fails, requests can be redirected to another machine.&lt;/li&gt;
&lt;li&gt;We can add as many machines as needed, so it scales very well.&lt;/li&gt;
&lt;li&gt;Better for unknown or peak workloads.&lt;/li&gt;
&lt;li&gt;More resilient and fault tolerant.&lt;/li&gt;
&lt;li&gt;Can be more cost-effective in the long term.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Maintenance is difficult because setting up and managing a distributed system is more complex than managing a single server.&lt;/li&gt;
&lt;li&gt;Maintaining data consistency across multiple servers is harder.&lt;/li&gt;
&lt;li&gt;Servers communicate with one another over the network, and that communication is comparatively slower.&lt;/li&gt;
&lt;li&gt;Inconsistency can arise when multiple servers try to handle and update the same data.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Which One Should You Choose?
&lt;/h2&gt;

&lt;p&gt;It depends on your use case.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Choose vertical scaling if you want:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;better data consistency&lt;/li&gt;
&lt;li&gt;faster inter-process communication&lt;/li&gt;
&lt;li&gt;simpler setup and maintenance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Choose horizontal scaling if you want:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;better scalability&lt;/li&gt;
&lt;li&gt;resilience and fault tolerance&lt;/li&gt;
&lt;li&gt;support for unknown or peak workloads&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the real world, we mostly use both and try to get the best of both worlds.&lt;/p&gt;

&lt;p&gt;Vertical scaling is usually cheaper in the short term, while horizontal scaling can be more cost-effective in the long term.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Scaling is a journey, not a destination.” - Sahn Lam&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Got any doubt or wanna chat? Reach out to me on &lt;a href="https://www.linkedin.com/in/shubham-kant/" rel="noopener noreferrer"&gt;linkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>systemdesign</category>
      <category>distributedsystems</category>
      <category>architecture</category>
      <category>performance</category>
    </item>
    <item>
      <title>Why we need State variables in react</title>
      <dc:creator>Shubham Kant</dc:creator>
      <pubDate>Mon, 28 Aug 2023 10:45:04 +0000</pubDate>
      <link>https://forem.com/shubhamkant_/why-we-need-state-variables-in-react-4lb1</link>
      <guid>https://forem.com/shubhamkant_/why-we-need-state-variables-in-react-4lb1</guid>
      <description>&lt;p&gt;So I got stuck on a very interesting problem today.&lt;br&gt;
Then got to know about &lt;code&gt;state variables&lt;/code&gt; in react. So I thought I should share what I learnt today.&lt;/p&gt;

&lt;p&gt;We will learn about :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What are State variables ?&lt;/li&gt;
&lt;li&gt;How we can make a state variable ?&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Why we need state variables ? (mainly we will explore this!!!)&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  What are State variables ?
&lt;/h2&gt;

&lt;p&gt;State variables maintain the state of your component.&lt;/p&gt;

&lt;p&gt;We can make state variables via useState() Hook. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hooks are JavaScript functions given by React. Period!!!&lt;br&gt;
React has some hooks. Each has some superpowers (logic is written behind the scene).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  How we can make a state variable ?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;First, You will need to import useState() hook like a named import - &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;import { useState } from "react";&lt;/code&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Initialize useState&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;const [A,setA] = useState('Hello world');&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;useState() hook returns an array with 2 values.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;variable which have the respective value(&lt;code&gt;Hello world&lt;/code&gt; in above case)&lt;/li&gt;
&lt;li&gt;The function to update the value&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now our state variable &lt;code&gt;A&lt;/code&gt; has &lt;code&gt;Hello world&lt;/code&gt; value and via &lt;code&gt;setA()&lt;/code&gt; method we can change the value &lt;code&gt;A&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;em&gt;How to change the value via above method ?&lt;/em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Simply pass the updated value in function.&lt;br&gt;
&lt;code&gt;setA('Bye world');&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now the value of &lt;code&gt;A&lt;/code&gt; is being updated to &lt;code&gt;Bye world&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why we need state variables ?
&lt;/h2&gt;

&lt;p&gt;Let's understand with an example here - &lt;/p&gt;

&lt;p&gt;We need to add a toggle functionality i.e. feature of Login/Logout button, If a user is logged out ,then button text should be &lt;code&gt;Login&lt;/code&gt; and if click on it, text should change to &lt;code&gt;Logout&lt;/code&gt; and vice versa.&lt;/p&gt;

&lt;p&gt;It sounds easy right!!&lt;br&gt;
We can make a variable and store a value in it and on click of the button, change the text.&lt;/p&gt;

&lt;p&gt;In below code snippet -&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We made a variable &lt;code&gt;SessionStatus&lt;/code&gt; and its initial value is &lt;code&gt;Login&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;We added a &lt;code&gt;onClick&lt;/code&gt; handler to change the text accordingly.&lt;/li&gt;
&lt;li&gt;Added a simple logic to change the button text to &lt;code&gt;Logout&lt;/code&gt; if its value is &lt;code&gt;Login&lt;/code&gt; and vice versa.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also added a log statement to check if our onClick handler is getting called and our variable is getting updated or not.&lt;br&gt;
Please try - &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code snippet 1&lt;/strong&gt;&lt;br&gt;
&lt;iframe src="https://stackblitz.com/edit/react-q1w9aq?file=src%2FApp.js" width="100%" height="500"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If you will see in the console, the variable value is changing that means our click Handler is getting called but we are &lt;code&gt;NOT&lt;/code&gt; able to see the change in button text in our UI.&lt;br&gt;
It's really weird!!!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Let's try making &lt;code&gt;SessionStatus&lt;/code&gt; a state variable and try the same&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code snippet 2&lt;/strong&gt;&lt;br&gt;
&lt;iframe src="https://stackblitz.com/edit/react-p7mt1t?file=src%2FApp.js" width="100%" height="500"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Here it is working. Text of button is &lt;code&gt;ALSO&lt;/code&gt; changing in UI. &lt;strong&gt;&lt;em&gt;But why ???&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;State variables syncs UI layer with data layer. Period!!!&lt;/strong&gt;&lt;br&gt;
They maintain the state of your component.&lt;/p&gt;

&lt;p&gt;Here the value of &lt;code&gt;state variable&lt;/code&gt; is changing and &lt;strong&gt;when ever state variables changes/updates, React re-renders the whole component&lt;/strong&gt; or we can say react reloads the whole component or we can say react calls the component again with the updated values this time.&lt;/p&gt;

&lt;p&gt;React does it via &lt;strong&gt;Diff Algorithm&lt;/strong&gt;, i.e. calculates the difference between &lt;code&gt;previous Virtual DOM&lt;/code&gt; and &lt;code&gt;new Virtual DOM&lt;/code&gt; and then that difference is applied to Actual DOM.&lt;br&gt;
Here only button value is changing, so react re-renders the component again with that change only in the DOM.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Virtual DOM&lt;/strong&gt; - React keeps a track of UI (the DOM) in memory in the form of object and it is Virtual DOM.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;React makes the &lt;code&gt;DOM operations&lt;/code&gt; superfast.&lt;br&gt;
This is the core of react.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here is an interesting observation if you want to understand it one level deep -&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You will observe something weird in code snippet 2. &lt;/p&gt;

&lt;p&gt;Let's say the first time, the text in the button is currently is &lt;code&gt;Login&lt;/code&gt; and on click, it changes to &lt;code&gt;Logout&lt;/code&gt; but in console it's value is still printing as &lt;code&gt;Login&lt;/code&gt;. &lt;br&gt;
&lt;strong&gt;&lt;em&gt;Why is that ??&lt;/em&gt;&lt;/strong&gt; &lt;br&gt;
&lt;strong&gt;&lt;em&gt;We put console.log() after value being updated right ??&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Then why it does not printed the updated value then and there ??&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The answer to this is that &lt;code&gt;Setting it&lt;/code&gt; does not change the state variable you already have, but instead &lt;code&gt;triggers a re-render&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;React will make a &lt;code&gt;new instance&lt;/code&gt; of state variable with the &lt;code&gt;new value&lt;/code&gt; in a &lt;code&gt;new render cycle&lt;/code&gt;. &lt;strong&gt;Period!!!&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The value which is printing on clicking the button is the value of the variable in the component before the re-render triggered.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Got any doubt or wanna chat? Reach out to me on &lt;a href="https://www.linkedin.com/in/shubham-kant/" rel="noopener noreferrer"&gt;linkedIn&lt;/a&gt; or &lt;a href="https://twitter.com/shubhamkant_" rel="noopener noreferrer"&gt;twitter&lt;/a&gt;.&lt;/p&gt;

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