<?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: Rohit Shah</title>
    <description>The latest articles on DEV Community by Rohit Shah (@shahrohit).</description>
    <link>https://dev.to/shahrohit</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%2F3574649%2F34ded9b0-8da5-480d-b1e3-7fb3415789ba.png</url>
      <title>DEV Community: Rohit Shah</title>
      <link>https://dev.to/shahrohit</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shahrohit"/>
    <language>en</language>
    <item>
      <title>HashCodex — Building a Distributed, Secure Code Execution Platform Like LeetCode</title>
      <dc:creator>Rohit Shah</dc:creator>
      <pubDate>Mon, 20 Oct 2025 04:16:06 +0000</pubDate>
      <link>https://dev.to/shahrohit/hashcodex-building-a-distributed-secure-code-execution-platform-like-leetcode-2gpp</link>
      <guid>https://dev.to/shahrohit/hashcodex-building-a-distributed-secure-code-execution-platform-like-leetcode-2gpp</guid>
      <description>&lt;p&gt;Have you ever wonder &lt;strong&gt;how platforms like LeetCode or HackerRank execute your code instantly and securely&lt;/strong&gt; - even when thousands of users are submitting simultaneously?&lt;/p&gt;

&lt;p&gt;That question led me to build &lt;strong&gt;HashCodex&lt;/strong&gt; — an open-source, distributed, real-time &lt;strong&gt;code execution and evaluation platform&lt;/strong&gt;, inspired by online judges like LeetCode and HackerRank.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧩 What is HashCodex?
&lt;/h2&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%2Fl13iwo998tid9wj946k2.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%2Fl13iwo998tid9wj946k2.png" alt="Hashcodex UI" width="800" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HashCodex&lt;/strong&gt; is a &lt;strong&gt;full-stack online code execution system&lt;/strong&gt; that allows users to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🧑‍💻 Solve coding problems directly in the browser
&lt;/li&gt;
&lt;li&gt;⚙️ Run or submit code in multiple languages (&lt;code&gt;C++&lt;/code&gt;, &lt;code&gt;Java&lt;/code&gt;, &lt;code&gt;Python&lt;/code&gt;)
&lt;/li&gt;
&lt;li&gt;📦 Execute user code securely inside &lt;strong&gt;sandboxed Docker containers&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;🔄 Receive &lt;strong&gt;real-time results&lt;/strong&gt; via &lt;strong&gt;Server-Sent Events (SSE)&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s a &lt;strong&gt;distributed system&lt;/strong&gt; — meaning the platform is composed of multiple services (frontend, backend, worker, message queue, etc.), all communicating asynchronously.&lt;/p&gt;

&lt;h2&gt;
  
  
  🧱 System Architecture
&lt;/h2&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%2F2rvfo0v5vemurj0igv54.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%2F2rvfo0v5vemurj0igv54.png" alt="Hashcodex Architecture" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Components Overview
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;Technology&lt;/th&gt;
&lt;th&gt;Responsibility&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Frontend&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Next.js (React)&lt;/td&gt;
&lt;td&gt;UI + Code Editor&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Backend API&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Spring Boot&lt;/td&gt;
&lt;td&gt;Auth, SSE, Queue Management&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Worker Service&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Go&lt;/td&gt;
&lt;td&gt;Executes user code inside Docker sandbox&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Message Broker&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;RabbitMQ&lt;/td&gt;
&lt;td&gt;Async communication between backend &amp;amp; workers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Database&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;PostgreSQL&lt;/td&gt;
&lt;td&gt;Stores users, problems, testcases, submissions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Cache&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Redis&lt;/td&gt;
&lt;td&gt;Used for email verification &amp;amp; password reset tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  ⚙️ How It Works
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;User selects a problem and writes code in the browser.
&lt;/li&gt;
&lt;li&gt;The frontend sends code, language, and problem ID to the backend.
&lt;/li&gt;
&lt;li&gt;The backend creates a submission, assigns a unique ID, and publishes the request to a RabbitMQ queue.
&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;Go Worker Service&lt;/strong&gt; consumes the queue, runs the code inside a &lt;strong&gt;Docker container&lt;/strong&gt; (isolated with CPU/memory limits).
&lt;/li&gt;
&lt;li&gt;Once executed, results are sent back to another queue.
&lt;/li&gt;
&lt;li&gt;The backend consumes the result, updates the database, and &lt;strong&gt;streams the final output&lt;/strong&gt; to the frontend in &lt;strong&gt;real-time&lt;/strong&gt; via SSE.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  💾 Database Design
&lt;/h2&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%2F7jit266597lauy1vuc4f.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%2F7jit266597lauy1vuc4f.png" alt="Database Design" width="800" height="348"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🔐 Security Highlights
&lt;/h2&gt;

&lt;p&gt;Each user’s code runs inside &lt;strong&gt;sandboxed containers&lt;/strong&gt; with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No network access (&lt;code&gt;NetworkMode: "none"&lt;/code&gt;)
&lt;/li&gt;
&lt;li&gt;No privileged operations (&lt;code&gt;CapDrop: ["ALL"]&lt;/code&gt;, &lt;code&gt;no-new-privileges&lt;/code&gt;)
&lt;/li&gt;
&lt;li&gt;Limited CPU &amp;amp; memory using Docker’s &lt;code&gt;NanoCPUs&lt;/code&gt; and memory quotas
&lt;/li&gt;
&lt;li&gt;Process limit (&lt;code&gt;PidsLimit&lt;/code&gt;) to prevent fork bombs or infinite loops
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This ensures that no user code can affect the system or other submissions.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Key Challenges I Solved
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Safe sandboxing:&lt;/strong&gt; Running arbitrary user code without exposing the host system.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Async processing:&lt;/strong&gt; Decoupling code execution from HTTP requests using queues.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Real-time updates:&lt;/strong&gt; Streaming results with &lt;strong&gt;Server-Sent Events&lt;/strong&gt;.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Testcase management:&lt;/strong&gt; Handling multi-param inputs and comparing expected vs actual output.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error alignment:&lt;/strong&gt; Adjusting compiler error line numbers to match user code context.
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧭 Learnings
&lt;/h2&gt;

&lt;p&gt;This project taught me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How distributed systems communicate using message queues
&lt;/li&gt;
&lt;li&gt;How to securely run untrusted code
&lt;/li&gt;
&lt;li&gt;How to stream real-time updates without WebSockets
&lt;/li&gt;
&lt;li&gt;How to design scalable and fault-tolerant architectures
&lt;/li&gt;
&lt;/ul&gt;




&lt;blockquote&gt;
&lt;p&gt;Check out the github repository of &lt;strong&gt;hashcodex&lt;/strong&gt; &lt;a href="https://github.com/shahrohit/hashcodex" rel="noopener noreferrer"&gt;github.com/shahrohit/hashcodex&lt;/a&gt; to learn more about hashcodex.&lt;/p&gt;

&lt;p&gt;💬 I’d love to hear your thoughts — how would &lt;em&gt;you&lt;/em&gt; improve scalability or isolation in such systems?&lt;br&gt;&lt;br&gt;
Drop a comment below! 👇&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>distributedsystems</category>
      <category>docker</category>
      <category>pubsub</category>
      <category>fullstack</category>
    </item>
  </channel>
</rss>
