<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by German Hugo Martinez Mendieta on Medium]]></title>
        <description><![CDATA[Stories by German Hugo Martinez Mendieta on Medium]]></description>
        <link>https://medium.com/@martinezmendietagerman?source=rss-606b3262d658------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0Ce_jN1t0AHuyZDkorXDQg.png</url>
            <title>Stories by German Hugo Martinez Mendieta on Medium</title>
            <link>https://medium.com/@martinezmendietagerman?source=rss-606b3262d658------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 00:07:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@martinezmendietagerman/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Scaling Web Apps: Stateful vs Stateless]]></title>
            <link>https://medium.com/@martinezmendietagerman/scaling-web-apps-stateful-vs-stateless-87ce157b8dcf?source=rss-606b3262d658------2</link>
            <guid isPermaLink="false">https://medium.com/p/87ce157b8dcf</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[stateful]]></category>
            <category><![CDATA[stateless]]></category>
            <dc:creator><![CDATA[German Hugo Martinez Mendieta]]></dc:creator>
            <pubDate>Thu, 28 Dec 2023 18:55:13 GMT</pubDate>
            <atom:updated>2023-12-28T18:55:13.655Z</atom:updated>
            <content:encoded><![CDATA[<h3>Decoding the Stateful vs. Stateless Dilemma: Unleashing the Power of Scalable and Efficient Web Applications</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xYvS7mMWe-u3ehzm58O78A.png" /><figcaption>Stateful vs Stateless architecture</figcaption></figure><h3>What’s the Difference Between Stateful and Stateless?</h3><h4>Introduction</h4><p>As the world rapidly advances towards a future where technology plays an integral role in our lives, we often hear the term <strong>network protocol.</strong> So, what is a <strong>network protocol</strong>? It is a set of rules governing how data is formatted, sent, and received between computer network devices, ranging from servers and routers to endpoints, regardless of their underlying infrastructures, designs, or standards. Devices on both sides of a communication exchange must accept and adhere to the protocol standards to correctly send and receive data.</p><p>Network protocols can be broadly classified into two types: <strong>Stateful</strong> and <strong>Stateless</strong>. The term ‘<strong>state</strong>’ refers to the condition or quality of being at a given point in time. Whether a protocol is stateful or stateless depends on the duration of the interaction a client has with it and how much information is stored. Analyzing the server’s or server-side software’s needs to store information about the state or session details (here, a session refers to the temporary exchange of information between the server and the client) helps uncover the differences between them. Let’s delve into an introduction to these.</p><p>Stateless and stateful architectures play a crucial role in application design, especially in environments like the cloud. Simply put, a “<strong>stateful</strong>” system retains information about previous sessions, while a “<strong>stateless</strong>” system relies on clients to maintain those sessions.</p><p>“<strong>Stateful</strong>” services keep track of sessions or transactions and react differently to the same inputs based on that history. “<strong>Stateless</strong>” services rely on clients to maintain sessions and focus on operations that manipulate resources rather than state.</p><p>Two potential points of confusion when considering “<strong>stateless</strong>” and “<strong>stateful</strong>” architectures are:</p><p>1. A wholly “<strong>stateless</strong>” service usually still needs to handle the state in some form. “<strong>Stateless</strong>” simply refers to the fact that this state is not tracked in server-side sessions</p><p>2. The term ‘<strong>state</strong>’ is broad and can mean different things in different contexts. In this context, it specifically refers to maintaining sessions for authentication and similar processes involving multiple actions. However, this is not related to permanently storing data in a database, which “<strong>stateless</strong>” services still often do</p><h3>Let’s look at an example</h3><p>Let’s think about a web application using protocols like HTTP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_2HemdE_tDSvZYCY1xXbfw.png" /></figure><p>In the diagram above, as you can see, we have a server that hosts an application with a database that the <strong>server</strong> can query.</p><p>There are two main features of the application labeled in the diagram, namely Login and ViewProfile. A person cannot see the profile until they authenticate, so a user named <strong>JOSE</strong> sends their login credentials to the server to authenticate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bWz5JyzppqXkRl64R9w_VA.png" /></figure><p>The server queries the database, checks if the user is registered, verifies the credentials, and authenticates the user.</p><p>Now, under the hood, the server is doing one more thing, which is setting a variable <strong>`logged`</strong> to true after the user successfully authenticates. This specific variable is called a session variable.</p><p>The use of this strategy is making this application “<strong>stateful</strong>” because it is storing the user’s state. So, when the user revisits the site within the specified session duration, they won’t have to provide login credentials again and will get what they requested without any delay.</p><p>While this strategy worked seamlessly in the previously mentioned scenario, let’s now analyze the following situation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9T1wFIp_JpOfMUpD3ajJ7Q.png" /></figure><p>In this scenario, when the user <strong>JOSE</strong> <strong>requests</strong> <strong>/viewprofile</strong> and is not directed to the server where they authenticated (in this case, server2), the server to which they were directed will not recognize <strong>JOSE</strong> because the session variable `<strong>logged</strong>` is set to false on this server. Consequently, this server will require user <strong>JOSE</strong> to log in again, which is undesired for any user.</p><h3>Why two servers?</h3><p>Well, applications use <strong>multiple machines or servers</strong> when they want to scale. As the user base grows, they tend to increase the number of servers hosting their application because a single server cannot handle a large number of requests, leading to poor performance and a subpar user experience.</p><p>As illustrated in the following diagram, when a user requests a site, that request goes to a <strong>load balancer</strong> that distributes the load across both servers (the<strong> load balancer</strong> is essentially a reverse proxy). The user is unaware of which server is handling the request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fYBdQmx1bi6MSLV3O_sh6Q.png" /></figure><p>As you can see, the stateful service will hinder the application from scaling, and a poor user experience would be unavoidable. However, if you intend to create a small application for which you do not anticipate a very large user base (for example, your portfolio), then the stateful service is the way to go.</p><h4><strong>Advantages</strong>:</h4><p>Preserves the user’s state, reducing the need for reauthentication and repetitive queries to the database.</p><h4><strong>Disadvantages</strong>:</h4><p>Less horizontal scalability due to the necessity of maintaining the state on the server. Data loss is possible if the connection is interrupted.</p><h3>Stateless</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k3j5wes6_Uu1JdzJzFul0Q.png" /></figure><p>As you have seen, the stateful service complicates the scalability of the application. Guess what? The<strong> stateless service</strong> is here to rescue us. Let me explain it using a diagram.</p><p>The next time the user tries to access /viewprofile, they will also send the token along with the request. The server receiving the request checks the database, authenticates, and serves what is requested.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SKItdJlOIHBOE47AWgMdCA.png" /></figure><p>Now, it doesn’t matter which server is handling the request; it has become trivial as all servers are querying the same database. Now, the application can scale up to 100 servers, and it won’t make a difference.</p><h4>Advantages:</h4><p>Greater horizontal scalability, as each request contains all the necessary information. There is no data loss if the connection is interrupted.</p><h4>Disadvantages:</h4><p>Requires authentication for each request, which can increase the load and complexity.</p><h3>Comparison</h3><p>Here, the difference between <strong>stateful</strong> and <strong>stateless</strong> is related to how sessions and user state are managed in a web application.</p><p>In the <strong>stateful</strong> approach, the <strong>application</strong> maintains information about the user’s session on the server, allowing for a richer and more personalized experience over time.</p><p>In the <strong>stateless</strong> approach, each user request is treated independently, and the server does not store information between requests. Each request must contain all the necessary information for the server to understand and respond appropriately. This approach is typically more scalable and easier to handle in distributed environments.</p><p>In summary, the choice between ‘<strong>stateful</strong>’ and ‘<strong>stateless</strong>’ depends on the specific scalability and customization needs of the application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87ce157b8dcf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>