<?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: S.S.Vikash</title>
    <description>The latest articles on DEV Community by S.S.Vikash (@ssvikash_20).</description>
    <link>https://dev.to/ssvikash_20</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%2F2602013%2F04ec11eb-f93b-43df-a142-c880b40c9059.jpg</url>
      <title>DEV Community: S.S.Vikash</title>
      <link>https://dev.to/ssvikash_20</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ssvikash_20"/>
    <language>en</language>
    <item>
      <title>My Experience with college server.</title>
      <dc:creator>S.S.Vikash</dc:creator>
      <pubDate>Thu, 21 Aug 2025 17:21:54 +0000</pubDate>
      <link>https://dev.to/ssvikash_20/my-experience-with-college-server-43dj</link>
      <guid>https://dev.to/ssvikash_20/my-experience-with-college-server-43dj</guid>
      <description>&lt;h2&gt;
  
  
  Hello people!
&lt;/h2&gt;

&lt;p&gt;Ever felt the pain of wanting to deploy a side project but getting bogged down by cloud configs, billing alarms, and complex DevOps tools? So did I. That's why I built &lt;strong&gt;KWS&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But this isn't just a story about an application. It's a story about taking that application from a codebase on my laptop to a physical server humming in a college rack, navigating network policies, and building a real-world, self-hosted cloud platform. Buckle up!&lt;/p&gt;

&lt;h2&gt;
  
  
  🚀 What is KWS?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;KWS&lt;/strong&gt; is a self-hosted cloud platform that lets developers and students deploy their apps in secure, containerized environments instantly. Think of it as a mini-Heroku + VS Code Server + Fly.io, all running on your own hardware.&lt;/p&gt;

&lt;p&gt;Here’s what it offers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;🔒 Secure VPN-Based Access:&lt;/strong&gt; Every container is isolated and accessible via a private WireGuard VPN.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;💻 Browser-Based VS Code:&lt;/strong&gt; Every instance gets a live VS Code IDE at &lt;code&gt;https://&amp;lt;container-id&amp;gt;.kwscloud.in&lt;/code&gt;. No setup needed.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;🗃️ Built-In PostgreSQL:&lt;/strong&gt; Managed databases from the dashboard with scoped user privileges. No need to run DBs in your app container.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;🌐 One-Click Public Hosting:&lt;/strong&gt; Make your app public in seconds at &lt;code&gt;https://&amp;lt;your-app&amp;gt;.kwscloud.in&lt;/code&gt;. No manual Nginx configs!&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;🧰 Full Instance Control:&lt;/strong&gt; Start, stop, redeploy, and monitor everything from a clean dashboard.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's perfect for hackathons, college courses, or anyone who wants real deployment power without the cloud bill.&lt;/p&gt;




&lt;h2&gt;
  
  
  🏗️ The Adventure: Hosting KWS on College Hardware
&lt;/h2&gt;

&lt;p&gt;Our college bought a new server for KWS. The mission was simple: get it from the box to the internet. The execution, however, was a fantastic lesson in practical networking.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: The Hypervisor - My Foundation
&lt;/h3&gt;

&lt;p&gt;I started with bare metal. I chose &lt;strong&gt;Proxmox VE&lt;/strong&gt; (a fantastic Type 1 hypervisor) as my base layer. It allows me to create and manage virtual machines (VMs) easily, giving me the flexibility to host KWS and other future services.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Navigating the Network - The DMZ
&lt;/h3&gt;

&lt;p&gt;This was the first big lesson in enterprise IT. You can't just plug a server into the main campus network.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;The Problem:&lt;/strong&gt; The main LAN is trusted. A vulnerable server on it could risk the entire college network.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;The Solution:&lt;/strong&gt; The &lt;strong&gt;DMZ (Demilitarized Zone)&lt;/strong&gt;, a segregated network for public-facing services. The college's firewall strictly controls traffic between the DMZ, the internet, and the internal LAN.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The college assigned me a &lt;strong&gt;private IP from the DMZ range&lt;/strong&gt; (like &lt;code&gt;10.10.20.x&lt;/code&gt;) for my Proxmox host. They then set up firewall rules on their edge device to &lt;strong&gt;NAT&lt;/strong&gt; and forward public traffic for ports &lt;code&gt;80&lt;/code&gt;, &lt;code&gt;443&lt;/code&gt;, and &lt;code&gt;51820&lt;/code&gt; (WireGuard) to my Proxmox host's DMZ IP.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: The Internal Challenge - No DMZ IPs for VMs
&lt;/h3&gt;

&lt;p&gt;Here's where it got interesting. The college's policy prevented me from getting additional DMZ IPs for our individual VMs. I had to get creative.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My Solution:&lt;/strong&gt; Create a private network &lt;em&gt;inside&lt;/em&gt; Proxmox for all our VMs.&lt;/p&gt;

&lt;p&gt;I created a new Linux Bridge (&lt;code&gt;vmbr1&lt;/code&gt;) in Proxmox and gave it its own private subnet: &lt;strong&gt;&lt;code&gt;192.168.69.0/29&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why a /29?&lt;/strong&gt; It provides 6 usable IP addresses. One for the Proxmox gateway, leaving five for VMs. It's small, secure, and perfect for my needs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# /etc/network/interfaces on Proxmox&lt;/span&gt;
auto vmbr1
iface vmbr1 inet static
    address 192.168.69.1/29 &lt;span class="c"&gt;# Proxmox is the gateway&lt;/span&gt;
    bridge_ports none
    bridge_stp off
    bridge_fd 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: Making the Magic Happen with iptables
&lt;/h2&gt;

&lt;p&gt;Now I had a problem. My KWS VM (and others) lived on the &lt;code&gt;192.168.69.0/29&lt;/code&gt; network, utterly invisible to the outside world.&lt;br&gt;&lt;br&gt;
The solution? Turn the Proxmox host into a router.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Enable IP Forwarding:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo &lt;/span&gt;1 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /proc/sys/net/ipv4/ip_forward
sysctl &lt;span class="nt"&gt;-p&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Set up NAT (Masquerading) so the VMs can access the internet outbound:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;iptables &lt;span class="nt"&gt;-t&lt;/span&gt; nat &lt;span class="nt"&gt;-A&lt;/span&gt; POSTROUTING &lt;span class="nt"&gt;-s&lt;/span&gt; 192.168.69.0/29 &lt;span class="nt"&gt;-o&lt;/span&gt; vmbr0 &lt;span class="nt"&gt;-j&lt;/span&gt; MASQUERADE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Set up Port Forwarding (DNAT) to direct public traffic to the correct internal VM. This was the key to making KWS accessible.
&lt;/h3&gt;

&lt;h4&gt;
  
  
  HTTPS:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;iptables &lt;span class="nt"&gt;-t&lt;/span&gt; nat &lt;span class="nt"&gt;-A&lt;/span&gt; PREROUTING &lt;span class="nt"&gt;-i&lt;/span&gt; vmbr0 &lt;span class="nt"&gt;-p&lt;/span&gt; tcp &lt;span class="nt"&gt;--dport&lt;/span&gt; 443 &lt;span class="nt"&gt;-j&lt;/span&gt; DNAT &lt;span class="nt"&gt;--to-destination&lt;/span&gt; 192.168.69.2:443
iptables &lt;span class="nt"&gt;-A&lt;/span&gt; FORWARD &lt;span class="nt"&gt;-p&lt;/span&gt; tcp &lt;span class="nt"&gt;-d&lt;/span&gt; 192.168.69.2 &lt;span class="nt"&gt;--dport&lt;/span&gt; 443 &lt;span class="nt"&gt;-m&lt;/span&gt; state &lt;span class="nt"&gt;--state&lt;/span&gt; NEW,ESTABLISHED,RELATED &lt;span class="nt"&gt;-j&lt;/span&gt; ACCEPT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Wireguard VPN:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;iptables &lt;span class="nt"&gt;-t&lt;/span&gt; nat &lt;span class="nt"&gt;-A&lt;/span&gt; PREROUTING &lt;span class="nt"&gt;-i&lt;/span&gt; vmbr0 &lt;span class="nt"&gt;-p&lt;/span&gt; udp &lt;span class="nt"&gt;--dport&lt;/span&gt; 51820 &lt;span class="nt"&gt;-j&lt;/span&gt; DNAT &lt;span class="nt"&gt;--to-destination&lt;/span&gt; 192.168.69.2:51820 

iptables &lt;span class="nt"&gt;-A&lt;/span&gt; FORWARD &lt;span class="nt"&gt;-p&lt;/span&gt; udp &lt;span class="nt"&gt;-d&lt;/span&gt; 192.168.69.2 &lt;span class="nt"&gt;--dport&lt;/span&gt; 51820 &lt;span class="nt"&gt;-m&lt;/span&gt; state &lt;span class="nt"&gt;--state&lt;/span&gt; NEW,ESTABLISHED,RELATED &lt;span class="nt"&gt;-j&lt;/span&gt; ACCEPT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Make the rules persistent:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;iptables-persistent
iptables-save &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/iptables/rules.v4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 5: The Grand Finale - Wildcard SSL
&lt;/h2&gt;

&lt;p&gt;The main domain for the college is &lt;code&gt;kamarajengg.edu.in&lt;/code&gt;, and it already has a wildcard SSL (&lt;code&gt;*.kamarajengg.edu.in&lt;/code&gt;). This allows &lt;code&gt;kws.kamarajengg.edu.in&lt;/code&gt; to work with HTTPS. However, apps like &lt;code&gt;app1.kws.kamarajengg.edu.in&lt;/code&gt; cannot get HTTPS because wildcard certificates only support one level, and these are subdomains of a subdomain.  &lt;/p&gt;

&lt;p&gt;To solve this, I purchased my own domain &lt;code&gt;kwscloud.in&lt;/code&gt;, set up a DNS challenge in Cloudflare (where my DNS is managed), and obtained a wildcard SSL (&lt;code&gt;*.kwscloud.in&lt;/code&gt;). Now, apps hosted in &lt;code&gt;kws.kamarajengg.edu.in&lt;/code&gt; are securely accessible under &lt;code&gt;*.kwscloud.in&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  📖 The Architecture Diagram:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Here’s a simplified view of how traffic flows to a user's app:
&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%2Fdljfyacq69ogcgb0lgff.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%2Fdljfyacq69ogcgb0lgff.png" alt="Architecture Diagram" width="800" height="2668"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🎓 Lessons Learned &amp;amp; Conclusion
&lt;/h2&gt;

&lt;p&gt;This project was an incredible deep dive into practical networking, security, and system administration. I learned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Value of the DMZ:&lt;/strong&gt; Isolating public services is a critical security practice.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;NAT and Port Forwarding are Foundational:&lt;/strong&gt; Understanding &lt;code&gt;iptables&lt;/code&gt; is like gaining a networking superpower.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Planning is Key:&lt;/strong&gt; Carefully planning your IP addressing scheme from the start prevents headaches later.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Power of Self-Hosting:&lt;/strong&gt; There's immense value in controlling your own infrastructure, both for learning and for independence from cloud vendors.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>networking</category>
      <category>linux</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>O(1) IP allocator regardless of the network size.</title>
      <dc:creator>S.S.Vikash</dc:creator>
      <pubDate>Mon, 16 Jun 2025 18:32:05 +0000</pubDate>
      <link>https://dev.to/ssvikash_20/o1-ip-allocator-regardless-of-the-network-size-ol7</link>
      <guid>https://dev.to/ssvikash_20/o1-ip-allocator-regardless-of-the-network-size-ol7</guid>
      <description>&lt;p&gt;&lt;strong&gt;An IP allocator that dosen't care about the network size, or active hosts in the network. If a client requests for a free IP, it will find it in O(1) time. Sounds cool? It's actually dead simple.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's first understand my use-case. I am building a vpn secured IaaS using wireguard (open source vpn protocol)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The problem:&lt;/strong&gt;&lt;br&gt;
Wireguard is not a server-client based one. It's p2p. So, there is no concept of IP allocation in the server side of wireguard in a logical sense. So, I had to write one myself.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Naive Solution:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The naive approach would be looping through the entire network host portion and finding a free one. But that would take ages. Imagine a network of /8 which has more than 16 million hosts.&lt;/li&gt;
&lt;li&gt;So, I had to think something better.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;O(1) Solution:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I already have a db table where I would store all the public keys and IP's of wireguard peers. But I can't loop over them all to find a free one.&lt;/li&gt;
&lt;li&gt;So, I brought redis stack in. For a simple reason. To push and pop released IP's. Clients may remove their device from the network. In that case, their released IP will be stored in the redis stack.&lt;/li&gt;
&lt;li&gt;So now, if a user requests for a new IP, I would first check if there are any released IP's in the redis stack. If it's not empty, I'll just pop it which is &lt;strong&gt;&lt;em&gt;O(1)&lt;/em&gt;&lt;/strong&gt; in time complexity.&lt;/li&gt;
&lt;li&gt;If there are no released IP's in the redis stack, I would then query the DB to get the max IP there is currently and increment that with 1 to get the next free IP.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;New problem:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;But now you can see a new issue rising up. Query the DB to get the max IP? How? If you store the IP as a literal string like "10.0.0.1/16" or "10.1.0.0/8", it would be too difficult to parse the string and find the current maximum one.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;A simple solution. Don't store the IP as a literal string. Store it as a &lt;em&gt;number&lt;/em&gt;. What? How?&lt;/li&gt;
&lt;li&gt;For example, lets take /24 IP addresses as an example. (10.0.x.x)&lt;/li&gt;
&lt;li&gt;If the &lt;em&gt;number&lt;/em&gt; is 255, then the equivalent IP is 10.0.0.255. If the &lt;em&gt;number&lt;/em&gt; is 256, then the equivalent IP is 10.0.1.0, and so on. I hope you can get the idea.&lt;/li&gt;
&lt;li&gt;It would be super easy to get the maximum of a number from a DB table.&lt;/li&gt;
&lt;li&gt;Now, I just have to write a function that converts the &lt;em&gt;number&lt;/em&gt; to the IP equivalent regardless of the CIDR notation.&lt;/li&gt;
&lt;li&gt;I'll share my implementation using basic math operations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Code that converts the number to IP equivalent:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;func (ip *IPAllocator) GenerateIP(hostNumber int) (string, error) {
    firstOctet, secondOctet, thirdOctet := 0, 0, 0

    if ip.CidrValue &amp;gt; 24 || ip.CidrValue &amp;lt; 8 || ip.CidrValue%8 != 0 {
        log.Println("Cannot generate IP for this cidr. Only supports /24, /16, and /8")
        return "", errors.New(status.INVALID_CIDR)
    }

    c := hostNumber / 256

    if c &amp;lt; 256 {
        thirdOctet = hostNumber % 256
        secondOctet = c
        return fmt.Sprintf("10.%d.%d.%d", firstOctet, secondOctet, thirdOctet), nil
    }

    firstOctet = c / 256
    secondOctet = c % 256
    thirdOctet = hostNumber % 256

    return fmt.Sprintf("10.%d.%d.%d", firstOctet, secondOctet, thirdOctet), nil
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now, we have one last problem. &lt;strong&gt;It's still not truly O(1)&lt;/strong&gt; because the DB query to get the maximum &lt;em&gt;number&lt;/em&gt; will be &lt;strong&gt;O(N)&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The simple solution is to &lt;strong&gt;&lt;em&gt;index&lt;/em&gt;&lt;/strong&gt; the column that has the &lt;em&gt;number&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Now, the DB query would be something like this.&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT ip_address FROM wgpeer ORDER BY ip_address DESC LIMIT 1&lt;/code&gt;&lt;br&gt;
where &lt;em&gt;ip_address&lt;/em&gt; is the indexed column.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The magic lies behind how sorting with index works.&lt;/li&gt;
&lt;li&gt;Indexing a column will make the db to create a B+ tree.&lt;/li&gt;
&lt;li&gt;So, if I sort the column with limit 1 and DESC, it will do a backwards index scan which will start from the rightmost leaf node and that is obviously the highest value. It will stop just right there as we have LIMIT 1.&lt;/li&gt;
&lt;li&gt;And this ultimately makes the entire query &lt;strong&gt;O(1)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Redis push and pop: &lt;strong&gt;O(1)&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;DB query          : &lt;strong&gt;O(1)&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;number&lt;/em&gt; to IP    : &lt;strong&gt;O(1)&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;And ultimately the entire logic of the IP allocator becomes O(1)&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>networking</category>
      <category>programming</category>
      <category>webdev</category>
      <category>devops</category>
    </item>
    <item>
      <title>Code execution system..</title>
      <dc:creator>S.S.Vikash</dc:creator>
      <pubDate>Mon, 07 Apr 2025 13:01:44 +0000</pubDate>
      <link>https://dev.to/ssvikash_20/code-execution-system-deo</link>
      <guid>https://dev.to/ssvikash_20/code-execution-system-deo</guid>
      <description>&lt;h1&gt;
  
  
  🚀 Designing a Secure &amp;amp; Scalable Code Execution System (Like Online Compilers)
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;So, for the past week, I’ve been designing and building my own code execution system from scratch — similar to what online compilers do — for my application.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  😅 The Wrong Way I Started With
&lt;/h2&gt;

&lt;p&gt;My initial prototype had a simple idea:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clients send code to a &lt;strong&gt;gateway&lt;/strong&gt; endpoint.&lt;/li&gt;
&lt;li&gt;The gateway calls the &lt;strong&gt;code execution service&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The code execution service &lt;strong&gt;spins up a new process&lt;/strong&gt; (e.g., Python) and runs it.&lt;/li&gt;
&lt;li&gt;The gateway &lt;strong&gt;synchronously waits&lt;/strong&gt; for the response and returns it to the client.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ❌ Sounds simple, but it was a disaster waiting to happen...
&lt;/h3&gt;




&lt;h3&gt;
  
  
  🚨 1. Scalability Nightmare
&lt;/h3&gt;

&lt;p&gt;Let’s say 10,000 Python requests come in.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;That’s &lt;strong&gt;10,000 new processes&lt;/strong&gt; created.&lt;/li&gt;
&lt;li&gt;Each process might compute something heavy (e.g., big factorials).&lt;/li&gt;
&lt;li&gt;CPU and RAM go 📉.&lt;/li&gt;
&lt;li&gt;And worse: &lt;strong&gt;10,000 clients are left waiting&lt;/strong&gt; — even the homepage won’t load.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  🔐 2. Security Disaster
&lt;/h3&gt;

&lt;p&gt;When you execute user-submitted code directly on your host machine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You're practically &lt;strong&gt;inviting hackers&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;They can run anything — install backdoors, shut down your server, leak environment variables, etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No isolation&lt;/strong&gt; between your service and their malicious code.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🛠️ Time to Re-Architect
&lt;/h2&gt;

&lt;p&gt;I took a step back and decided to &lt;strong&gt;redesign the entire system&lt;/strong&gt;. The core idea was to:&lt;/p&gt;

&lt;p&gt;✅ Make it &lt;strong&gt;asynchronous&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
✅ Make it &lt;strong&gt;secure and isolated&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
✅ Make it &lt;strong&gt;scalable&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚙️ System Architecture Overview
&lt;/h2&gt;

&lt;p&gt;Instead of waiting for the code to execute:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;strong&gt;gateway&lt;/strong&gt; receives the code and &lt;strong&gt;publishes a job&lt;/strong&gt; to a &lt;strong&gt;RabbitMQ&lt;/strong&gt; queue.&lt;/li&gt;
&lt;li&gt;It returns a &lt;strong&gt;unique Job ID&lt;/strong&gt; to the client immediately.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;code execution service&lt;/strong&gt; listens to the queue and picks up jobs.&lt;/li&gt;
&lt;li&gt;Code is run in &lt;strong&gt;Docker containers&lt;/strong&gt; (isolated environments).&lt;/li&gt;
&lt;li&gt;Output is sent back through &lt;strong&gt;another queue&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;client connects to an SSE (Server-Sent Events) endpoint&lt;/strong&gt; to receive output in real-time.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🧠 Container Management &amp;amp; Scheduling
&lt;/h2&gt;

&lt;p&gt;I didn’t want to bring in Kubernetes or Docker Swarm — too heavy for my use case. So I built:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;custom scheduler&lt;/strong&gt; (event-driven)&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;pool of pre-warmed containers&lt;/strong&gt; (5 per language)&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;thread-safe internal queue&lt;/strong&gt; (per language)&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;linked-list implementation&lt;/strong&gt; to manage the job queues&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🧪 When a job comes in:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;It’s placed into its corresponding &lt;strong&gt;language queue&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;My scheduler &lt;strong&gt;detects available containers&lt;/strong&gt; and assigns the job.&lt;/li&gt;
&lt;li&gt;When the job completes, the output is sent to RabbitMQ and then &lt;strong&gt;streamed to the client&lt;/strong&gt; via SSE.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🔐 Defense Against Attacks
&lt;/h2&gt;

&lt;p&gt;Because code execution endpoints are &lt;strong&gt;prime targets&lt;/strong&gt;, I added:&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Rate Limiting
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Implemented a &lt;strong&gt;token bucket algorithm&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Limits how many requests a user can make per second&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ✅ Execution Timeout
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Every container has a &lt;strong&gt;5-second timeout&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Prevents infinite loops and long-hanging processes&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ✅ Isolated Environments
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Every job runs inside a &lt;strong&gt;Docker container&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Malicious code can’t touch the host machine&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ⚡ Advantages of This Architecture
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🛡️ &lt;strong&gt;Secure&lt;/strong&gt; execution using isolated Docker containers&lt;/li&gt;
&lt;li&gt;🔄 &lt;strong&gt;Asynchronous&lt;/strong&gt; and non-blocking — no user is left waiting&lt;/li&gt;
&lt;li&gt;🚀 &lt;strong&gt;Scalable&lt;/strong&gt; — containers are reused and jobs are scheduled&lt;/li&gt;
&lt;li&gt;🔒 &lt;strong&gt;Resilient to attacks&lt;/strong&gt; like infinite loops, backdoors, and DOS&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🎥 I Made a YouTube Video Too
&lt;/h2&gt;

&lt;p&gt;I shared the system design and architecture (not the source code).&lt;br&gt;&lt;br&gt;
It walks through the architecture visually so others can learn from it.&lt;/p&gt;




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

&lt;p&gt;This system took me about a week to plan and build. And I took my time because…&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Unlike typical APIs where attackers have to find vulnerabilities, a code execution API is an &lt;strong&gt;open playground for hackers&lt;/strong&gt;. You're basically letting them run anything.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So I had to make sure the design was &lt;strong&gt;secure&lt;/strong&gt;, &lt;strong&gt;scalable&lt;/strong&gt;, and &lt;strong&gt;robust&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🙌 Let Me Know Your Thoughts!
&lt;/h2&gt;

&lt;p&gt;If you're interested in the code behind this or want me to deep dive into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🧠 My custom scheduler algorithm&lt;/li&gt;
&lt;li&gt;🧱 Linked list queue implementation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let me know in the comments! 💬&lt;/p&gt;




&lt;h3&gt;
  
  
  💻 Built with:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Go (Golang)&lt;/li&gt;
&lt;li&gt;RabbitMQ&lt;/li&gt;
&lt;li&gt;Docker&lt;/li&gt;
&lt;li&gt;Custom scheduler (Golang)&lt;/li&gt;
&lt;li&gt;SSE&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>systemdesign</category>
      <category>programming</category>
      <category>javascript</category>
    </item>
    <item>
      <title>PHP and Go as a Tech Stack.</title>
      <dc:creator>S.S.Vikash</dc:creator>
      <pubDate>Wed, 25 Dec 2024 14:27:42 +0000</pubDate>
      <link>https://dev.to/ssvikash_20/php-and-go-as-a-tech-stack-31i5</link>
      <guid>https://dev.to/ssvikash_20/php-and-go-as-a-tech-stack-31i5</guid>
      <description>&lt;h2&gt;
  
  
  First, let me start with all the reasons why I prefer this over other famous &lt;strong&gt;JAVASCRIPT&lt;/strong&gt; tech stacks..
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;I hate "Javascript for everything" trend.. Yea.. Javascript can do pretty much anything at this point.. &lt;strong&gt;BUTT&lt;/strong&gt;, is it effective in doing that?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Let's take an example of a very intensive CPU bound task. This is a code sample that simulates CPU intensive task. And let's see how Javascript performs.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Reason 1: Javascript sucks at CPU bound tasks!
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setTimeout(function() {
    console.log("Hello world")
}, 1000)

const startTime = Date.now();
while (Date.now() - startTime &amp;lt; 3000) {} //Simulating a long CPU intensive main thread task..

console.log("End")

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;So, what do we have here? Me, as a user of &lt;strong&gt;JAVASCRIPT&lt;/strong&gt; would expect to see &lt;code&gt;"hello world"&lt;/code&gt; printed out after 1 second.. And guess what. It dosen't. It spits out &lt;code&gt;"hello world"&lt;/code&gt; after 3 seconds..&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Why does this happen? To understand this, we need to understand how event loop in browsers and node js works. In simple terms, the event loop checks the call stack and the callback queues at the same time. The callback function that we pass in the &lt;code&gt;setTimeout()&lt;/code&gt; will get into the callback queue once the timer is done with 1000ms.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;But guess what... The callstack is not empty when the timer is done with it's work.. Its still busy performing the 3 seconds CPU intensive task we wrote(Yea.. Its a simulation.. Not a real world dumb program that takes 3 seconds to do whatever its intending to do).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;So, the callback functions in the callback queue and the microtask queue would starve.. Poor callback functions. They only get the chance to get into the callstack after 3 seconds.. And that's the reason why we see the &lt;code&gt;"hello world"&lt;/code&gt; being printed out after 3 seconds even tho I specified 1000ms.&lt;/p&gt;&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%2Fmx9pfh34nek0ww0udllb.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%2Fmx9pfh34nek0ww0udllb.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yea. This is a random image of the event loop I downloaded from the web.. Cool Image.&lt;/p&gt;

&lt;p&gt;Let's take a Go code that does the excat same..&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "fmt"
    "time"
)

func main() {
    time.AfterFunc(1*time.Second, func() {
        fmt.Println("Hello world")
    })

    // Simulating a long CPU-intensive main thread task
    startTime := time.Now()
    for time.Since(startTime) &amp;lt; 3*time.Second {
    }

    print("End")
}

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

&lt;/div&gt;



&lt;p&gt;Here, the &lt;code&gt;"hello world"&lt;/code&gt; gets printed out after 1 second.. How? Because the &lt;code&gt;AfterFunc()&lt;/code&gt; is running on its own GoRoutine which has no business in interfering with the main GoRoutine..&lt;/p&gt;

&lt;h2&gt;
  
  
  Reason 2: I personally hate client side rendering..
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Let's talk about reactJS. It pushes the javascript components to the client and shoves the client's throat with so many things that the clients start to throttle..&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Imagine a low end PC making a request for some static HTML file, and you get a bunch load of react component shits.. How would the client feel? It gets slow.. The browser has to parse the javascript, execute the virtual DOM, generate the HTML out of it.. And what not..&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The browser is doing all the work that the server has to do..&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Remember the &lt;strong&gt;NATURAL FLOW OF WEB?&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;First load the HTML, only then load the javascript? Why? To make the initial paint as fast as possible.. Remember the days when we load the javascript in the footer of the HTML documemt?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;React just made the entire flow upside down.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And in result, the client has to stare at a blank white screen for a solid amount of time..&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  With the reasons being said..
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;I am choosing 2 languages that shines in their own world..&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Go
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The thing that straight up impressed me was that Go is a compiled language and is statically typed.. You can blindly say, Go is super fast and is a lot faster than javascript..&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It has inbuild light weight threads called "GoRoutines" which is a lot faster than actual OS threads as the Go threads are light weight.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go can be used to build RESTful endpoints or can be used for any backend service..&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;BUTT, I cannot use Go for SSR.. PHP shines in that.. In my stack, Go will be heavily used for CPU intensive API's or any backend service.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  PHP
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;PHP is the best thing I ever used for SSR. Simple and very straight forward. Creates a process for each client.. Makes it kind of slow. But still these processes are independent of each other unlike threads that will share the same process memory space and is bad for race conditions and a lot other thread related issues..&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;PHP is also tightly coupled with the web in my opinion.. The straight out of the box superGlobal variables like &lt;code&gt;$_GET&lt;/code&gt;, &lt;code&gt;$_SERVER&lt;/code&gt;, etc.. which makes it easier to work with the web in general..&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The session management in PHP is just too good.. Comes with the language itself.. And is too easy to manage the sessions..&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;PHP can be purely used for SSR. And session management. I can't trust PHP for doing CPU intensive tasks as it sucks in that. Why? Its an interpreted language and its also not multithreaded..&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;So, I offload all the CPU intensive calls to Go.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Best of two worlds.. PHP for SSR, so that the client wouldn't suffer and Go for CPU intensive tasks because it can do concurrency so well...&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>php</category>
    </item>
  </channel>
</rss>
