<?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 Aniket Singh on Medium]]></title>
        <description><![CDATA[Stories by Aniket Singh on Medium]]></description>
        <link>https://medium.com/@anikt?source=rss-f5835af41ef8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QqACus_6QCXpj36MAk1HBg.jpeg</url>
            <title>Stories by Aniket Singh on Medium</title>
            <link>https://medium.com/@anikt?source=rss-f5835af41ef8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:00:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anikt/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[Cost-Effective Real-Time Collaboration with PostgreSQL, WebSockets, and Firestore]]></title>
            <link>https://anikt.medium.com/cost-effective-real-time-collaboration-with-postgresql-websockets-and-firestore-399b13242760?source=rss-f5835af41ef8------2</link>
            <guid isPermaLink="false">https://medium.com/p/399b13242760</guid>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[websocket]]></category>
            <dc:creator><![CDATA[Aniket Singh]]></dc:creator>
            <pubDate>Tue, 18 Mar 2025 16:02:42 GMT</pubDate>
            <atom:updated>2025-03-18T16:02:42.563Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Real-time collaboration in applications — such as chat systems, live document editing, or shared dashboards — requires <strong>instant updates and multi-user access</strong>. Firebase Firestore provides real-time listeners, but at scale, the cost can become prohibitive due to the pricing model based on document reads.</p><p>To optimize costs, a <strong>hybrid approach</strong> using <strong>PostgreSQL, WebSockets, and Firestore</strong> can be more efficient. In this article, we’ll explore how to implement real-time collaboration with <strong>PostgreSQL for data storage, WebSockets for real-time updates, and Firestore for cloud syncing</strong>.</p><h3>Why Not Just Use Firestore Listeners?</h3><p>Firestore’s listener system is <strong>convenient</strong> but <strong>expensive</strong>:</p><ul><li><strong>High Read Costs:</strong> Firestore charges for each read, even if the data hasn’t changed. With multiple users collaborating, this cost multiplies quickly.</li><li><strong>No Offline Syncing:</strong> If a user is offline, they miss real-time updates and must rely on manual refreshes.</li><li><strong>No Granular Control:</strong> Firestore listeners update everything in a collection, even if only one document changes.</li></ul><h3>Alternative Approach: PostgreSQL + WebSockets</h3><p>To avoid excessive Firestore read costs, we can use:</p><ol><li><strong>PostgreSQL</strong> (running on a VPS) as the primary data store.</li><li><strong>WebSockets</strong> for real-time updates to active users.</li><li><strong>Firestore</strong> only for cloud syncing when necessary.</li></ol><h3>How This Works:</h3><ol><li><strong>User actions (e.g., sending a message, updating a task) are stored in PostgreSQL.</strong></li><li><strong>A WebSocket connection broadcasts updates to online users</strong> immediately.</li><li><strong>For offline users, PostgreSQL maintains a ‘sync log’</strong>, marking records as synced = false.</li><li><strong>When a user comes online, their app checks for </strong><strong>synced = false records</strong> and fetches the latest changes.</li><li><strong>Firestore is only updated when necessary</strong> (e.g., for permanent cloud backup).</li></ol><p>This setup ensures that:</p><ul><li>Online users receive instant updates (via WebSockets).</li><li>Offline users get changes when they reconnect (via PostgreSQL sync logs).</li><li>Firestore read costs are minimized by syncing only when required.</li></ul><h3>VPS vs. Managed PostgreSQL (Cost Breakdown)</h3><p>Running PostgreSQL on a <strong>VPS</strong> (Virtual Private Server) is more cost-effective than managed database services. Here’s why:</p><p>Hosting Option Monthly Cost Pros Cons <strong>Firebase Firestore</strong> Varies (pay-per-read/write) Scalable, fully managed High read costs, limited control <strong>Managed PostgreSQL (e.g., AWS RDS, Supabase, Neon)</strong> $10-$50 Easy backups, managed service Additional cost, read/write limits <strong>VPS (self-hosted PostgreSQL)</strong> <strong>$5-$10</strong> Full control, low cost Requires setup &amp; maintenance</p><h3>Why VPS is Better for Cost Efficiency</h3><p>When using a VPS, <strong>PostgreSQL runs on the same server</strong>, eliminating extra database hosting costs. You pay only for the VPS itself, making it ideal for cost-conscious applications.</p><p>For example:</p><ul><li>A <strong>$5/month VPS</strong> can handle PostgreSQL, WebSockets, and your backend.</li><li>A managed PostgreSQL instance alone <strong>would cost $10-$50/month</strong>.</li></ul><h3>Diagram of the System</h3><p>Below is a simplified diagram showing how PostgreSQL, WebSockets, and Firestore work together:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qB8Jt0K8-UUyONnYk6TDMA.png" /></figure><h3>Conclusion</h3><p>Using <strong>PostgreSQL and WebSockets</strong> for real-time collaboration instead of <strong>Firestore listeners</strong> provides a <strong>scalable and cost-effective</strong> solution. This hybrid approach:</p><ul><li><strong>Reduces Firestore read costs</strong> by eliminating constant listeners.</li><li><strong>Provides real-time updates via WebSockets</strong> for active users.</li><li><strong>Ensures offline users get updated when they reconnect</strong> via PostgreSQL sync logs.</li><li><strong>Runs entirely on a VPS, avoiding additional database hosting fees</strong>.</li></ul><p>For applications requiring real-time collaboration, this is a <strong>cost-efficient</strong> and <strong>scalable</strong> solution without sacrificing performance! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=399b13242760" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simplify your Flutter code with GetX]]></title>
            <link>https://medium.com/dsc-ghrce/simplify-your-flutter-code-with-getx-a771b2ffd9a9?source=rss-f5835af41ef8------2</link>
            <guid isPermaLink="false">https://medium.com/p/a771b2ffd9a9</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[getx]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[dart]]></category>
            <dc:creator><![CDATA[Aniket Singh]]></dc:creator>
            <pubDate>Thu, 01 Jul 2021 12:24:09 GMT</pubDate>
            <atom:updated>2021-07-01T12:24:09.507Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AXH1XLFYhMCecc7rMfb33A.png" /></figure><p>We all love flutter right? What makes flutter soo lovable is the structure of the code. The readability of the code is so simple that even the newbies could understand it easily. But I have some complaints, to do some simple task you need to write long code</p><p>For example: Navigating from one screen to another the code looks something like this</p><pre>Navigator.push(<br>    context,<br>    MaterialPageRoute(builder: (context) =&gt; HomeScreen()),<br>  );</pre><p>I know it might be freaking you out that to do <strong>this</strong> simple task you need to write <strong>this</strong> long code.</p><p>Now you know the drawback so let’s talk about the solution. We can overcome this problem by using <strong>GetX</strong> which is the micro-framework. Throughout this blog, I’m going to compare the normal flutter code and code using <strong>GetX. </strong>Before getting inside the blog let’s understand it with this meme</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*qskkZqrorlQzbbnwZjXn2A.png" /></figure><h3>What is GetX?</h3><p><strong>GetX </strong>is a micro-framework that aims to provide some sweet code shorteners, state management, and route management. In Flutter to do anything you need some context but it’s not always possible to have, for example, what if you create a class that has some functions and in one of the functions you want to navigate from one screen to another but there’s no tree so there’s no context right but this thing can be solved using GetX as there’s no context required. When developing large projects GetX can be a superhero for you. One of my most favorite parts of GetX is local storage where you can store key-value pairs very easily as compared to any of the alternatives. All these things come under a single umbrella yet It is super Fast and Powerful.</p><h3>Installing GetX in your project</h3><p>Add this code to pubspec.yaml</p><pre>dependencies:<br>  get: ^4.1.4</pre><p>Import it to the file</p><p>import &#39;package:get/get.dart&#39;;</p><h3>The Comparison</h3><h3>Navigation</h3><p>Flutter Code</p><pre>Navigator.push(<br>    context,<br>    MaterialPageRoute(builder: (context) =&gt; HomeScreen()),<br>  );</pre><p>GetX Code</p><pre>Get.to(HomeScreen());</pre><h3>Bottom Sheet</h3><p>Flutter Code</p><pre>showModalBottomSheet(<br>    context: context,<br>    builder: (context) {<br>      return Column(<br>        mainAxisSize: MainAxisSize.min,<br>        children: &lt;Widget&gt;[<br>          ListTile(<br>            leading: new Icon(Icons.<em>photo</em>),<br>            title: new Text(&#39;Photo&#39;),<br>            onTap: () {<br>              Navigator.<em>pop</em>(context);<br>            },<br>          ),<br>          ListTile(<br>            leading: new Icon(Icons.<em>music_note</em>),<br>            title: new Text(&#39;Music&#39;),<br>            onTap: () {<br>              Navigator.<em>pop</em>(context);<br>            },<br>          ),<br>          ListTile(<br>            leading: new Icon(Icons.<em>videocam</em>),<br>            title: new Text(&#39;Video&#39;),<br>            onTap: () {<br>              Navigator.<em>pop</em>(context);<br>            },<br>          ),<br>          ListTile(<br>            leading: new Icon(Icons.<em>share</em>),<br>            title: new Text(&#39;Share&#39;),<br>            onTap: () {<br>              Navigator.<em>pop</em>(context);<br>            },<br>          ),<br>        ],<br>      );<br>    });</pre><p>GetX Code</p><pre>Get.bottomSheet(<br>    Column(<br>      mainAxisSize: MainAxisSize.min,<br>      children: &lt;Widget&gt;[<br>        ListTile(<br>          leading: new Icon(Icons.<em>photo</em>),<br>          title: new Text(&#39;Photo&#39;),<br>          onTap: () {<br>            Navigator.<em>pop</em>(context);<br>          },<br>        ),<br>        ListTile(<br>          leading: new Icon(Icons.<em>music_note</em>),<br>          title: new Text(&#39;Music&#39;),<br>          onTap: () {<br>            Navigator.<em>pop</em>(context);<br>          },<br>        ),<br>        ListTile(<br>          leading: new Icon(Icons.<em>videocam</em>),<br>          title: new Text(&#39;Video&#39;),<br>          onTap: () {<br>            Navigator.<em>pop</em>(context);<br>          },<br>        ),<br>        ListTile(<br>          leading: new Icon(Icons.<em>share</em>),<br>          title: new Text(&#39;Share&#39;),<br>          onTap: () {<br>            Navigator.<em>pop</em>(context);<br>          },<br>        ),<br>      ],<br>    ),<br>    backgroundColor: Colors.<em>white</em>);</pre><h3>Alert Dialog</h3><p>Flutter Code</p><pre>showDialog(<br>  context: context,<br>  builder: (BuildContext context) {<br>    return AlertDialog(<br>      title: Text(&#39;Not in stock&#39;),<br>      content:<br>          const Text(&#39;This item is no longer available&#39;),<br>      actions: [<br>        MaterialButton(<br>          child: Text(&#39;Ok&#39;),<br>          onPressed: () {<br>            Navigator.<em>of</em>(context).pop();<br>          },<br>        ),<br>      ],<br>    );<br>  },<br>);</pre><p>GetX Code</p><pre>Get.defaultDialog();</pre><h3>Media Query</h3><p>Flutter Code</p><pre>MediaQuery.<em>of</em>(context).size.height</pre><p>GetX Code</p><pre>Get.height</pre><h3>Validation</h3><p>GetX Code</p><pre>GetUtils.isEmail(email_id)</pre><h3>Local Storage</h3><p>GetX Code</p><pre>void main() async {<br>  await GetStorage.<em>init</em>();<br>  runApp(MyApp());<br>}</pre><pre>final doc = GetStorage();<br>doc.write(&quot;name&quot;, &quot;name&quot;);<br>doc.read(&quot;name&quot;),</pre><h3>ThemeData</h3><p>Flutter Code</p><pre>Theme.of(context).primaryColor</pre><p>GetX Code</p><pre>Get.theme.primaryColor</pre><h3>Switch Between Dark and Light Mode</h3><p>GetX Code</p><pre>onPressed: () {<br>  if (Get.isDarkMode) {<br>    Get.changeTheme(ThemeData.light());<br>  } else {<br>    Get.changeTheme(ThemeData.dark());<br>  }<br>},</pre><h3>Check Platform</h3><p>Flutter Code</p><pre>import &#39;dart:io&#39;;<br>IO.Platform.isAndroid</pre><p>GetX Code</p><pre>GetPlatform.isAndroid</pre><p>These were some of the uses of GetX in Flutter and there are many more which you could try out.</p><p>GetX is probably one of the best tools/packages for state management which I won’t cover in this blog as it is quite a big topic itself to discuss here but definitely, I’ll try writing a blog on the same in future</p><p>Here is a simple flutter application made with GetX.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F566523864%3Fapp_id%3D122963&amp;dntp=1&amp;display_name=Vimeo&amp;url=https%3A%2F%2Fvimeo.com%2F566523864&amp;image=http%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F1171356684_1280&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=vimeo" width="1920" height="1080" frameborder="0" scrolling="no"><a href="https://medium.com/media/5fe06fdead8f47506df905e6dd34a91b/href">https://medium.com/media/5fe06fdead8f47506df905e6dd34a91b/href</a></iframe><p>Find out the code here: <a href="https://github.com/Anikets08/GetX">https://github.com/Anikets08/GetX</a></p><p>Thanks for your time. See you in the next one 👋</p><p>Let’s <strong>Connect</strong></p><p><a href="https://github.com/anikets08"><strong><em>GitHub</em></strong></a><strong><em> </em></strong><a href="https://twitter.com/aniketsiingh"><strong><em>Twitter</em></strong></a><strong><em> </em></strong><a href="https://www.instagram.com/aniket.siingh"><strong><em>Instagram</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a771b2ffd9a9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/dsc-ghrce/simplify-your-flutter-code-with-getx-a771b2ffd9a9">Simplify your Flutter code with GetX</a> was originally published in <a href="https://medium.com/dsc-ghrce">GDSC GHRCE</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>