<?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 Aurimas Gaidys on Medium]]></title>
        <description><![CDATA[Stories by Aurimas Gaidys on Medium]]></description>
        <link>https://medium.com/@aurimasgaidys?source=rss-5163344914dd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*uVN7z19Z3OJsCXqS.</url>
            <title>Stories by Aurimas Gaidys on Medium</title>
            <link>https://medium.com/@aurimasgaidys?source=rss-5163344914dd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 06:38:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aurimasgaidys/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[Firebase cloud functions as a mobile game backend]]></title>
            <link>https://medium.com/@aurimasgaidys/firebase-cloud-functions-as-a-mobile-game-backend-71e5ccb730a?source=rss-5163344914dd------2</link>
            <guid isPermaLink="false">https://medium.com/p/71e5ccb730a</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[games]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[mobile-apps]]></category>
            <category><![CDATA[cloud-functions]]></category>
            <dc:creator><![CDATA[Aurimas Gaidys]]></dc:creator>
            <pubDate>Wed, 05 Jan 2022 21:36:10 GMT</pubDate>
            <atom:updated>2022-01-05T21:45:52.819Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Why does games" src="https://cdn-images-1.medium.com/max/831/1*jXGpmWkOrtl2-Aki3TBoPg.png" /></figure><p>During quarantine, together with my friend, we decided we need a project to help us stay positive. And the <a href="https://whydoesgames.com/">Why doe games — Ghosts</a> was born. Our idea was: A Story driven mobile game where people walk around the city and communicate with NPC (ghosts).</p><p>Sounds easy right?</p><p>We set ourself 3 main goals :</p><ol><li>The game is event-based. That means a huge amount of people use the app for 3–5 hours and after that 3 weeks with almost 0 users. AKA no manual server management.</li><li>We are bootstrapping, so we wanted to save as much cash on servers as possible. AKA if someone pays us to use the service, we take it :D</li><li>We need fast prototyping experience</li></ol><p>For a long time, I was looking at Firebase Cloud Functions for Firebase. If you never heard of them please take a look <a href="https://firebase.google.com/docs/functions/">here</a> and catch up after you feel ready to continue.</p><p><strong>Honeymoon period.</strong></p><p>First couple of weeks everything is great we are prototyping creating functionality everything is great. After a week or so we start to have performance issues. Cloud functions is billed only when you use them and that is great. The issue is a cold start. If you don’t use the function for a couple of hours google recycles the function. And some functions was taking up to 5 seconds to return the first result and up to 300 milliseconds to return the remaining ones.</p><p>So we started optimizing. First of all — npm packages. I never took too much notice of the version. You install the latest one and feel happy. Turns out google cloud functions reuse node modules from other projects so using the most popular versions saves time.</p><p>It was better but not good enough. Next step region. By default, cloud functions are published in the US. We live in the EU. The game where in EU (Later in New Zealand, but it is a story for another time)</p><p>I took a cup of coffee turned on my favourite music track and five minutes later I was done. By default functions are published to the US you need to add <em>functions.region(“europe-west3”) </em>to publish to Europe. To top it off i created a new project to create Firestore (You can not more database to another region after creation) in the correct region. Small update 2x performance. Now that is what I call 5 minutes well spent.</p><p>Then another step was to eliminate the cold starts. Requiring task calls the function every 20 minutes. Is it an elegant solution — no. But it does the job.</p><p>Ok the next step was caching. Request to Firestore costs about 100 milliseconds. And that is where we hit a little snag. Define little you say. Well, there is no easy way to do that. For our project sub 200 ms response time was good. We used UI animations and transitions to hide it.</p><p>So cost is good, performance is good what’s next.</p><figure><img alt="Players playing WhyDoesGames — ghosts game" src="https://cdn-images-1.medium.com/max/983/1*vlCUU2xZrKcAVXELjpL6NA.png" /></figure><p>Well, the next thing was project structure.</p><p>Cloud functions start out as a one file project but soon it becomes hard to maintain it. So my solution looks like this:</p><p>the main file that is in root</p><p>Folder for each functionality group. (user, NPC, inventory)</p><p>Inner folder to separate concerns (Reactive, Callable)</p><p>File for each function (what-function-do.ts)</p><p>Ok, let me expand on it. I keep them in 2 folders: “Reactive” for internally called functions, like DB updates and “Callable” for functions you call yourself.</p><p>I prefer control so I managed them manually, but if you what to set up automatic index file generation you can find great guides for that.</p><p><strong>Final thoughts</strong></p><p>Firebase functions have issues with caching (You need to load all data from scratch) and performance (It’s good but not great) compared with the monolith. But what is losing in performance you get back and more in price and scalability. This approach forces you to think about what you are doing because you can not hide your inabilities and laziness under a big server.</p><p>The project has run for a year and a half now. We had a lot of great events with people playing we had a lot of Covid waves stopping us but at the end of the day. I dot need to do anything google makes sure my bill does not go above 10 EUR :)</p><p>If you have any questions or want to play the game, write a comment. If you like the content press that clap button :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71e5ccb730a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating static IP proxy for C# run in GCE using squid.]]></title>
            <link>https://medium.com/@aurimasgaidys/creating-static-ip-proxy-for-c-run-in-gce-using-squid-75a3d4d909cd?source=rss-5163344914dd------2</link>
            <guid isPermaLink="false">https://medium.com/p/75a3d4d909cd</guid>
            <category><![CDATA[c-sharp-programming]]></category>
            <category><![CDATA[proxy]]></category>
            <category><![CDATA[squid]]></category>
            <dc:creator><![CDATA[Aurimas Gaidys]]></dc:creator>
            <pubDate>Wed, 05 Jan 2022 20:45:55 GMT</pubDate>
            <atom:updated>2022-01-05T20:45:55.514Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*ll1ia8YQRntc1i468Tai0Q.png" /></figure><p>Why you need static IP, so that other provider can whitelist it. Security you know. Yup it is just that simple. Here is the fast guide how to do it for your C# backend.</p><p>To create id you will need.</p><ul><li><strong>Google compute engine instance (micro is enough).</strong></li><li><strong>Static IP</strong></li></ul><p>We chose custom port 999, which is not default port so we needed to update <a href="https://console.cloud.google.com/networking/firewalls">Firewall</a>.</p><h3>Step — 1: <strong>Create Firewall Rule</strong></h3><p>Press <strong>Create Firewall Rule</strong> to create new rule like this :</p><p>Name: <strong>proxy</strong></p><p>Logs: <strong>No</strong></p><p>Network: <strong>default</strong></p><p>Priority: <strong>1000</strong></p><p>Direction of traffic: <strong>Ingress</strong></p><p>Action on match: <strong>Allow</strong></p><p>Source Filter: <strong>IP ranges</strong></p><p>Source IP ranges <strong>0.0.0.0/0</strong></p><p>Specific protocols -&gt; tcp: <strong>999</strong></p><p><strong>Create the rule</strong></p><h3>Step — 2: Create new Instance</h3><p>Go to Google Cloud console -&gt; Compute engine -&gt; VM instances.</p><p>Press <strong>Create new instance</strong></p><p>Add name, select region</p><p>Machine type: <strong>e2-micro </strong>(Or witch ever you like :))</p><p>Boot disk -&gt; change</p><p>Select Operating system: <strong>Ubuntu</strong></p><p>Select version: <strong>Ubuntu 18.04 LTS</strong></p><h3>Step — 1: Configure VM</h3><p><strong>SSH </strong>to VM instance</p><p>Ensure you’re working with the latest software version available.</p><pre>sudo apt-get update</pre><p>To install Squid, run the command:</p><pre>sudo apt-get install squid</pre><p>Do a backup of your configuration file; you can do it by running the command below.</p><pre>sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.original</pre><p>Make the backup non-writable by running the following command.</p><pre>sudo chmod a-w /etc/squid/squid.conf.original</pre><p>Now you can edit Squid. To edit Squid’s configuration file in production, run the command below.</p><p>Configuring Squid Proxy Server</p><pre>sudo nano /etc/squid/squid.conf</pre><p>Change it as follows:</p><pre>auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwords<br>auth_param basic realm proxy<br>request_header_access X-Forwarded-For deny all<br>acl authenticated proxy_auth REQUIRED<br>http_access allow authenticated<br># Choose the port you want. Default is 3128, but we set it to 999<br>http_port 999</pre><p>Configuring Squid Proxy Server</p><pre>sudo nano /etc/squid/squid.conf</pre><p>Create configuration entry in <strong>appsettings.json</strong></p><p>“Proxy”: {</p><p>“Ip”: “squid-server-ip”,</p><p>“User”: “squid-username”,</p><p>“Pass”: “squid-pass”,</p><p>“Port”: 8888</p><p>}</p><p>In the <strong>Startup.cs</strong> of your application create</p><pre>var proxy = Configuration.GetSection(“Proxy”);</pre><pre>var user = proxy.GetValue&lt;string&gt;(“User”);</pre><pre>var pass = proxy.GetValue&lt;string&gt;(“Pass”);</pre><pre>var ip = proxy.GetValue&lt;string&gt;(“Ip”);</pre><pre>var port = proxy.GetValue&lt;int&gt;(“Port”);</pre><pre>HTTPClientHelper.Setup(ip, user, pass, port);</pre><pre>services.AddSingleton&lt;ProxyHttpClient, ProxyHttpClient&gt;();</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75a3d4d909cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>