<?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:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[Software in the Grid]]></title><description><![CDATA[A home for software developers in the power grid. Software, networks, protocols, and infrastructure behind modern energy systems.]]></description><link>https://www.softwareinthegrid.com</link><image><url>https://substackcdn.com/image/fetch/$s_!M0GQ!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png</url><title>Software in the Grid</title><link>https://www.softwareinthegrid.com</link></image><generator>Substack</generator><lastBuildDate>Tue, 17 Nov 2026 08:20:02 GMT</lastBuildDate><atom:link href="https://www.softwareinthegrid.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Dmytro Huz]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[dmytrohuz@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[dmytrohuz@substack.com]]></itunes:email><itunes:name><![CDATA[Dmytro Huz]]></itunes:name></itunes:owner><itunes:author><![CDATA[Dmytro Huz]]></itunes:author><googleplay:owner><![CDATA[dmytrohuz@substack.com]]></googleplay:owner><googleplay:email><![CDATA[dmytrohuz@substack.com]]></googleplay:email><googleplay:author><![CDATA[Dmytro Huz]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Pulse #3 — Can the Grid Have Availability Zones?]]></title><description><![CDATA[Week of 6&#8211;13 November 2026]]></description><link>https://www.softwareinthegrid.com/p/pulse-3-can-the-grid-have-availability</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/pulse-3-can-the-grid-have-availability</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Fri, 13 Nov 2026 10:11:58 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!M0GQ!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Three stories I have been thinking about this week.</p><p>Lithuania wants parts of its electricity grid to keep operating even when the main transmission network is damaged. Britain spent &#163;3.1 billion balancing its electricity system in a year. And Norway has temporarily stopped reserving new grid capacity for data centres while it develops technical requirements for connecting them.</p><p>Together they touch three requirements for the grid that are also as relevant to any distributed system: <strong>resilience, efficiency, and scalability</strong>..</p><p>Reading them, I kept coming back to a familiar question from software engineering:</p><p><strong>How much of a system&#8217;s reliability comes from the way its components are connected and operated?</strong></p><h2>Main signal: can the grid have availability zones?</h2><p>On 10 November, Lithuania&#8217;s transmission system operator <a href="https://www.litgrid.eu/en/news/litgrid-unveils-energy-islands-model-separate-parts-of-lithuanias-grid-will-be-able-to-operate-independently-during-major-disruptions">Litgrid presented its proposed </a><em><a href="https://www.litgrid.eu/en/news/litgrid-unveils-energy-islands-model-separate-parts-of-lithuanias-grid-will-be-able-to-operate-independently-during-major-disruptions">energy islands</a></em><a href="https://www.litgrid.eu/en/news/litgrid-unveils-energy-islands-model-separate-parts-of-lithuanias-grid-will-be-able-to-operate-independently-during-major-disruptions"> model</a>.</p><p>The idea is to divide the country into seven electricity-system regions that could temporarily operate independently if the main 330 kV transmission network became unavailable.</p><p>To make that possible, Litgrid proposes ten new flexible power plants with a combined capacity of 800 MW, upgrades to existing generation, and integration of battery storage. The initial phase could support limited isolated operation of four regions in 2028; the full seven-region design is targeted for 2033.</p><p>Litgrid explicitly points to Ukraine&#8217;s experience of attacks on energy infrastructure as one of the reasons for the proposal.</p><p>Reading about it, I couldn&#8217;t help thinking about distributed systems.</p><h3>Watertight compartments, or availability zones?</h3><p>It reminded me of a ship protection technology &#8212; watertight compartments.</p><p>The idea was to divide a ship into isolated sections so that if one section was breached, the barriers would prevent water from spreading. I learned about this from the story of the Titanic. We all know that it did not save the ship from disaster. The effectiveness of watertight compartments depends on how the damage spreads and how much of the ship can still function.</p><p>In cloud infrastructure, there is another familiar idea: availability zones.</p><p>You can deploy a service across independent failure domains, usually in different geographical locations, so that healthy infrastructure can continue serving requests when one or more zones go down. Of course, the application must be designed for failover, and the surviving zones need enough capacity.</p><p>The ideas are similar, but there is an interesting difference: <strong>in the first case, individual sections may survive even when the whole system fails; in the second, the goal is for the whole system to remain available when individual zones fail.</strong></p><p>I can imagine the Titanic having some perfectly dry, intact compartments even after sinking, possibly for quite a long time. Not particularly useful for the ship as a whole, though.</p><p>And now I wonder: <strong>which of these systems is Lithuania trying to build?</strong></p><p>Under normal conditions, the seven regions would work together as one interconnected electricity system. During a major disruption, they should be able to separate and continue supplying electricity independently.</p><p>That could significantly improve fault containment and regional resilience. But does it also give us the equivalent of cloud failover? If one region loses its ability to supply consumers, could the other six take over part of its load?</p><p>It depends on what survives the failure. Power needs a usable transmission path, and neighbouring regions need enough generation and reserves to help. Unlike a load balancer redirecting API requests, the grid cannot simply move demand wherever spare capacity exists.</p><p>Each isolated region must also balance its own generation and demand, maintain frequency and voltage, respect equipment limits, and keep protection working under the new topology. Healthy power lines alone won&#8217;t help much without enough generation and control capability.</p><p>So I see two different goals: <strong>keep each region operating when the wider grid is damaged, and keep the wider system supplying electricity when one region fails.</strong></p><p>Lithuania is proposing a way to achieve the first. How far it could support the second is what I would like to understand.</p><h3>The engineering problem behind the proposal</h3><p>To understand what it takes for a region to survive on its own, suppose a major transmission connection is suddenly lost and that region becomes electrically separated from the rest of Lithuania.</p><p>Several things have to happen, often almost at once.</p><p><strong>First, detect and establish the new operating state.</strong> Which breakers opened? Which sources and loads are still connected? What has happened to frequency, voltage and power flows?</p><p><strong>Second, stabilize the island.</strong> Some resources must establish or support voltage and frequency. Batteries and fast-responding generation may help, but their capabilities, operating modes and energy limits matter. If demand exceeds supply, some loads may need to be disconnected.</p><p><strong>Third, adapt protection and control.</strong> Short-circuit levels and fault-current behaviour can be different in islanded operation. Protection settings and coordination that worked in the interconnected grid may not work in precisely the same way after separation.</p><p><strong>Fourth, restore and reconnect.</strong> Starting a de-energized region presents different challenges from keeping an existing island stable. Restoration requires sequencing and potentially black-start-capable resources. Reconnecting two live islands also requires acceptable differences in frequency, phase angle and voltage.</p><p>Now look at how much software is involved.</p><p>You need reliable topology information, measurements, event detection, state estimation, local control, coordinated protection, restoration procedures and communications that do not themselves become a single point of failure.</p><p>And there is one requirement I would borrow directly from resilient software design:</p><p><strong>The tests have to cover the failures the system is supposed to survive.</strong></p><p>Seven islands on an architecture diagram are not enough. They have to work when the connections actually fail.</p><h3>Wouldn&#8217;t shared capacity be better than isolated capacity?</h3><p>That brings me back to the availability-zone analogy.</p><p>In a well-designed distributed software system, resilience often comes from combining independent failure domains with enough spare capacity and connectivity for surviving nodes to take over the work of failed ones.</p><p>Could the seven electricity regions support each other in a similar way?</p><p>In some conditions, yes. Geographically distributed generation, storage, reserves and strong interconnections can make a power system more resilient. Surviving regions may be able to support each other when adequate transmission paths remain.</p><p>When those interconnections fail, sharing resources becomes impossible. Even healthy connections have thermal and stability limits, so the network can support only certain transfers.</p><p>That means the design has to support <strong>both</strong> modes: share resources when the network is healthy, and preserve essential local supply when it is not.</p><p>Of course, both approaches have a price.</p><p>In cloud systems, distributing a service across several regions usually costs more. We accept replication, infrastructure overhead and sometimes additional latency in exchange for availability.</p><p>In the grid, the trade-offs are different: additional dispatchable generation, reserves, storage, protection and control capability, potentially less efficient dispatch, and sometimes deliberate load prioritization during an emergency.</p><p>Litgrid <a href="https://www.litgrid.eu/en/news/litgrid-unveils-energy-islands-model-separate-parts-of-lithuanias-grid-will-be-able-to-operate-independently-during-major-disruptions">estimates</a> that its proposed isolated-operation services would add <strong>0.67 euro cents per kWh</strong> to the electricity transmission tariff after 2033. The figure is a projection for the proposed programme; the final tariff has yet to be approved. Litgrid also expects the new flexible plants to help moderate wholesale price peaks.</p><p>At least this gives us a number to discuss when talking about the cost of resilience.</p><p>But what exactly would we be paying for: independent regional operation, the ability to maintain service across the country after a major failure, or some combination of both? I&#8217;d want to measure <strong>how much load each region can serve, for how long, under which failures, and how the system recovers as a whole</strong>.</p><p>Keeping individual regions alive is useful. I am equally interested in what happens to consumers in a region that cannot survive on its own, and whether the wider grid can help it recover.</p><p>Lithuania&#8217;s design is still a proposal, with details <a href="https://www.litgrid.eu/en/news/public-consultations/public-consultation-on-the-concept-for-isolated-operation-services-of-the-lithuanian-electricity-system">open for public consultation until 10 December</a>.</p><div><hr></div><h2>Around the grid</h2><h3>Britain has electricity. Can it move it where it&#8217;s needed?</h3><p>On 9 November, Britain&#8217;s National Energy System Operator published <a href="https://www.neso.energy/news/balancing-act-part-2-outturn">the second part of its </a><em><a href="https://www.neso.energy/news/balancing-act-part-2-outturn">Balancing Act</a></em><a href="https://www.neso.energy/news/balancing-act-part-2-outturn"> series</a>.</p><p>Its reported balancing costs for 2025/26 reached <strong>&#163;3.1 billion</strong>, 16% above the previous year. Thermal transmission constraints were the largest component. Just under &#163;0.5 billion was paid to wind farms to reduce generation, and NESO says it now performs more than twice as much balancing activity per unit of electricity consumed as in 2018.</p><p>Wind curtailment makes an easy headline. The geography of the system explains much of the problem.</p><p>Imagine that wind farms in Scotland can produce plenty of electricity while consumers farther south need it. If the transmission network cannot safely carry the required power, the operator may have to reduce generation north of the constraint and increase it somewhere else.</p><p>Even with enough generation overall, delivering it <strong>where and when it is needed</strong> can be impossible within the network&#8217;s limits.</p><p>NESO gives a useful comparison: October 2025 had lower potential wind generation and lower wholesale prices than December, yet balancing costs were 34% higher. One important difference was that less transmission capacity was available because of outages.</p><p>This is where I think better software can genuinely help.</p><p>Better forecasts, network models, outage planning, security-constrained optimization and flexible demand can reduce unnecessary cost. NESO estimates that its actions and those of its partners avoided &#163;891 million in 2025/26.</p><p>The optimization still has to respect the thermal and stability limits of the network.</p><p>We will still need more dependable generation, storage and flexibility for certain hours, regions and future scenarios.</p><p>At the same time, <strong>coordinating generation, demand and transmission is becoming a major engineering challenge of its own</strong>. When that coordination costs billions, I think the models and software deserve much more attention.</p><h3>Norway needs to know how data centres behave</h3><p>On 9 November, <a href="https://www.statnett.no/om-statnett/nyheter-og-pressemeldinger/nyhetsarkiv-2026/midlertidige-tiltak-for-fortsatt-forsvarlig-systemdrift/">Statnett temporarily suspended new grid-capacity reservations for data centres</a>. Norway&#8217;s <a href="https://www.regjeringen.no/en/whats-new/government-seeks-controlled-growth-of-data-centres-in-norway/id3192054/">government followed with proposed regulatory changes</a>.</p><p>Just look at the numbers.</p><p>Norway has around 800 MW of connected data-centre demand, with 4,200 MW reserved, 9,100 MW in the connection queue and another 18,000 MW in additional enquiries. The country&#8217;s peak demand is just over 25,000 MW.</p><p>Much of that demand is still at the reservation or enquiry stage. Even so, the scale is remarkable.</p><p>The queue is an obvious infrastructure bottleneck, with more proposed projects than substations and transmission lines can accommodate. Statnett is also concerned about how these loads operate: rapid changes in demand, software-controlled loads, sensitivity to disturbances and the possibility of contributing to network oscillations.</p><p>It is considering requirements for how quickly load can change, when facilities must remain connected during disturbances, and how compliance will be demonstrated.</p><p>This is the part that caught my attention. We usually describe a data centre by its power demand in megawatts. The system operator also has to consider its behaviour as a huge, software-controlled load.</p><p>A software workload scheduler can affect a physical power-demand profile.</p><p>The connection study therefore needs to answer several questions: <em>How many megawatts? How quickly can demand change? How will the facility behave during a disturbance?</em></p><p>Europe&#8217;s ability to deploy computing infrastructure, and the speed of inovation in general, increasingly depends on how quickly it can build and safely integrate the electrical systems, alongside securing chips and developing models.</p><h3>What if hosting capacity could be recalculated instead of assumed?</h3><p>At Enlit Europe in Vienna, <a href="https://plexigrid.com/de/events-enlit-2026/">Plexigrid presented its approach to continuously updated hosting capacity</a>.</p><p>Hosting capacity is the additional generation or consumption a network can accommodate without violating its operating limits.</p><p>Traditionally, an operator may use conservative studies to decide how much additional solar generation, EV charging or other load can connect to a feeder.</p><p>The problem is that the feeder does not behave the same way throughout the day.</p><p>A transformer may have substantial spare capacity overnight and very little during the evening peak. Solar generation may cause voltage rise on one feeder at noon, while EV charging causes voltage drop later. Network switching and equipment outages change the picture again.</p><p>And it made me wonder:</p><p><strong>What if the DSO could regularly recalculate available capacity using topology, measurements and forecasts?</strong></p><p>In principle, a system could combine network models, telemetry, state estimation and power-flow calculations, then generate a time-dependent operating envelope for flexible loads and generation.</p><p>There is a catch, though. Someone also has to make sure the equipment respects the calculated limits.</p><p>The model may be wrong. Telemetry may be missing. A charger may ignore its requested limit. A communications link may fail.</p><p>To make dynamic capacity usable safely, the operator needs uncertainty margins, controllable devices, enforcement mechanisms and conservative fallback behaviour.</p><p>Plexigrid&#8217;s presentation is a good starting point for exploring this problem. I&#8217;d still want to see the actual deployments and their results before judging how well the approach works.</p><p>When that calculation starts influencing physical equipment, the planning software becomes part of a distributed control system.</p><h3>Generation, storage and transmission should be designed together</h3><p>On 12 November, Turkey announced a <a href="https://www.aa.com.tr/tr/ekonomi/turkiye-ile-cin-arasinda-yenilenebilir-enerji-alaninda-yaklasik-15-milyar-dolarlik-yatirim-anlasmasi/4122419">preliminary cooperation agreement with China&#8217;s National Energy Administration</a>.</p><p>The stated ambition is approximately $15 billion in investment, including 7 GW of wind and solar generation, new storage, and transmission infrastructure intended to handle 4 GW.</p><p>The agreement is preliminary, with the projects still to be developed. I like that generation, storage and network capacity appear in the same plan.</p><p>We often treat a solar farm, a battery and a transmission connection as separate projects. In operation, they are parts of the same power system. Their locations, capacities, controls and constraints determine what the system can actually deliver.</p><p>I would like to know how that combination behaves when generation varies, a line becomes congested, or part of the system fails. The number of announced gigawatts tells us little about that.</p><h3>A hidden dependency can take down a very visible system</h3><p>A suspected drone attack on Iraq&#8217;s <a href="https://www.internazionale.it/ultime-notizie-reuters/2026/11/09/production-suspended-at-iraq-s-khor-mor-gas-field-after-drone-attack-sources-say">Khor Mor gas field on 8 November</a> halted gas production. Regional authorities reported that about 2.8 GW of electricity generation was affected.</p><p>The electricity generators lost a common upstream dependency: the gas supply.</p><p>In software terms, this is a <strong>common-mode dependency</strong>.</p><p>You can deploy multiple services, or multiple generators, and still have one point of failure if they all depend on the same upstream resource.</p><p>You can count as many redundant instances as you like. If they share a critical dependency, you still have a single point of failure.</p><h3>AI infrastructure is becoming energy infrastructure</h3><p>On 12 November, <a href="https://www.reuters.com/business/media-telecom/spacex-invest-over-74-billion-supercompute-facilities-texas-arizona-2026-11-12/">Reuters reported SpaceX&#8217;s plans for more than $74 billion in AI computing campuses</a> in Texas and Arizona.</p><p>The proposed Texas campus would generate its own electricity using a gas-fired plant, while the Arizona project involves coordination with local electric cooperatives. Both are proposed investments, and the Arizona campus still needs local approval.</p><p>I was reminded of <a href="https://www.youtube.com/watch?v=XuoqKYxDHVc">Elon Musk&#8217;s July interview with </a><em><a href="https://www.youtube.com/watch?v=XuoqKYxDHVc">The Economist</a></em>, where he argued that electricity and cooling can constrain AI expansion more than the supply of chips, particularly outside China.</p><p>That is his assessment; I wouldn&#8217;t treat it as a universal rule.</p><p>Still, if a computing campus needs its own generation and major electrical connections, where does the data centre end and the power system begin?</p><div><hr></div><h2>Worth watching: Lithuania&#8217;s open consultation</h2><p>Litgrid&#8217;s <a href="https://www.litgrid.eu/en/news/public-consultations/public-consultation-on-the-concept-for-isolated-operation-services-of-the-lithuanian-electricity-system">consultation on regional isolated-operation services</a> is worth reading if you want to go deeper. It is open until 10 December 2026.</p><p>I would be particularly interested in the technical requirements for restoration, sustained islanded operation, resource availability, and interactions between local control and the national system operator.</p><p>This is where an attractive architecture diagram has to turn into engineering requirements that can actually be tested.</p><div><hr></div><h2>The thread I see this week</h2><p>I keep coming back to the different roles that network connections play in these stories. Lithuania wants to keep supplying electricity when some of them fail. Britain is spending billions because existing connections cannot always carry the electricity that is available. Norway needs to know how huge, software-controlled consumers will behave before connecting them. And Plexigrid is looking at how much additional capacity a network actually has as conditions change.</p><p>These are different problems, and I don&#8217;t think there is one solution for all of them.</p><p><strong>Our software needs to represent the grid&#8217;s physical limits, operating modes and failure dependencies alongside its nominal capacity.</strong></p><p>Better models and algorithms can improve planning, dispatch, coordination and utilization. Stronger infrastructure, local reserves and carefully designed protection are still essential.</p><p>The cloud analogies are useful to a point. Electrical networks bring constraints that software infrastructure rarely has to consider.</p><p>I still see useful lessons from distributed systems here: identify failure domains, avoid hidden shared dependencies, understand degraded modes, maintain observability, and test recovery.</p><p>Here, a failed recovery procedure can interrupt electricity supply, with consequences far beyond a failed API request.</p><p>See you next week.</p><p>&#8212; <strong>Dmytro</strong></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption"><em>Software in the Grid explores how software actually works inside modern power infrastructure&#8212;from protocols and networking to SCADA, cybersecurity, distributed systems and software architecture.</em></p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p><em>Software in the Grid is an independent publication. The views expressed here are my own.</em></p><p></p>]]></content:encoded></item><item><title><![CDATA[Rebuilding a Substation From First Principles]]></title><description><![CDATA[The central hub for the series.]]></description><link>https://www.softwareinthegrid.com/p/rebuilding-a-substation-from-first</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/rebuilding-a-substation-from-first</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Wed, 11 Nov 2026 20:16:57 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!sPRD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6931f4ab-c95a-4499-9a00-a8c3845272f9_1672x941.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sPRD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6931f4ab-c95a-4499-9a00-a8c3845272f9_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sPRD!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6931f4ab-c95a-4499-9a00-a8c3845272f9_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!sPRD!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6931f4ab-c95a-4499-9a00-a8c3845272f9_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!sPRD!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6931f4ab-c95a-4499-9a00-a8c3845272f9_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!sPRD!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6931f4ab-c95a-4499-9a00-a8c3845272f9_1672x941.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sPRD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6931f4ab-c95a-4499-9a00-a8c3845272f9_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6931f4ab-c95a-4499-9a00-a8c3845272f9_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2460739,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/224503140?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6931f4ab-c95a-4499-9a00-a8c3845272f9_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!sPRD!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6931f4ab-c95a-4499-9a00-a8c3845272f9_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!sPRD!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6931f4ab-c95a-4499-9a00-a8c3845272f9_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!sPRD!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6931f4ab-c95a-4499-9a00-a8c3845272f9_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!sPRD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6931f4ab-c95a-4499-9a00-a8c3845272f9_1672x941.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>AI is booming. And everything that makes it work is booming as well.</p><p>And that creates scarcity for some of the main building blocks. Computational hardware is a known problem, and RAM already costs a small fortune. But just because something is in the middle of the loudest hype, does it mean that it is the most important part?</p><h3>What if the bigger problem lies somewhere much more boring, in something we barely even notice?</h3><p>Electricity is the backbone of AI and everything behind it: data centers, computers, servers, and all the infrastructure that makes them work.</p><p>Connecting a datacenter to the electrical grid requires a huge amount of work and infrastructure. Electricity has to be generated, transmitted, transformed, and distributed. And one of the key elements that makes all of this possible is the transformer.</p><p>Transformers are essential on both sides of the grid. At large power plants, they increase the voltage to make long-distance transmission more efficient. On the consumer side, they reduce it to the levels required by factories, data centers, cities, and our homes. And between these two sides, electricity may pass through several more transformers before reaching its destination.</p><p>Now think about what happens when electricity demand grows. We need more generation capacity, more connections for new consumers, and often more infrastructure between them. New power plants need to be connected to the grid, and new consumers need to receive electricity from it. That means more transformers, more substations, and more equipment to make the whole system work.</p><h3>But are transformers a real bottleneck? Do we have any problems here?</h3><p>Surprisingly, yes. Increasing electricity demand, grid expansion, and the need to replace old equipment have created serious problems with transformer availability. For example, to the <a href="https://www.iea.org/reports/building-the-future-transmission-grid/executive-summary">International Energy Agency</a>, procuring a large power transformer can take up to four years.</p><p>Imagine building an entire datacenter and then discovering that you might have to wait years for the equipment needed to connect it to the grid.</p><h3>But let&#8217;s say we have our transformer. What follows it? </h3><p>Is placing a transformer between the grid and our consumer enough to deliver electricity safely and reliably? What happens when something goes wrong, and how do we make all these electrical components work together?</p><p><strong>That&#8217;s what we&#8217;re going to figure out in this series.</strong></p><p>The AI boom is just an illustrative example, the hook I used, to show how almost everything that requires electricity depends on transformers and a much more complex system around them. A system that includes switching equipment, protection relays, measurement devices, control systems, and communication networks. Much of this equipment comes together in what we call a <strong>substation</strong>.</p><p>In this series, we&#8217;ll look at how a typical substation works, what parts it has, and what functions they perform. But instead of starting with an existing substation and explaining every component, we&#8217;ll try to rebuild one from first principles. We&#8217;ll start with a power source and a consumer, encounter problems along the way, and introduce new components as we figure out why we need them.</p><p>And most interestingly, we&#8217;ll look at how all these components communicate with each other, how they work together, and, perhaps even more importantly, how one substation is connected to a much larger, interconnected electrical network: the <strong><a href="https://www.softwareinthegrid.com/p/a-developers-map-of-the-european">power grid</a></strong>.</p><div><hr></div><p>This article will serve as the central hub for the series, and I&#8217;ll update it as new parts are published.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Software in the Grid is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Networking Machinery for Software Engineers Part 4: Rebuilding a Network Inside One Linux Machine]]></title><description><![CDATA[Build two sensor networks, connect their logical devices, and trace a supervisor request through routing and NAT in a hands-on Linux lab.]]></description><link>https://www.softwareinthegrid.com/p/networking-machinery-for-software-323</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/networking-machinery-for-software-323</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Sat, 17 Oct 2026 20:33:10 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!7DWE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76d0fb2a-9816-4860-b7bb-2d139b51347a_1672x941.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7DWE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76d0fb2a-9816-4860-b7bb-2d139b51347a_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7DWE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76d0fb2a-9816-4860-b7bb-2d139b51347a_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!7DWE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76d0fb2a-9816-4860-b7bb-2d139b51347a_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!7DWE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76d0fb2a-9816-4860-b7bb-2d139b51347a_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!7DWE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76d0fb2a-9816-4860-b7bb-2d139b51347a_1672x941.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7DWE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76d0fb2a-9816-4860-b7bb-2d139b51347a_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/76d0fb2a-9816-4860-b7bb-2d139b51347a_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2164831,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/220904040?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76d0fb2a-9816-4860-b7bb-2d139b51347a_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!7DWE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76d0fb2a-9816-4860-b7bb-2d139b51347a_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!7DWE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76d0fb2a-9816-4860-b7bb-2d139b51347a_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!7DWE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76d0fb2a-9816-4860-b7bb-2d139b51347a_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!7DWE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76d0fb2a-9816-4860-b7bb-2d139b51347a_1672x941.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-tqxFUX" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-tqxFUX" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>Previous Article:</strong></h3><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;14de22b6-2d27-4693-9a50-6868fc5f21ed&quot;,&quot;caption&quot;:&quot;Previous part:&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Networking Machinery for Software Engineers Part 3: Inside the Linux Networking Stack&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer in the energy sector. I publish Software in the Grid, exploring how software works inside modern power infrastructure.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-10-03T17:58:46.849Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!xaga!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55e49167-4d3a-482a-ae8d-af5c40454628_1672x941.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/inside-the-linux-networking-stack&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:218666073,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:1,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:false,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><p><a href="https://www.softwareinthegrid.com/p/networking-in-the-power-grid-for">In the first three parts of this series</a>, we followed Ethernet frames across a local network, IP packets between networks, and traffic through the Linux networking stack. We now know the machinery behind a network connection. The next challenge is to put those pieces together and build a networked system we can actually test.</p><p>The power grid is a network of networks, and software that monitors, operates, protects, or simulates it often has to respect the same boundaries. An application might receive measurements on one interface, exchange information with other devices on a second, and expose a service to a supervisor on a third.</p><p>If we want to develop or test such an application, we need an environment that reproduces more than its individual connections. We need the relevant devices, Ethernet segments, routes, and communication paths, together with a way to observe what happens when something changes or fails.</p><p>We could build the setup with physical computers, switches, and a router. But even a small test network costs money, takes space, and needs maintenance. Change a requirement, add another device, or investigate a routing problem, and suddenly the environment itself can demand more attention than the software we wanted to test.</p><p>Fortunately, Linux gives us the tools to recreate this kind of topology on a single machine. Network namespaces, virtual Ethernet interfaces, bridges, routing, and NAT let us build realistic communication paths without filling an office with hardware.</p><p>In this post you will learn how these pieces fit together by building a small, grid-inspired network. I&#8217;ve prepared a hands-on Killercoda course that begins with an empty topology and gradually adds devices, networks, and new requirements.</p><p style="text-align: center;"><strong><a href="https://killercoda.com/dmytrohuzz/course/killercoda/virtual-energy-network">Open the interactive course: Build an energy network with Linux</a></strong></p><p>The course provides commands, expected observations, and checkpoints. This companion article explains the architecture we are building, why its boundaries matter, and what to look for in the terminal. You can keep it open alongside the interactive lab.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.softwareinthegrid.com/subscribe?"><span>Subscribe now</span></a></p><h2>The system we will build</h2><p>We will start with one local network, add an independent second network, and then introduce communication between devices and a supervisor. Each new requirement will give us a reason to add another piece of Linux networking.</p><h3>One local network: a measurement becomes an alarm</h3><p>Imagine a voltage source we want to monitor. We need to read its value, decide whether it has reached an alarm threshold, and show the result on an indicator. To keep the network behavior visible, we will separate those responsibilities into three devices.</p><p>We will put three devices on one Ethernet LAN. Let&#8217;s call it the <strong>Sensor LAN</strong>:</p><ol><li><p><strong>A sensor</strong> reads the voltage value once per second and publishes the measurement as a Layer 2 multicast message. It reports what it measured; it does not decide whether the value is acceptable.</p></li><li><p><strong>A logical device</strong> listens to the Sensor LAN and compares each measurement with a configured threshold. When the value reaches or exceeds that threshold, it raises its local alarm and publishes an ON command on the same LAN. When the value falls below the threshold, it publishes an OFF command.</p></li><li><p><strong>An LED with a small controller</strong> listens for those commands and turns its indicator on or off. It does not need to know the threshold or repeat the logical device&#8217;s decision.</p></li></ol><p>In the lab, three Python programs play these roles. A file stands in for the voltage source, while the LED&#8217;s state appears in a log. We use demonstration integers rather than calibrated voltage readings: an input of 5 keeps the alarm clear, while 15 exceeds the threshold of 10.</p><p>This gives us a complete path to test: the sensor publishes a measurement, the logical device evaluates it and publishes an alarm command, and the indicator follows that command. The programs publish repeatedly, so we can observe the result both when the value changes and after the system has settled.</p><p>All three devices share one Ethernet segment. The measurement and command messages use Ethernet multicast directly, so this first network does not require IP addresses. In a physical setup, we would connect the devices to a switch. In our Linux setup, we will give each device a network namespace, connect it with a veth pair, and use a bridge as the switch.</p><h3>Multiple local networks: devices share their alarm information</h3><p>A single LAN is a useful start, but a networked system becomes more interesting when we need to preserve boundaries between independent subsystems.</p><p>Suppose we have several voltage sources, each with its own sensor, logical device, and LED. Each subsystem should keep its own Sensor LAN, so a measurement from one does not automatically appear on another. In the course, we will build two of these subsystems.</p><p>At the same time, we want the logical devices to know when another subsystem has an alarm. For that, we introduce one additional network: the <strong>Operator LAN</strong>.</p><p>The new requirements are:</p><ol><li><p><strong>Each logical device gets a second network interface.</strong> Its first interface stays on its own Sensor LAN; its second connects to the shared Operator LAN.</p></li><li><p><strong>Each logical device publishes its local alarm state on the Operator LAN.</strong> Here it uses an IP multicast message carried over UDP, identifying the device and whether its alarm is ON or OFF.</p></li><li><p><strong>The logical devices listen for those notifications and store the received alarm information locally.</strong> So now each Logical Device contains both types of information: its own state and the alarms from other devices.</p></li></ol><p>For example, Sensor1 reports a high value while Sensor2 remains low. LD1 raises its local alarm, turns LED1 on, and publishes an operator notification. LD2 receives that notification and remembers that LD1 has an alarm, but LD2&#8217;s own local alarm stays clear and LED2 remains off.</p><p>Notice what has crossed the boundary: <strong>information about the alarm</strong>. LD1 has received a measurement on one network and created a new message on another. We have not connected the two Sensor LANs into one large Ethernet segment, and Sensor1&#8217;s original frame does not travel into Sensor LAN 2.</p><p>In a physical setup, these would be distinct switched Ethernet segments, with the logical devices connected to both their local Sensor LAN and the shared Operator LAN. On Linux, we represent them with separate bridges and additional veth connections. The tutorial calls each repeated sensor/device/indicator subsystem a <strong>bay</strong>.</p><h3>A supervisor on another network: first routing, then NAT</h3><p>The logical devices can now exchange alarm information, but operators also need a way to inspect their state from another network.</p><p>We will run a <strong>supervisor</strong> on a different subnet and let it request the status of each logical device. Each response identifies the device, reports its local alarm state, and lists the other device alarms it has heard on the Operator LAN.</p><p>For this purpose, each logical-device application also exposes a small TCP status service on its Operator LAN address, using port 10000. The supervisor is on a different subnet, so reaching those services requires a gateway connected to both networks, IP forwarding, and routes for both requests and replies.</p><p>First, we will make the connection work with ordinary IP routing. That is enough for the supervisor to reach the devices by their internal addresses. Then we will introduce a separate requirement: give the supervisor stable service addresses on the gateway side, so its configuration does not have to refer directly to each logical device&#8217;s Operator LAN address. In this example, destination NAT (DNAT) maps those service addresses to the devices.</p><p>In the lab, the mappings will be:</p><ul><li><p>A connection to <strong>192.0.2.10:10000</strong> reaches LD1 at <strong>10.20.0.11:10000</strong>.</p></li><li><p>A connection to <strong>192.0.2.11:10000</strong> reaches LD2 at <strong>10.20.0.12:10000</strong>.</p></li></ul><p>These are gateway-owned service addresses on our simulated WAN. We use the documentation prefix <code>192.0.2.0/24</code> to represent an external-facing subnet, but every address remains inside the lab. Nothing is exposed to the public Internet.</p><p>A physical gateway could perform this translation with destination NAT rules. In the lab, a gateway namespace and <code>iptables</code> do the same job. The supervisor opens a TCP connection to a gateway alias, the gateway rewrites the destination and forwards the packets, and the reply returns through the gateway with the reverse translation applied by connection tracking. Routing still matters, and NAT alone is not a security boundary.</p><p>By now, a simple sensor and indicator have grown into a small network of networks: two separate measurement systems, a shared network for device notifications, and another network for supervisory access. <strong>That is the complete system we will reconstruct in the hands-on course.</strong></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Ct0Z!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F608fbf0b-f2ee-4988-9031-e4aa3fbc994c_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Ct0Z!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F608fbf0b-f2ee-4988-9031-e4aa3fbc994c_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!Ct0Z!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F608fbf0b-f2ee-4988-9031-e4aa3fbc994c_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!Ct0Z!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F608fbf0b-f2ee-4988-9031-e4aa3fbc994c_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!Ct0Z!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F608fbf0b-f2ee-4988-9031-e4aa3fbc994c_1536x1024.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!Ct0Z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F608fbf0b-f2ee-4988-9031-e4aa3fbc994c_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/608fbf0b-f2ee-4988-9031-e4aa3fbc994c_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1284967,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/220904040?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F608fbf0b-f2ee-4988-9031-e4aa3fbc994c_1536x1024.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Ct0Z!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F608fbf0b-f2ee-4988-9031-e4aa3fbc994c_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!Ct0Z!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F608fbf0b-f2ee-4988-9031-e4aa3fbc994c_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!Ct0Z!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F608fbf0b-f2ee-4988-9031-e4aa3fbc994c_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!Ct0Z!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F608fbf0b-f2ee-4988-9031-e4aa3fbc994c_1536x1024.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-tqxFUX" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-tqxFUX" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Two separate Sensor LANs connect through their logical devices to a shared Operator LAN. The supervisor reaches device status through a gateway. All connections and devices are represented inside one Linux machine.</em></p><p>The completed topology contains eight device namespaces, three Linux bridges, and a direct veth connection between the gateway and the supervisor. The drawing shows physical and logical connections; application messages can travel in different directions depending on the service.</p><p>Here, <em>bay</em> means one repeated sensor, logical device, and indicator subsystem. LD1 and LD2 are small Python applications that play an intelligent-device role; their names do not mean that we have implemented the IEC 61850 logical-device model.</p><p>Everything runs on one Linux kernel. The network interfaces, Ethernet switching, IP routing, and packet processing are real Linux mechanisms, while the individual devices, cables, and switches are represented in software.</p><p>This is also where the grid connection becomes useful. In a real substation, measurements, device-to-device information, and supervisory communication can have different network boundaries and requirements. Our small model deliberately separates those roles, so we can test communication across the boundaries before introducing actual substation protocols or equipment.</p><h2>The Linux objects behind the drawing</h2><p>The course introduces each Linux tool at the moment we need it. Before opening the terminal, it helps to have a mental picture of the objects behind the topology.</p><p>A <strong>network namespace</strong> gives a device its own view of the network stack, including interfaces, routes, neighbor tables, sockets, and firewall rules. Creating a namespace does not automatically connect it to anything. In lesson 1, a new device starts with only a loopback interface.</p><p>A <strong>veth pair</strong> provides two connected virtual Ethernet interfaces. Traffic transmitted from one end arrives at the other. We move one end into a device namespace and usually keep the other as a port on a Linux bridge in the host namespace.</p><p>A <strong>Linux bridge</strong> connects those switch-side ports into one Ethernet LAN. Its forwarding database associates learned MAC addresses with ports. That differs from an IP routing table, which selects the next hop for packets sent between IP networks.</p><p>A <strong>gateway namespace</strong> has an interface in each of two IP subnets. Its presence alone does not make it a router: we must enable IP forwarding and configure the routes that allow the endpoints to exchange requests and replies.</p><p>A network namespace is <strong>not a virtual machine</strong>. It isolates networking resources, not the kernel or filesystem. In this lab, the programs share the underlying kernel and filesystem, so the sensor can read a file you edit from the host shell while using its own isolated network stack. The Linux manual lists the resources isolated by <a href="https://man7.org/linux/man-pages/man7/network_namespaces.7.html">network namespaces</a>.</p><p>One detail will prevent confusion during the exercises: <strong>host</strong> means the disposable Ubuntu machine provided by Killercoda. A command such as <code>ip -n lab-s1</code> inspects or changes the sensor namespace&#8217;s networking state, while <code>ip netns exec lab-s1 ...</code> runs a command inside that namespace. Neither command permanently moves your terminal into the sensor.</p><h2>How to work through the course</h2><p>You need basic familiarity with the shell, Python, IP addresses, and switches, plus a general idea of what a substation does. The earlier <a href="https://www.softwareinthegrid.com/p/networking-in-the-power-grid-for">networking series index</a> provides the networking context, while <a href="https://www.softwareinthegrid.com/p/a-developers-map-of-the-european">A Developer&#8217;s Map of the European Power Grid</a> provides the wider industry context.</p><p>The exercises introduce Linux namespaces from the beginning, so you do not need prior container or IEC 61850 experience.</p><p>Plan for roughly <strong>45&#8211;60 minutes for the guided path</strong>, with more time if you want to experiment. Killercoda environments expire, so keep an eye on the timer and save anything you want to retain.</p><p>The ten lessons build the topology in this order:</p><p>Lessons What you build and learn 1&#8211;3 Separate network stacks, follow both veth ends, and join devices through a bridge. 4 Run the applications, capture Ethernet frames, and trigger a local alarm. 5&#8211;6 Repeat a bay, preserve its LAN boundary, and exchange operator notifications. 7&#8211;8 Cable another subnet and make requests and replies cross the gateway. 9 Assign gateway aliases and capture packets before and after DNAT. 10 Break a link and a return route, diagnose the failures, and restore the system.</p><p>Wait for <strong>Ready</strong> before starting the first lesson. Setup installs the required tools and places the example programs in <code>/root/energy-lab</code>; you create the networking connections yourself.</p><p>Follow the command blocks in order, compare the result with the expected observation, and try to predict what will happen before running the next command. Use <strong>Check</strong> at the end of each lesson. A successful check confirms the required state, but it cannot confirm that you understand why the network behaves that way. Try explaining each packet path in your own words.</p><p>One sequencing detail is worth mentioning: lesson 4 prepares LD1&#8217;s operator interface because the supplied program expects both interfaces when it starts. That interface does not connect to the shared Operator LAN until lesson 6.</p><p>In Killercoda, going back to an earlier lesson does not undo the commands you have already run. If you see &#8220;File exists,&#8221; inspect the existing object before repeating a creation command. For a fresh start, the supplied <code>lab.sh reset</code> command clears the lab topology and application state so you can rebuild from lesson 1.</p><p>If you want to work without the online timer, the <a href="https://github.com/DmytroHuzz/virtual-energy-network/blob/main/killercoda/virtual-energy-network/finish.md#continue-on-your-own-linux-machine">closing lesson</a> explains how to prepare the same files in a disposable Ubuntu 24.04 virtual machine.</p><h2>What to take from the lab</h2><p>By the end of the course, you should be able to look at a topology and decide which devices need independent network stacks, which interfaces belong to the same Ethernet segment, and which communication paths require routing.</p><p>More importantly, you should be able to distinguish three very different operations: a bridge forwarding an Ethernet frame, a router forwarding an IP packet, and an application receiving information and creating a new message.</p><p>The example deliberately uses simple protocols to make network behavior easier to observe. It does not implement IEC 61850 GOOSE, Sampled Values, MMS, or a production SCADA service. The sensor reads demonstration integers, the LED records software state, and alarm notifications have no authentication, persistence, or expiry. The lab also cannot reproduce physical-link timing or protection-system performance.</p><p>What it does give us is a way to make the network underneath an application visible and testable, instead of treating interfaces, switching, and routing as an invisible dependency.</p><p>Before finishing, try one exercise without step-by-step instructions: draw a third bay before writing any commands. Give it a separate Sensor LAN and connect its logical device to the Operator LAN. Predict which devices should receive its alarm notification and which LEDs should remain unaffected. Then build it, capture the traffic, and compare the result with your prediction. The supplied helper manages two bays, so you will need to launch any additional roles explicitly.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://killercoda.com/dmytrohuzz/course/killercoda/virtual-energy-network&quot;,&quot;text&quot;:&quot;Start the hands-on Killercoda course&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://killercoda.com/dmytrohuzz/course/killercoda/virtual-energy-network"><span>Start the hands-on Killercoda course</span></a></p><h2>From a Packet to a Networked System</h2><p>In Part 1, we started with two machines on the same local network. Before they could exchange an IP packet, we needed to understand Ethernet frames, MAC addresses, switches, and ARP. In Part 2, we moved the destination beyond the local network and introduced IP addressing, routing tables, and gateways. We saw that the IP destination describes where the packet is going, while Ethernet handles delivery over each local link.</p><p>In Part 3, we turned our attention to the Linux host itself. We followed incoming traffic from the network interface and driver through the kernel networking stack to the application. The socket was no longer just an API call. It was the end of a journey through real operating-system machinery.</p><p>And in this fourth part, we have used those ideas to build a small network of networks on one Linux machine. We created interfaces and links, kept local networks separate, connected applications across them, and watched how routing and NAT affected communication. We also introduced faults, because understanding a network means knowing how to investigate it when something stops working.</p><p>In this series I wanted to understand what happens beneath networked software well enough to investigate and understand, build and create more complex systems myself. This is still a foundation, not a production substation design. We have deliberately left industrial protocol behavior, redundancy, time synchronization, and security requirements for later. But now we can approach those subjects with a working model of the network underneath them. The next step is to use that model to understand how substations, IEC 61850, IEC 60870-5-104, and SCADA systems actually communicate.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Software in the Grid is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h3><strong>Series Hub:</strong></h3><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;5c86a94a-72da-45d7-b317-59504eb54e86&quot;,&quot;caption&quot;:&quot;I have worked with networked software for years, but for most of that time the network was something I used rather than something I really understood. I could open a socket, call an API, connect to an IP address, and continue with the part of the system I was responsible for.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;lg&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Networking Machinery for Software Engineers&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer in the energy sector. I publish Software in the Grid, exploring how software works inside modern power infrastructure.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-08-27T21:18:02.367Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!sXgD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2f83a8-82b3-42d5-817b-5266707341bb_1672x941.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/networking-in-the-power-grid-for&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:213058272,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><p></p>]]></content:encoded></item><item><title><![CDATA[Pulse #2 - The grid has a scaling problem. Software is part of the answer.]]></title><description><![CDATA[Week of 5&#8211;9 October 2026]]></description><link>https://www.softwareinthegrid.com/p/pulse-2-the-grid-has-a-scaling-problem</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/pulse-2-the-grid-has-a-scaling-problem</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Fri, 09 Oct 2026 12:55:54 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!M0GQ!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>Week of 5&#8211;9 October 2026</em></p><p>I keep coming back to the same question when reading about the energy transition: how do we actually scale a system as large as the power grid?</p><p>The obvious answer is physical. More generation. More batteries. More substations and power lines.</p><p>But I think there is another part of the answer that is easy to miss.</p><p>In software engineering, we distinguish between <strong>horizontal scaling</strong> - adding more machines - and <strong>vertical scaling</strong> - increasing the capacity of existing machines. The power grid is not a cluster of servers, but I find the distinction useful here too.</p><p><strong>Horizontally</strong>, we need more generation, storage, substations, lines and connections. That means more assets, planning models, engineering tools and organizations that need to work together.</p><p><strong>Vertically</strong>, we need to make better use of the infrastructure we already have through measurements, forecasting, flexible demand and smarter control. The analogy is not exact: these approaches do not simply upgrade a power line the way we add CPU or RAM to a server. They help the system operate more intelligently within its physical limits.</p><p>Both directions create software problems.</p><p>This week&#8217;s developments gave me several good examples.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.softwareinthegrid.com/subscribe?"><span>Subscribe now</span></a></p><h2>Main signal: the grid needs an interoperability layer</h2><p>On 7 October, the <a href="https://www.linuxfoundation.org/press/linux-foundation-launches-opengrid-to-build-open-shared-infrastructure-for-the-worlds-electric-grid?hs_amp=true">Linux Foundation announced OpenGrid</a>, a new open-source initiative focused on electricity-grid planning.</p><p>The motivation is straightforward: planning the grid is becoming more difficult just as we need to build it faster.</p><p>According to the <a href="https://www.iea.org/reports/electricity-2026/demand">IEA&#8217;s Electricity 2026 outlook</a>, global electricity consumption is projected to rise from about 28,200 TWh in 2025 to 33,600 TWh in 2030. That is roughly 19% growth in five years. Almost quarter. It is an enormous amount of additional electricity to produce, deliver and manage.</p><p>And the bottleneck is already visible. The <a href="https://www.iea.org/reports/electricity-2026/grids">IEA reports</a> more than 2,500 GW of renewable generation, storage and large-load projects stalled in grid-connection queues worldwide.</p><p>The grid is also becoming more distributed. Instead of planning around a relatively small number of large power plants and predictable consumers, engineers increasingly have to consider solar installations, wind farms, batteries, electric vehicles, data centres and flexible industrial loads.</p><p>Many more participants. Many more possible operating conditions.</p><p>This is where it starts to look like a software architecture problem.</p><h3>The problem behind the announcement</h3><p>Imagine an engineer studying what will happen if a region adds a new battery park, several solar installations and a large industrial consumer.</p><p>They need network topology, equipment parameters, load and generation forecasts, connection requests, and assumptions about future operating conditions. They may use several modelling tools, each with its own representation of the network.</p><p>Now the engineer needs to move a model from one tool into another.</p><p>What happens to identifiers, units, equipment definitions, assumptions, or the relationships between network elements?</p><p>Can another team reproduce the result? Can a regulator inspect the model? Can someone compare two scenarios without rebuilding everything by hand?</p><p>These are familiar questions for software engineers. We have seen them in databases, APIs, distributed systems and data pipelines.</p><p><strong>The difficulty is no longer only solving the electrical equations. It is getting the right engineering information into the right tool, preserving its meaning, and being able to trust the result.</strong></p><p>That is the problem OpenGrid is trying to address.</p><p>The proposed foundation includes shared schemas and standards, programmatic APIs, integrations, and a Data Hub for validated, model-ready datasets. Its first planned application, <strong>OpenGrid Translator</strong>, is intended to move data and models between commercial and open-source planning tools, with a release targeted for 2027.</p><p><strong>The main focus of OpenGrid now is interoperability between grid-planning tools.</strong></p><p>And it is not yet a finished platform. The initiative has launched; much of the proposed architecture still has to be built and proven.</p><h3>Why I find it interesting</h3><p>There is a pattern here that I recognize from software engineering.</p><p>As a system grows, connecting its parts becomes a problem of its own. At first, you can build a custom converter, export a file or agree on an internal format. Eventually there are too many participants and too many combinations.</p><p>At that point, shared models and well-defined interfaces stop being conveniences. They become infrastructure.</p><p>The power grid cannot be scaled by software alone. We still need copper, steel, transformers and years of physical construction.</p><p>But if planning tools cannot exchange and validate the information needed to build that infrastructure, software itself becomes another bottleneck.</p><p>I like the idea of applying open-source collaboration and explicit interoperability contracts to that layer of the power system.</p><p>The question now is whether OpenGrid can move beyond a good architectural proposal into models, adapters and workflows that engineers actually trust and use.</p><div><hr></div><h2>Around the grid</h2><h3>Getting more out of existing power lines</h3><p>Building more grid infrastructure is one way to increase capacity. But sometimes the existing infrastructure can be used more intelligently.</p><p>On 6 October, Portuguese grid-technology company Enline published a <a href="https://enline.energy/white-papers/dynamic-line-rating-at-the-distribution-edge">white paper on Dynamic Line Rating at the distribution edge</a>.</p><p>A power line has thermal limits. The current flowing through it generates heat, while wind, air temperature and other conditions determine how effectively it cools.</p><p>Traditionally, operators often work with ratings based on conservative assumed conditions.</p><p><strong>Dynamic Line Rating (DLR)</strong> estimates how much current a line can safely carry under the actual or forecast conditions.</p><p>If the weather allows better cooling, there may be more thermal headroom. If conditions become worse, the safe rating may decrease.</p><p>The interesting part is the software around it:</p><p>measurements and weather data &#8594; thermal model &#8594; calculated rating &#8594; operational decision</p><p>Yes, the <a href="https://enline.energy/white-papers/dynamic-line-rating-at-the-distribution-edge">paper is vendor-authored</a>, so I would treat its projected investment savings as claims to investigate rather than settled results.</p><p>But anyway, the architectural direction is clear: <strong>more data about a physical asset can change how much useful work we can safely get from it.</strong></p><p>&#8220;More data&#8221; &#8230;. sounds so familiar &#128578;</p><h3>What if a data centre could become a flexible load?</h3><p>There is another way to make better use of existing grid capacity: change demand rather than the line.</p><p>On 8 October, <a href="https://www.reuters.com/business/energy/data-centers-flexible-power-usage-could-save-grid-billions-can-they-scale-2026-10-08/">Reuters examined efforts to make data-centre electricity consumption more flexible</a>.</p><p>The idea is to temporarily reduce or shift some computing workloads when the electricity system is under pressure.</p><p>Some data centres may be able to reduce peak consumption by around 10&#8211;30%, according to the examples discussed in the report. That is not a universal capability. Critical workloads, service commitments, cooling, on-site power systems and the duration of a request all limit what can actually be shifted.</p><p>From a software perspective, the question is fascinating.</p><p>A scheduler normally decides <strong>where</strong> and <strong>when</strong> work runs according to computing resources, deadlines and availability.</p><p>What happens when electrical-grid conditions become another scheduling input?</p><p>Now the data centre&#8217;s workload orchestrator, energy-management system and grid operator may need to coordinate.</p><p>It is another kind of scaling: instead of increasing the capacity available at every instant, make parts of demand flexible enough to fit the capacity we have.</p><div><hr></div><h3>Big technology companies are moving closer to the power system</h3><p>Two announcements this week caught my attention for different reasons.</p><p>On 6 October, <a href="https://www.constellationenergy.com/news/2026/10/google-and-constellation-announce-landmark-agreement-to-bring-890-mw-of-new-nuclear-capacity-to-pjm-grid.html">Google and Constellation Energy announced a long-term collaboration</a>. The agreement supports <strong>890 MW of additional nuclear capacity</strong> through upgrades at existing reactors, alongside a separate long-term 2,700 MW supply agreement.</p><p>The companies also announced a technology partnership involving Google Cloud and Gemini Enterprise for energy applications, including infrastructure planning, asset optimization and reliability.</p><p>These are agreements and plans, not evidence that an AI system is already autonomously controlling the grid.</p><p>On 8 October, <a href="https://www.anthropic.com/news/anthropic-cyber-mission">Anthropic launched its Cyber Mission</a>, including a Critical Infrastructure Defense Program focused on operational technology - the control systems, industrial networks and software used by power grids and other physical infrastructure.</p><p>These are not the same kind of investment.</p><p>Google is involved because its computing infrastructure needs enormous amounts of reliable electricity. Anthropic is approaching the sector through cybersecurity capabilities and partnerships.</p><p>But the direction is worth watching.</p><p>The technology industry is no longer only consuming electricity and building software for other software companies. It is becoming more deeply involved in how energy infrastructure is financed, operated, analysed and protected.</p><p>That creates opportunities, but also new dependencies worth understanding.</p><div><hr></div><h2>Worth watching: cybersecurity has to catch up with grid software</h2><p>All the developments above show what more software can do for the grid. But there is another side to this growth that concerns me.</p><p><strong>I think cybersecurity is becoming one of the most urgent engineering challenges for modern power infrastructure.</strong></p><p>Consider how the IT industry got here. Cloud platforms did not become reasonably good at isolating workloads, controlling identities, deploying updates, monitoring failures and responding to incidents overnight. Those practices evolved over years of building complex systems, defending them against attacks and learning from failures. And even today, cloud providers are far from immune to security problems.</p><p>Now look at what is happening in energy.</p><p>The industry is connecting more and more equipment to cloud services, remote-management platforms, APIs and software-update systems. Solar inverters, batteries, EV chargers and industrial controllers increasingly behave like nodes in a huge distributed software system.</p><p>But much of the physical infrastructure was designed in a different world: long equipment lifetimes, controlled access, limited connectivity and very strict availability requirements.</p><p>This does <strong>not</strong> mean that the energy sector has no cybersecurity experience. OT engineers have worked on network segmentation, secure operations and industrial security for decades. Standards such as <a href="https://webstore.iec.ch/en/publication/62883">IEC 62443</a> are part of that work.</p><p>My concern is more specific: <strong>the software architecture is changing faster than the security practices around the whole connected system can mature.</strong></p><p>A good example appeared on 7 October, when the Dutch <a href="https://www.rdi.nl/actueel/nieuws/2026/10/07/verbonden-energieapparaten-kunnen-leiden-tot-verstoring-van-elektriciteitsnet">Rijksinspectie Digitale Infrastructuur (RDI) published a position paper</a> about <em>high-power IoT</em>: connected inverters, chargers, home batteries and heat pumps.</p><p>One device is not necessarily the problem. The interesting risk appears when thousands of devices depend on the same software platform.</p><p><strong>cloud service &#8594; authenticated command or software update &#8594; device fleet &#8594; aggregate electrical load or generation</strong></p><p>If a platform is compromised, or a faulty update reaches a large fleet, the consequences may no longer be confined to one customer or one device. A shared software failure could produce a shared physical effect. That is a risk scenario, not a claim that such a grid-wide incident has already happened.</p><p>The RDI argues that cybersecurity requirements should take into account how much electrical power can be influenced through remote control. That is a different way to think about the importance of a software system.</p><p>And this is where simply borrowing cloud practices is not enough.</p><p>A cloud provider can often isolate a service, deploy a fix and roll back a release relatively quickly. A protection relay, inverter or industrial controller may need extensive validation and a carefully planned maintenance window. An update that breaks the software is not just an availability incident; it can affect the physical process.</p><p>Still, we need the same underlying engineering discipline: strong identity and authorization, limited privileges, trustworthy updates, observability, containment, incident response and the ability to recover safely.</p><p><strong>We are turning power infrastructure into an increasingly complex distributed software system. Its security maturity has to catch up quickly - without forgetting that this system cannot be operated like an ordinary cloud cluster.</strong></p><p>That seems to me just as important as connecting more assets or using existing capacity more efficiently.</p><div><hr></div><h2>The thread I see this week</h2><p>At first, these stories appear to point in different directions.</p><p>OpenGrid wants planning tools to exchange models.</p><p>Dynamic Line Rating wants to extract more usable capacity from existing lines.</p><p>Flexible data centres want to adjust their consumption to grid conditions.</p><p>Technology companies are investing in energy and its software.</p><p>Cybersecurity regulators are asking what happens when many physical devices depend on shared digital infrastructure.</p><p>But I see a common engineering problem: <strong>the grid needs to scale not only its hardware, but also the software systems that describe, coordinate and protect that hardware.</strong></p><p>Horizontal scaling needs trustworthy models and interoperability.</p><p>Making better use of existing capacity - the vertical side of this analogy - needs measurements, forecasting and control.</p><p>And both require security that grows with the system&#8217;s complexity.</p><p>We cannot solve the energy transition by writing better software. But I increasingly doubt we can solve it <em>without</em> better software.</p><p>That is the part of modern power infrastructure I want to keep investigating.</p><p>See you next week.</p><p>- Dmytro</p><p><em>Software in the Grid explores how software actually works inside modern power infrastructure - from protocols and networking to SCADA, cybersecurity, distributed systems and software architecture.</em></p><p><em>Software in the Grid is an independent publication. The views expressed here are my own.</em></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Software in the Grid is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item><item><title><![CDATA[Building a SCADA System from First Principles (Coming soon)]]></title><description><![CDATA[From substations and gateways to IEC 60870-5-104, telemetry, commands, and control-centre software.]]></description><link>https://www.softwareinthegrid.com/p/building-a-scada-system-from-first</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/building-a-scada-system-from-first</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Tue, 06 Oct 2026 12:20:48 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!h7FJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7fcdf04-16b9-46b7-8045-6a4cc342e715_1672x941.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!h7FJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7fcdf04-16b9-46b7-8045-6a4cc342e715_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!h7FJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7fcdf04-16b9-46b7-8045-6a4cc342e715_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!h7FJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7fcdf04-16b9-46b7-8045-6a4cc342e715_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!h7FJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7fcdf04-16b9-46b7-8045-6a4cc342e715_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!h7FJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7fcdf04-16b9-46b7-8045-6a4cc342e715_1672x941.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!h7FJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7fcdf04-16b9-46b7-8045-6a4cc342e715_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a7fcdf04-16b9-46b7-8045-6a4cc342e715_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2234433,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/219089434?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7fcdf04-16b9-46b7-8045-6a4cc342e715_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!h7FJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7fcdf04-16b9-46b7-8045-6a4cc342e715_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!h7FJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7fcdf04-16b9-46b7-8045-6a4cc342e715_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!h7FJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7fcdf04-16b9-46b7-8045-6a4cc342e715_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!h7FJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7fcdf04-16b9-46b7-8045-6a4cc342e715_1672x941.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-tqxFUX" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-tqxFUX" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption"><strong>Coming soon &#8212; subscribe to get notified.</strong></p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item><item><title><![CDATA[Pulse #1 — Engineering tools are part of the attack surface]]></title><description><![CDATA[Week of 28 September&#8211;4 October 2026]]></description><link>https://www.softwareinthegrid.com/p/pulse-1-engineering-tools-are-part</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/pulse-1-engineering-tools-are-part</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Mon, 05 Oct 2026 12:09:54 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!M0GQ!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is a small experiment.</p><p>Alongside the longer Software in the Grid deep dives, I want to regularly look at what is changing around the software that runs modern power infrastructure.</p><p>Not everything happening in energy belongs here. The filter is narrower:</p><p><strong>Does this development tell us something interesting about how software inside the power system is built, connected, secured or operated?</strong></p><p>This week, one theme kept appearing: systems that look like ordinary software suddenly become much more interesting when the other side of the interface is physical infrastructure.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Software in the Grid is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2>Main signal: engineering tools are part of the substation attack surface</h2><p>PCM600 is ABB&#8217;s engineering software for protection and control devices used in electrical substations. Many of those devices are IEDs &#8212; <strong>intelligent electronic devices</strong> &#8212; small computers such as protection relays that monitor electrical conditions and perform protection or control functions.</p><p>An engineer can run PCM600 on a Windows workstation, connect to supported devices over the network, work with their settings and configuration, and exchange engineering data with them.</p><p>So PCM600 may look like ordinary desktop software, but its context is very different.</p><p>The machine running it can sit close to devices that participate directly in protecting and operating the electrical system.</p><p>That is what makes two security advisories published by ABB on 28 September interesting.</p><p>The first vulnerability, <a href="https://www.cve.org/CVERecord?id=CVE-2026-15952">CVE-2026-15952</a>, is about privileges on the Windows workstation running PCM600.</p><p>One of PCM600&#8217;s background services can run with elevated permissions. At the same time, a local PCM600 user may be able to change how that service is configured.</p><p>In practice, that creates a dangerous combination: an authenticated local user who belongs to the PCM600 user group may be able to modify a Windows service running with SYSTEM privileges. If exploited successfully, that could allow commands to run with elevated privileges on the workstation.</p><p>The second issue, <a href="https://www.cve.org/CVERecord?id=CVE-2026-15953">CVE-2026-15953</a>, is easier to picture.</p><p>PCM600 can import project archives. A specially crafted archive could contain file paths that point outside the directory where the project is supposed to be extracted.</p><p>Instead of writing files only into the project folder, the archive could potentially overwrite files somewhere else on the workstation, using the permissions of the engineer importing it.</p><p>Both issues are described in <a href="https://www.abb.com/global/en/company/about/cybersecurity/alerts-and-notifications">ABB&#8217;s security notifications</a>.</p><p>The individual CVEs matter, but I find the larger architectural point more interesting.</p><p>When we think about substation cybersecurity, it is natural to focus on the equipment that is visibly part of the operational network:</p><p>protection relays, gateways, station computers, SCADA servers, switches and remote connections.</p><p>But the engineering environment is part of the system too.</p><p>An engineering workstation may hold project files, device credentials and configuration information. It may communicate directly with IEDs and may be trusted to make changes that an ordinary office computer cannot.</p><p>That makes the workstation a meaningful trust boundary.</p><p>This does <strong>not</strong> mean that a vulnerability in PCM600 automatically gives an attacker control of an IED or a substation. That would be an unjustified jump.</p><p>But it does mean that protecting the operational network while treating engineering workstations as ordinary desktop systems is an incomplete security model.</p><p>The interesting question for me is therefore not only:</p><p><strong>How serious are these two vulnerabilities?</strong></p><p>It is also:</p><p><strong>What should the security architecture around a modern substation engineering workstation actually look like?</strong></p><p>Isolation, imported project files, provenance, privileges, update mechanisms, credentials, engineering access and communication with field devices all meet at that point.</p><p>That feels more interesting than another CVE headline.</p><div><hr></div><h2>Around the grid</h2><h3>EV charging software meets a very physical security boundary</h3><p>Another vulnerability this week came from a very different part of the energy system: EV charging.</p><p>Monta provides software for managing charging stations. A charging station can connect to Monta&#8217;s backend using OCPP &#8212; the Open Charge Point Protocol &#8212; over a WebSocket connection.</p><p>That connection is important. It is how the charger and the backend exchange information and commands: the charger can report its state and meter values, while the backend can send commands such as starting or stopping a charging session.</p><p>A simplified view looks like this:</p><p><strong>charging station &#8594; OCPP over WebSocket &#8594; Monta backend &#8594; operator / application</strong></p><p>Now the vulnerability becomes easier to understand.</p><p><a href="https://www.cve.org/CVERecord?id=CVE-2026-95102">CVE-2026-95102</a> concerns insufficient authentication on WebSocket endpoints. According to the vulnerability report, an attacker could use this weakness to impersonate a charging station.</p><p>In other words, the backend may receive a connection that claims to be a real charger without having sufficiently verified that identity.</p><p>This looks like a very familiar software problem: authentication at the boundary between a client and a backend.</p><p>But the &#8220;client&#8221; here is not a browser or another SaaS service.</p><p>It is a physical charging station.</p><p>That changes the consequences.</p><p>The same connection can represent a device that reports measurements, receives commands and controls the delivery of electrical energy to a vehicle. A weakness in authentication therefore crosses the boundary between ordinary backend security and a physical system.</p><p>This is the part I find interesting.</p><p>WebSockets, authentication, backend services and APIs are normal software-engineering territory. But increasingly, the system on the other side of those interfaces is something physical.</p><p>And that raises a broader question:</p><p><strong>Which assumptions from conventional software stop being safe once the software is connected to the physical world?</strong></p><h3>Europe wants more grid-data exchange &#8212; but the architecture matters</h3><p>On 28 September, ENTSO-E published its <a href="https://www.entsoe.eu/2026/09/28/unlocking-electrification-entso-e-position-on-the-future-proof-electricity-bills-proposal/">position on the European Commission&#8217;s Future-proof Electricity Bills proposal</a>.</p><p>Among other things, the proposal touches accelerated grid connections, smart-meter deployment and enhanced grid-data exchange.</p><p>One recommendation caught my attention. ENTSO-E argues that an EU grid-data exchange framework should remain <strong>voluntary, secure, focused and supported by adequate financing</strong>.</p><p>This is policy language.</p><p>But behind it sits a very concrete software problem.</p><p>&#8220;Exchange more grid data&#8221; eventually turns into questions such as:</p><ul><li><p>Which systems expose the data?</p></li><li><p>Which information models describe it?</p></li><li><p>Which organizations are allowed to consume it?</p></li><li><p>How is identity established?</p></li><li><p>How is authorization managed across organizational boundaries?</p></li><li><p>Which interfaces and protocols are used?</p></li><li><p>What are the latency and availability requirements?</p></li><li><p>Who owns compatibility when the model changes?</p></li><li><p>How do you secure all of this without making interoperability impossible?</p></li></ul><p>These are distributed-systems questions as much as energy-policy questions.</p><p>The proposal may be written in Brussels, but somebody eventually has to implement the interfaces.</p><div><hr></div><h2>Worth watching: IEC 61850 meets WebSockets and JSON</h2><p>This one is not strictly from this week, but it is too relevant to Software in the Grid to ignore.</p><p>On 4 September, IEC published Committee Draft 57/2980/CD for IEC 61850-8-3, with comments from the IEC national committees due by 30 October. <a href="https://blog.nettedautomation.com/2026/09/iec-published-committee-draft-572980cd.html">Karlheinz Schwarz documented the Committee Draft publication</a>, while the <a href="https://standardsdevelopment.bsigroup.com/projects/2026-02608">BSI project description</a> gives a useful public summary of what is being proposed.</p><p>To understand why it is interesting, it helps to separate two things inside IEC 61850.</p><p>IEC 61850 defines a rich information model for the power system and a set of abstract communication services called ACSI &#8212; things like reading data, receiving reports or operating controllable objects.</p><p>Those services describe <strong>what</strong> applications want to do.</p><p>They do not by themselves define exactly how the messages should travel over the network.</p><p>That is the job of a communication mapping.</p><p>The familiar IEC 61850 client/server stack uses IEC 61850-8-1, which maps ACSI services onto MMS &#8212; Manufacturing Message Specification &#8212; and then transports them over the usual network stack.</p><p>IEC 61850-8-3 proposes another mapping.</p><p>The important part is that the IEC 61850 information model and ACSI services stay in place. What changes is the way those services are represented and transported.</p><p>Instead of mapping them through MMS, the new approach defines messages more directly. They can be encoded using ASN.1 JSON Encoding Rules for a human-readable, JSON-like representation, or using binary Distinguished Encoding Rules where a more compact representation is useful. The messages are then carried over WebSockets.</p><p>A simplified view looks like this:</p><p><strong>IEC 61850 information model &#8594; ACSI services &#8594; direct message representation &#8594; JSON-like JER or binary DER &#8594; WebSocket</strong></p><p>That makes the proposal much easier to place.</p><p>It is not &#8220;IEC 61850 is replacing MMS with JSON&#8221;.</p><p>It is another communication option alongside the existing mappings.</p><p>And the intended use case is especially interesting.</p><p>The draft targets communication between DSO control centres and potentially large populations of modern devices associated with distributed energy resources &#8212; solar installations, batteries, controllable loads and other DER systems.</p><p>That is a very different environment from a small number of protection devices inside one substation.</p><p>You may have thousands of geographically distributed devices, software-heavy controllers and systems that already live much closer to conventional IP and web technologies.</p><p>In that context, WebSockets and a JSON-like representation start to make much more sense.</p><p>What I like about this development is the broader engineering idea behind it.</p><p>IEC 61850 is a mature system with years of domain knowledge embedded in its information models and services. Instead of throwing that away and designing another completely new protocol, the standard can keep those mature abstractions while adapting the communication layer to newer software requirements.</p><p>I find that a much more interesting story than &#8220;IEC 61850 now supports JSON&#8221;.</p><p>It is a good example of how mature infrastructure can evolve: <strong>preserve the domain model that already works, but modernize the parts that need to interact with a changing software world.</strong></p><p>And it raises several questions I want to investigate properly:</p><p>How does this compare with the traditional MMS mapping?</p><p>Why was WebSocket chosen?</p><p>What does the security architecture look like?</p><p>Where exactly does this communication sit between DER systems and DSO control centres?</p><p>And what becomes easier &#8212; or harder &#8212; for software engineers when IEC 61850 services can be represented this way?</p><p>This deserves a proper technical deep dive.</p><div><hr></div><h2>The thread I see this week</h2><p>These stories look unrelated:</p><p>a Windows service inside an IED engineering tool,</p><p>WebSocket authentication for EV chargers,</p><p>European grid-data exchange,</p><p>and a new IEC 61850 mapping using WebSockets and modern encoding mechanisms.</p><p>But there is a common pattern.</p><p>Power infrastructure is accumulating more of the problems software engineers already recognize:</p><p><strong>authentication, trust boundaries, distributed communication, interoperability and compatibility.</strong></p><p>The difference is what sits on the other side of the software.</p><p>Not another SaaS application.</p><p>Protection systems. Charging infrastructure. Control centres. Distributed energy resources. Physical power flows.</p><p>That boundary between software systems and physical infrastructure is exactly what I want to keep exploring with Software in the Grid.</p><p>See you next week.</p><p>&#8212; Dmytro</p><p><em>Software in the Grid explores how software actually works inside modern power infrastructure &#8212; from protocols and networking to SCADA, cybersecurity, distributed systems and software architecture.</em></p><p><em>Software in the Grid is an independent publication. The views expressed here are my own.</em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.softwareinthegrid.com/subscribe?"><span>Subscribe now</span></a></p><p></p>]]></content:encoded></item><item><title><![CDATA[Networking Machinery for Software Engineers Part 3: Inside the Linux Networking Stack]]></title><description><![CDATA[Understanding how Linux receives and processes network traffic]]></description><link>https://www.softwareinthegrid.com/p/inside-the-linux-networking-stack</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/inside-the-linux-networking-stack</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Sat, 03 Oct 2026 17:58:46 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!xaga!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55e49167-4d3a-482a-ae8d-af5c40454628_1672x941.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xaga!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55e49167-4d3a-482a-ae8d-af5c40454628_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xaga!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55e49167-4d3a-482a-ae8d-af5c40454628_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!xaga!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55e49167-4d3a-482a-ae8d-af5c40454628_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!xaga!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55e49167-4d3a-482a-ae8d-af5c40454628_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!xaga!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55e49167-4d3a-482a-ae8d-af5c40454628_1672x941.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xaga!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55e49167-4d3a-482a-ae8d-af5c40454628_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/55e49167-4d3a-482a-ae8d-af5c40454628_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1579163,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/218666073?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55e49167-4d3a-482a-ae8d-af5c40454628_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!xaga!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55e49167-4d3a-482a-ae8d-af5c40454628_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!xaga!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55e49167-4d3a-482a-ae8d-af5c40454628_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!xaga!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55e49167-4d3a-482a-ae8d-af5c40454628_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!xaga!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55e49167-4d3a-482a-ae8d-af5c40454628_1672x941.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>Previous Article</h3><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;64de5ac1-8020-4f50-b565-fae5070fe4ba&quot;,&quot;caption&quot;:&quot;Previous Article:&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Networking Machinery for Software Engineers Part 2: Extending The Empire and Rebuilding a Global Network&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer in the energy sector. I publish Software in the Grid, exploring how software works inside modern power infrastructure.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-09-02T16:02:36.253Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!JAas!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d96a595-7108-43f7-92b7-4c57c97c5f2a_1672x941.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/networking-machinery-for-software-f6b&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:213862386,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:false,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><h2>Intro</h2><p>The core purpose of a network is to establish communication between multiple nodes. That is already a difficult problem in almost any system, and it becomes even more demanding in critical real-time systems such as the power grid.</p><p>But some of the hardest networking problems do not happen between different devices at all. They happen inside one single machine.</p><p>It is easy to imagine that once an Ethernet frame reaches the network interface, most of the work is already done and everything after that is trivial. It is not. Behind the black box that we casually call the Linux networking stack is another complex system, with its own objects, queues, memory, control paths and state transitions. This is the system I want to open in this part.</p><p>Why should we care about what happens inside one machine? Because some of the most difficult, bug-prone and timing-sensitive problems I have faced were not hidden in the coordination of a huge number of servers or in enormous traffic volumes. They were hidden inside one particular computer that had to process network traffic with extremely strict timing requirements, where a lot could go wrong at very different levels.</p><p>So now I want to open one of the most underestimated black boxes we constantly depend on when working with networked systems: the Linux networking stack.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Software in the Grid is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2>The route</h2><p>I tried several ways to explain the whole concept, and the approach I want to use now is the one I wish I had when I first faced this topic. Instead of showing isolated diagrams, we will keep the state of the whole system visible at the same time. We will see userspace, kernel state, memory structures and the communication between them while one simple story evolves.</p><p>We will start before our tracked network interface exists in the kernel. Then we will watch Linux discover and initialize the NIC, create the interface representation, prepare the receive path, configure the interface, and finally trace one single Ethernet frame from the cable to a userspace application.</p><p>In this post we will discuss the Linux networking stack by following one machine as its networking state evolves. Instead of describing every observable value twice, we will use two languages in parallel: the text will explain <strong>why</strong> a transition happens and what it means, while the dashboard will show <strong>what exists now</strong>, what changed, which command was executed, and what the system returned. Long-lived state such as <code>net_device</code>, routing state and the RX machinery will stay in fixed places, while transient objects such as <code>sk_buff</code> will appear only when they actually exist.</p><p>There is one deliberate simplification. We follow one physical NIC and the Linux interface that represents it. State 0 therefore shows our tracked <code>net_device</code>, RX queue and routes as absent even though a real Linux system can already contain other interfaces, especially loopback. The goal is to make the birth and evolution of this particular interface visible without pretending that the rest of the operating system does not exist.</p><h2>Main concepts and characters</h2><p>Before the actual journey starts, we need a small vocabulary. The important point is that not everything in the diagram belongs to the same category. Some things are regions, some are long-lived objects, some are transient packet objects, and some are mechanisms that connect them.</p><h3>Regions</h3><p><strong>Hardware</strong> is where the physical NIC, PHY, firmware and hardware buses live. Hardware can read and write selected areas of RAM through DMA and can notify the CPU through interrupts.</p><p><strong>Kernel</strong> is the privileged part of the operating system. For our story it contains the network driver, interrupt handling, NAPI receive processing, the networking stack, sockets, routing state and kernel objects such as <code>net_device</code> and <code>sk_buff</code>.</p><p><strong>Userspace</strong> is where normal processes run. This includes applications and tools such as NetworkManager, <code>ip</code>, <code>nmcli</code> and <code>ethtool</code>.</p><h3>Actors and control interfaces</h3><p><strong>NIC</strong> is the physical network interface controller. It receives frames from the link and cooperates with the driver through queues, descriptors, DMA and interrupts.</p><p><strong>CPU</strong> executes the kernel and userspace code involved in our story.</p><p><strong>Driver</strong> is kernel code that knows how to control a specific NIC. It creates and configures much of the receive machinery that we will watch appear in the dashboard.</p><p><strong>Netlink</strong> is an important message-based interface between userspace and kernel subsystems. Networking tools can use it to request configuration changes or query state, and the kernel can also send notifications back to userspace. In the visualization, Netlink is better represented as a message channel or event log than as a permanent state object.</p><p>There is not one single Linux networking tool because there is not one single level of networking state.</p><p><code>ip</code> is the most direct tool in our story for inspecting and changing current kernel networking state. It works with objects such as links, addresses, routes and neighbors, mainly through rtnetlink. When we run <code>ip link</code> or <code>ip route</code>, we are asking what the kernel believes right now, or asking it to change that current state.</p><p><strong>NetworkManager</strong> is a long-running userspace daemon that sits one level higher. It keeps connection profiles and policy, decides which configuration should be active, and then applies that configuration to the kernel. It can manage addresses, routes, DNS, autoconnect behavior and many device settings. This means NetworkManager has its own idea of what the machine <em>should</em> look like, while the kernel contains what is actually active at this moment.</p><p><code>nmcli</code> is the command-line client for NetworkManager. It does not configure the driver directly. It talks to the NetworkManager daemon over D-Bus, and NetworkManager then uses Netlink and other kernel interfaces to apply the requested configuration.</p><p><code>ethtool</code> looks lower in the stack. It focuses mostly on NIC and driver properties such as link modes, channels, ring sizes, offloads, interrupt coalescing and hardware statistics. Modern ethtool operations use an ethtool Generic Netlink family, while some older operations still use legacy ioctls.</p><p>So these tools do not control separate networks. They give us different views and control points over the same running system. <code>ip</code> is close to current kernel network state, <code>nmcli</code> works through NetworkManager&#8217;s managed configuration and policy, and <code>ethtool</code> focuses on the device and driver layer. Their responsibilities can overlap, which is exactly why it is useful to keep all of them visible in the same story.</p><h3>Persistent kernel and memory state</h3><p><code>net_device</code> is the central kernel representation of a network interface. It is long-lived relative to individual packets and contains or references interface state such as the interface identity, flags, MTU, queue configuration and driver operations.</p><p><strong>RX queue</strong> is a logical receive path associated with the NIC and driver. For this visualization, each RX queue will own or reference the receive resources used to process incoming traffic.</p><p><strong>RX descriptor ring</strong> is a circular array of descriptors shared conceptually between the driver and the NIC. A descriptor does not store the complete Ethernet frame itself. Instead it describes a receive buffer and carries metadata and ownership or completion information that lets the NIC and driver coordinate packet reception.</p><p><strong>Receive buffers</strong> are areas of RAM prepared for incoming packet data. RX descriptors point to, or otherwise identify, these buffers so that the NIC can DMA frame data into them.</p><p><strong>Routing and forwarding state</strong> is separate kernel networking state. It is not a field inside <code>net_device</code>. Linux organizes routes in routing tables and uses this information through its <strong>FIB, Forwarding Information Base</strong>, when making forwarding decisions. Routes describe how destinations should be reached and may reference a network interface, next hop, scope and other routing information. In the dashboard we will show the routes relevant to our tracked interface so commands such as <code>ip route</code> have visible kernel state to inspect.</p><h3>Transient packet state</h3><p><code>sk_buff</code> is Linux&#8217;s central packet representation while network data moves through much of the kernel networking stack. It contains metadata and references to packet data. It should be treated very differently from <code>net_device</code>: <code>net_device</code> belongs to the machine, while <code>sk_buff</code> belongs to a particular packet processing episode.</p><h3>Mechanisms and events</h3><p><strong>DMA, Direct Memory Access</strong>, allows the NIC to access DMA-mapped memory without the CPU copying each byte itself. During receive processing, the NIC can write the incoming frame into a prepared receive buffer in RAM.</p><p><strong>IRQ, Interrupt Request</strong>, is a hardware notification mechanism. For our story, the NIC can signal that receive work is available. The CPU then runs the interrupt handling path registered by the driver. With NAPI, the interrupt handler typically does not perform the whole receive path itself; it arranges for receive polling to continue in the appropriate kernel context.</p><h2>Before anything moves: State 0</h2><p>This is the deliberately empty state from which the story begins. The physical NIC exists in the machine, but Linux has not yet created the kernel representation and receive resources that we want to watch appear.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4kJa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe6776c3-f25b-4973-a78b-566e9552dea8_1400x900.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4kJa!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe6776c3-f25b-4973-a78b-566e9552dea8_1400x900.svg 424w, https://substackcdn.com/image/fetch/$s_!4kJa!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe6776c3-f25b-4973-a78b-566e9552dea8_1400x900.svg 848w, https://substackcdn.com/image/fetch/$s_!4kJa!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe6776c3-f25b-4973-a78b-566e9552dea8_1400x900.svg 1272w, https://substackcdn.com/image/fetch/$s_!4kJa!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe6776c3-f25b-4973-a78b-566e9552dea8_1400x900.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!4kJa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe6776c3-f25b-4973-a78b-566e9552dea8_1400x900.svg" width="1456" height="936" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/be6776c3-f25b-4973-a78b-566e9552dea8_1400x900.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:936,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:3036,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/218666073?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe6776c3-f25b-4973-a78b-566e9552dea8_1400x900.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!4kJa!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe6776c3-f25b-4973-a78b-566e9552dea8_1400x900.svg 424w, https://substackcdn.com/image/fetch/$s_!4kJa!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe6776c3-f25b-4973-a78b-566e9552dea8_1400x900.svg 848w, https://substackcdn.com/image/fetch/$s_!4kJa!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe6776c3-f25b-4973-a78b-566e9552dea8_1400x900.svg 1272w, https://substackcdn.com/image/fetch/$s_!4kJa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe6776c3-f25b-4973-a78b-566e9552dea8_1400x900.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>State 0. Initial dashboard. The physical NIC exists, while the tracked </em><code>net_device</code><em>, RX queue, receive resources, routing entries and </em><code>sk_buff</code><em> are deliberately absent. The Terminal and Netlink panels are idle.</em></p><p>From this point on, the dashboard itself is the state description. Empty panels remain visible as <strong>NOT CREATED</strong>, <strong>NONE</strong> or <strong>NO ENTRIES</strong>, because seeing an object appear is part of the explanation. When a field changes, we will change it there instead of repeating the same information in a table below the image.</p><p>Now we can finally change something. The first transition happens when Linux discovers the NIC and the driver introduces it to the networking subsystem.</p><h2>State 1: the NIC becomes a Linux network interface</h2><p>The next transition starts when the system boots or the NIC is hot-plugged. Linux discovers the PCI (Peripheral Component Interconnect) device, matches it with the appropriate driver, and invokes the driver&#8217;s <code>probe()</code> callback. <code>probe()</code> is the driver&#8217;s initialization function for that device. It is where the driver starts setting up the hardware and creating the kernel-side structures needed to use it.</p><p>Inside that initialization path, the driver prepares access to the hardware, including mapping the device registers it needs to communicate with the NIC. It also creates its own internal state. The important moment for us comes when the driver creates and registers a <code>net_device</code>.</p><p>This is the point where our NIC stops being merely a piece of detected hardware and becomes a network interface that the Linux networking subsystem can work with.</p><p>When we say that the driver maps device registers, we are talking about the hardware control registers that the driver needs to access. On a typical PCI NIC this is commonly done through MMIO, memory-mapped I/O. MMIO lets device registers be accessed through addresses handled by the kernel&#8217;s device I/O APIs. <a href="https://www.kernel.org/doc/html/latest/driver-api/device-io.html">Linux device I/O documentation</a></p><h3>State 1 dashboard</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Zv0p!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff648f635-d93d-465a-8067-72768bc696e2_1500x1120.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Zv0p!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff648f635-d93d-465a-8067-72768bc696e2_1500x1120.svg 424w, https://substackcdn.com/image/fetch/$s_!Zv0p!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff648f635-d93d-465a-8067-72768bc696e2_1500x1120.svg 848w, https://substackcdn.com/image/fetch/$s_!Zv0p!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff648f635-d93d-465a-8067-72768bc696e2_1500x1120.svg 1272w, https://substackcdn.com/image/fetch/$s_!Zv0p!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff648f635-d93d-465a-8067-72768bc696e2_1500x1120.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!Zv0p!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff648f635-d93d-465a-8067-72768bc696e2_1500x1120.svg" width="1456" height="1087" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f648f635-d93d-465a-8067-72768bc696e2_1500x1120.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1087,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:4855,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/218666073?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff648f635-d93d-465a-8067-72768bc696e2_1500x1120.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Zv0p!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff648f635-d93d-465a-8067-72768bc696e2_1500x1120.svg 424w, https://substackcdn.com/image/fetch/$s_!Zv0p!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff648f635-d93d-465a-8067-72768bc696e2_1500x1120.svg 848w, https://substackcdn.com/image/fetch/$s_!Zv0p!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff648f635-d93d-465a-8067-72768bc696e2_1500x1120.svg 1272w, https://substackcdn.com/image/fetch/$s_!Zv0p!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff648f635-d93d-465a-8067-72768bc696e2_1500x1120.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p><em>State 1. The dashboard now carries the observable evidence: PCI and driver visibility, kernel log output, the registered </em><code>net_device</code><em>, </em><code>ip link</code><em> output, sysfs visibility, the rtnetlink request and reply, and the still-empty RX, routing and packet state.</em></p><p>The important part is <strong>why</strong> this visual change matters. Registering <code>net_device</code> creates the kernel object that the rest of Linux networking can now refer to. Before this moment we had discovered hardware and a bound driver; after it we have a network interface as far as the networking subsystem is concerned.</p><p>That gives us the next natural question: what happens when userspace notices the new interface? NetworkManager can now discover the interface and build its own higher-level view of the same device, which gives us the first chance to compare current kernel state with managed userspace configuration.</p><h2>State 2: NetworkManager discovers the interface</h2><p>The kernel now has a real network interface called <code>enp3s0</code>, which means userspace services that monitor Linux networking can learn about it too. NetworkManager maintains its own higher-level model above the raw kernel state, so when it discovers the new interface it first decides whether the device should be managed and then looks for connection profiles that can be used with it.</p><p>For our story, we will assume that NetworkManager finds a saved Ethernet profile and that the profile is eligible for <strong>autoconnect</strong>. Autoconnect does not mean that the interface is already connected. It means that NetworkManager is allowed to activate that profile automatically when a suitable device becomes available. <a href="https://networkmanager.dev/docs/api/latest/settings-connection.html">NetworkManager autoconnect documentation</a></p><p>We will freeze the system for one conceptual frame before that activation happens. The kernel-side interface is therefore almost exactly where we left it in State 1. What has changed is the userspace management state: NetworkManager now knows about <code>enp3s0</code>, considers it managed, and has a profile it could apply.</p><h3>State 2 dashboard</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0Q02!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4fe552c-89c4-4af1-bc39-12837b44872d_1400x1000.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0Q02!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4fe552c-89c4-4af1-bc39-12837b44872d_1400x1000.svg 424w, https://substackcdn.com/image/fetch/$s_!0Q02!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4fe552c-89c4-4af1-bc39-12837b44872d_1400x1000.svg 848w, https://substackcdn.com/image/fetch/$s_!0Q02!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4fe552c-89c4-4af1-bc39-12837b44872d_1400x1000.svg 1272w, https://substackcdn.com/image/fetch/$s_!0Q02!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4fe552c-89c4-4af1-bc39-12837b44872d_1400x1000.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!0Q02!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4fe552c-89c4-4af1-bc39-12837b44872d_1400x1000.svg" width="1456" height="1040" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d4fe552c-89c4-4af1-bc39-12837b44872d_1400x1000.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1040,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:5419,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/218666073?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4fe552c-89c4-4af1-bc39-12837b44872d_1400x1000.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0Q02!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4fe552c-89c4-4af1-bc39-12837b44872d_1400x1000.svg 424w, https://substackcdn.com/image/fetch/$s_!0Q02!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4fe552c-89c4-4af1-bc39-12837b44872d_1400x1000.svg 848w, https://substackcdn.com/image/fetch/$s_!0Q02!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4fe552c-89c4-4af1-bc39-12837b44872d_1400x1000.svg 1272w, https://substackcdn.com/image/fetch/$s_!0Q02!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4fe552c-89c4-4af1-bc39-12837b44872d_1400x1000.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>State 2. The kernel interface is still down and the RX, routing and packet state remain unchanged, but NetworkManager now has its own managed view of </em><code>enp3s0</code><em>. The terminal compares the kernel view from </em><code>ip</code><em> with the higher-level device and profile view from </em><code>nmcli</code><em>, while the control panel shows that </em><code>nmcli</code><em> talks to NetworkManager over D-Bus rather than directly to the kernel.</em></p><p>This is the first point where two related views of the same interface exist at the same time. The kernel owns the networking state that is active <strong>now</strong>, while NetworkManager owns a higher-level description of how that state should be managed. <code>ip</code> therefore answers questions about the current kernel objects, whereas <code>nmcli</code> asks NetworkManager about its device model and connection profiles.</p><p>Nothing in the receive data path has changed yet. Merely discovering an interface does not create an IP address, install a route, produce an <code>sk_buff</code>, or activate the RX path in our model. The next transition is the moment when NetworkManager actually activates the profile and asks the kernel to bring <code>enp3s0</code> administratively UP.</p><h2>State 3: the interface is brought administratively UP</h2><p>NetworkManager does not manipulate the driver directly. It first decides what the active configuration should be, then asks the kernel to change the link state through rtnetlink. One of the first link-level changes is to mark <code>enp3s0</code> as <strong>administratively UP</strong>.</p><p>Administratively UP means that software has enabled the interface and the kernel is allowed to operate it. It does <strong>not</strong> by itself mean that an Ethernet carrier is present, that an IP address has been assigned, or that any route exists.</p><p>When the networking subsystem opens the device, it invokes the driver&#8217;s <code>ndo_open()</code> callback. This is the driver entry point for putting the device into an operational state. Real drivers often allocate or activate RX rings, receive buffers, interrupts, NAPI, and other resources somewhere in this path. For the visualization, we separate those changes into the next state so that this frame contains only the control-plane transition from <strong>DOWN</strong> to <strong>UP</strong>. The exact internal ordering is driver-dependent. <a href="https://docs.kernel.org/networking/netdevices.html">Linux networking device documentation</a> <a href="https://man7.org/linux/man-pages/man7/rtnetlink.7.html">rtnetlink documentation</a></p><h3>State 3 dashboard</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0ONT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F761eb151-7225-4667-b9ea-c95c7c2abbd2_1400x1000.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0ONT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F761eb151-7225-4667-b9ea-c95c7c2abbd2_1400x1000.svg 424w, https://substackcdn.com/image/fetch/$s_!0ONT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F761eb151-7225-4667-b9ea-c95c7c2abbd2_1400x1000.svg 848w, https://substackcdn.com/image/fetch/$s_!0ONT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F761eb151-7225-4667-b9ea-c95c7c2abbd2_1400x1000.svg 1272w, https://substackcdn.com/image/fetch/$s_!0ONT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F761eb151-7225-4667-b9ea-c95c7c2abbd2_1400x1000.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!0ONT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F761eb151-7225-4667-b9ea-c95c7c2abbd2_1400x1000.svg" width="1456" height="1040" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/761eb151-7225-4667-b9ea-c95c7c2abbd2_1400x1000.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1040,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:5044,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/218666073?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F761eb151-7225-4667-b9ea-c95c7c2abbd2_1400x1000.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0ONT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F761eb151-7225-4667-b9ea-c95c7c2abbd2_1400x1000.svg 424w, https://substackcdn.com/image/fetch/$s_!0ONT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F761eb151-7225-4667-b9ea-c95c7c2abbd2_1400x1000.svg 848w, https://substackcdn.com/image/fetch/$s_!0ONT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F761eb151-7225-4667-b9ea-c95c7c2abbd2_1400x1000.svg 1272w, https://substackcdn.com/image/fetch/$s_!0ONT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F761eb151-7225-4667-b9ea-c95c7c2abbd2_1400x1000.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>State 3 dashboard. NetworkManager has started profile activation, the kernel interface is now administratively UP, and the driver&#8217;s </em><code>ndo_open()</code><em> path has been entered. RX resources are intentionally postponed to the next frame, while routing and packet state remain empty.</em></p><p>The important distinction here is that <strong>UP is permission, not proof of connectivity</strong>. Linux has now allowed the interface to operate, but the driver still has to prepare the machinery that will actually let the NIC receive frames.</p><p>That is the next transition: building the RX queue, descriptor ring, receive buffers, DMA mappings, interrupt path, and NAPI state that connect the physical NIC to packet processing in the kernel.</p><h2>Link transition: the Ethernet cable is plugged in</h2><p><code>enp3s0</code> is already administratively UP because software enabled it in State 3. That does not mean a usable Ethernet link exists yet. Now we connect the cable. The PHYs at both ends can detect each other and establish the physical link, commonly using autonegotiation to agree on parameters such as speed and duplex where applicable.</p><p>Once the link is established, the NIC reports carrier to the driver and Linux can update the interface&#8217;s lower-layer and operational state. The administrative state does <strong>not</strong> change. In our simplified story the transition is therefore <code>admin: UP &#8594; UP</code>, <code>carrier: DOWN &#8594; UP</code>, and <code>operstate: DOWN &#8594; UP</code>. The <code>ip link</code> output makes this distinction visible in one place: <code>UP</code> inside the angle-bracket flags means the administrative <code>IFF_UP</code> flag is set, <code>LOWER_UP</code> means the lower layer reports carrier, while <code>state UP</code> is the interface&#8217;s operational state. <a href="https://docs.kernel.org/networking/operstates.html">Linux operational state documentation</a></p><h3>Cable-connected dashboard</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_jum!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f100e35-b05b-4093-bf2a-ed259136ce78_1400x940.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_jum!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f100e35-b05b-4093-bf2a-ed259136ce78_1400x940.svg 424w, https://substackcdn.com/image/fetch/$s_!_jum!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f100e35-b05b-4093-bf2a-ed259136ce78_1400x940.svg 848w, https://substackcdn.com/image/fetch/$s_!_jum!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f100e35-b05b-4093-bf2a-ed259136ce78_1400x940.svg 1272w, https://substackcdn.com/image/fetch/$s_!_jum!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f100e35-b05b-4093-bf2a-ed259136ce78_1400x940.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!_jum!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f100e35-b05b-4093-bf2a-ed259136ce78_1400x940.svg" width="1456" height="978" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2f100e35-b05b-4093-bf2a-ed259136ce78_1400x940.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:978,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:4209,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/218666073?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f100e35-b05b-4093-bf2a-ed259136ce78_1400x940.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!_jum!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f100e35-b05b-4093-bf2a-ed259136ce78_1400x940.svg 424w, https://substackcdn.com/image/fetch/$s_!_jum!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f100e35-b05b-4093-bf2a-ed259136ce78_1400x940.svg 848w, https://substackcdn.com/image/fetch/$s_!_jum!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f100e35-b05b-4093-bf2a-ed259136ce78_1400x940.svg 1272w, https://substackcdn.com/image/fetch/$s_!_jum!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f100e35-b05b-4093-bf2a-ed259136ce78_1400x940.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Link transition dashboard. The cable is now connected, carrier appears, and Linux can report the interface as operationally UP, while the administrative state remains UP.</em></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!axd3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbf1602d-870c-4300-bb5f-6de0bd6bdd56_1400x520.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!axd3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbf1602d-870c-4300-bb5f-6de0bd6bdd56_1400x520.svg 424w, https://substackcdn.com/image/fetch/$s_!axd3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbf1602d-870c-4300-bb5f-6de0bd6bdd56_1400x520.svg 848w, https://substackcdn.com/image/fetch/$s_!axd3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbf1602d-870c-4300-bb5f-6de0bd6bdd56_1400x520.svg 1272w, https://substackcdn.com/image/fetch/$s_!axd3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbf1602d-870c-4300-bb5f-6de0bd6bdd56_1400x520.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!axd3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbf1602d-870c-4300-bb5f-6de0bd6bdd56_1400x520.svg" width="1456" height="541" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cbf1602d-870c-4300-bb5f-6de0bd6bdd56_1400x520.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:541,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2121,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/218666073?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbf1602d-870c-4300-bb5f-6de0bd6bdd56_1400x520.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!axd3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbf1602d-870c-4300-bb5f-6de0bd6bdd56_1400x520.svg 424w, https://substackcdn.com/image/fetch/$s_!axd3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbf1602d-870c-4300-bb5f-6de0bd6bdd56_1400x520.svg 848w, https://substackcdn.com/image/fetch/$s_!axd3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbf1602d-870c-4300-bb5f-6de0bd6bdd56_1400x520.svg 1272w, https://substackcdn.com/image/fetch/$s_!axd3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbf1602d-870c-4300-bb5f-6de0bd6bdd56_1400x520.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>The </em><code>ip link</code><em> command makes the distinction visible in one place: </em><code>UP</code><em> inside the flags means the administrative </em><code>IFF_UP</code><em> flag is set, </em><code>LOWER_UP</code><em> reports lower-layer carrier, and </em><code>state UP</code><em> is the operational state.</em></p><p>This distinction is easy to miss but important: <strong>administrative UP</strong> means that software has enabled the interface, while <strong>operationally UP</strong> means that the lower-layer conditions needed for the interface to operate are available. With the physical link established, we can now return to the driver and expose the RX machinery that will actually move received frame data into RAM.</p><h2>State 4: the driver builds the RX machinery</h2><p>The interface is already administratively UP, but that alone is not enough to receive a frame. The driver still needs a concrete path between the NIC and RAM, which means preparing the RX queue, descriptor ring, receive buffers and DMA mappings, then wiring that path into interrupt handling and NAPI.</p><p>The important relationship is simple: the descriptor ring does not contain the Ethernet frames themselves. Its descriptors identify receive buffers that the NIC is allowed to use. Once those buffers are DMA-mapped and their addresses are programmed into the NIC, the hardware can place incoming frame bytes directly into RAM without the CPU copying each byte itself. The driver also prepares the notification path, typically using interrupts together with NAPI, so completed receive work can later be processed by the kernel. <a href="https://docs.kernel.org/core-api/dma-api-howto.html">Linux DMA API documentation</a> <a href="https://docs.kernel.org/networking/napi.html">Linux NAPI documentation</a></p><p>The exact order is driver-specific. Some drivers allocate parts of this machinery during <code>probe()</code>, while others do more of it when the interface is opened through <code>ndo_open()</code>. Our dashboard shows the conceptual end state: the receive machinery exists and is ready before the first frame arrives.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!myQX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4f118ce-55a5-4fa0-b029-fba0df055815_1400x1080.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!myQX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4f118ce-55a5-4fa0-b029-fba0df055815_1400x1080.svg 424w, https://substackcdn.com/image/fetch/$s_!myQX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4f118ce-55a5-4fa0-b029-fba0df055815_1400x1080.svg 848w, https://substackcdn.com/image/fetch/$s_!myQX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4f118ce-55a5-4fa0-b029-fba0df055815_1400x1080.svg 1272w, https://substackcdn.com/image/fetch/$s_!myQX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4f118ce-55a5-4fa0-b029-fba0df055815_1400x1080.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!myQX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4f118ce-55a5-4fa0-b029-fba0df055815_1400x1080.svg" width="1456" height="1123" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d4f118ce-55a5-4fa0-b029-fba0df055815_1400x1080.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1123,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:6520,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/218666073?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4f118ce-55a5-4fa0-b029-fba0df055815_1400x1080.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!myQX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4f118ce-55a5-4fa0-b029-fba0df055815_1400x1080.svg 424w, https://substackcdn.com/image/fetch/$s_!myQX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4f118ce-55a5-4fa0-b029-fba0df055815_1400x1080.svg 848w, https://substackcdn.com/image/fetch/$s_!myQX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4f118ce-55a5-4fa0-b029-fba0df055815_1400x1080.svg 1272w, https://substackcdn.com/image/fetch/$s_!myQX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4f118ce-55a5-4fa0-b029-fba0df055815_1400x1080.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>State 4 dashboard. The RX queue, descriptor ring, receive buffers, DMA mappings, interrupt path and NAPI state now exist. The NIC is ready to place incoming frame data into RAM, but no packet has arrived yet, so there is still no </em><code>sk_buff</code><em>.</em></p><p>At this point the machine has everything it needs at the device level to receive Ethernet traffic, but it still has no IPv4 identity in our story. The next transition adds that Layer 3 state.</p><h2>State 5: the interface gets IPv4 configuration</h2><p>To keep this part focused on the Linux networking stack rather than turning it into a DHCP walkthrough, we will use a static IPv4 profile. Our example address is <code>192.0.2.10/24</code> with <code>192.0.2.1</code> as the default gateway. The <code>192.0.2.0/24</code> network is reserved for documentation examples, which makes it safe to use here. <a href="https://datatracker.ietf.org/doc/html/rfc5737">RFC 5737</a></p><p>NetworkManager now applies the Layer 3 configuration from the active profile to the kernel. The address itself is not simply another field inside <code>net_device</code>; Linux keeps IP address state separately and associates it with the interface. Through rtnetlink, NetworkManager can add the address with an <code>RTM_NEWADDR</code> request and install routing state with <code>RTM_NEWROUTE</code> requests. <a href="https://man7.org/linux/man-pages/man7/rtnetlink.7.html">rtnetlink documentation</a></p><p>In our simplified configuration, adding <code>192.0.2.10/24</code> gives the machine a connected route for <code>192.0.2.0/24</code> and a local route for its own address, while the gateway configured in the profile provides the default route through <code>192.0.2.1</code>. These routes are not only configuration that we can inspect with <code>ip route</code>. They become input to the kernel's forwarding decisions when packets later enter IPv4 processing.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!I3-n!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8678e1b-61e2-4514-a021-0d283140dbab_1400x1080.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!I3-n!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8678e1b-61e2-4514-a021-0d283140dbab_1400x1080.svg 424w, https://substackcdn.com/image/fetch/$s_!I3-n!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8678e1b-61e2-4514-a021-0d283140dbab_1400x1080.svg 848w, https://substackcdn.com/image/fetch/$s_!I3-n!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8678e1b-61e2-4514-a021-0d283140dbab_1400x1080.svg 1272w, https://substackcdn.com/image/fetch/$s_!I3-n!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8678e1b-61e2-4514-a021-0d283140dbab_1400x1080.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!I3-n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8678e1b-61e2-4514-a021-0d283140dbab_1400x1080.svg" width="1456" height="1123" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a8678e1b-61e2-4514-a021-0d283140dbab_1400x1080.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1123,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:6403,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/218666073?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8678e1b-61e2-4514-a021-0d283140dbab_1400x1080.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!I3-n!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8678e1b-61e2-4514-a021-0d283140dbab_1400x1080.svg 424w, https://substackcdn.com/image/fetch/$s_!I3-n!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8678e1b-61e2-4514-a021-0d283140dbab_1400x1080.svg 848w, https://substackcdn.com/image/fetch/$s_!I3-n!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8678e1b-61e2-4514-a021-0d283140dbab_1400x1080.svg 1272w, https://substackcdn.com/image/fetch/$s_!I3-n!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa8678e1b-61e2-4514-a021-0d283140dbab_1400x1080.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>State 5 dashboard. The RX machinery remains ready, while NetworkManager has now applied static IPv4 configuration. The kernel contains </em><code>192.0.2.10/24</code><em>, the connected and local routing state, and a default route through </em><code>192.0.2.1</code><em>. There is still no </em><code>sk_buff</code><em> because no frame is being processed yet.</em></p><p>We have now finished the setup part of the story. The hardware exists, Linux has a <code>net_device</code>, NetworkManager has activated its profile, the receive machinery is ready, carrier is available, and Layer 3 configuration exists. The next state can finally start with the event we have been preparing for all along: an Ethernet frame arrives at the NIC.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Software in the Grid is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2>State 6: an Ethernet frame arrives</h2><p>Until now the receive machinery has been prepared but idle. We now let one Ethernet frame reach the NIC. The NIC selects an available RX descriptor, which in our simplified ring is <code>D0</code>, follows the DMA address associated with <code>B0</code>, and writes the frame bytes directly into that receive buffer in RAM.</p><p>Once the transfer is complete, the NIC marks the receive work as completed and signals the CPU through the configured interrupt path.</p><p>At this moment the driver has usually done two important things: it has acknowledged the receive event and it has suppressed further RX interrupts for that queue, handing control over to NAPI polling until the receive work is drained so that the completed RX entry can be processed outside the hard interrupt path. <a href="https://docs.kernel.org/networking/napi.html">Linux NAPI documentation</a></p><p>There is an important boundary here: the Ethernet frame already exists in RAM, but Linux has not yet created an <code>sk_buff</code> for it. At this instant we still have hardware-facing receive state: one completed descriptor and one filled receive buffer. The higher-level packet object will appear only when the driver and NAPI process that completion in the next state.</p><p>Our ring remains deliberately simplified. Real NICs use different descriptor formats, ownership conventions and completion mechanisms, and some hardware separates submission and completion rings. The dashboard combines those details into one conceptual ring so that we can follow the lifecycle of one buffer without tying the explanation to a particular NIC.</p><h3>State 6 dashboard</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!vgpM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F053e75cb-f754-4a44-9fa4-16898ce26a03_1400x1080.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!vgpM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F053e75cb-f754-4a44-9fa4-16898ce26a03_1400x1080.svg 424w, https://substackcdn.com/image/fetch/$s_!vgpM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F053e75cb-f754-4a44-9fa4-16898ce26a03_1400x1080.svg 848w, https://substackcdn.com/image/fetch/$s_!vgpM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F053e75cb-f754-4a44-9fa4-16898ce26a03_1400x1080.svg 1272w, https://substackcdn.com/image/fetch/$s_!vgpM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F053e75cb-f754-4a44-9fa4-16898ce26a03_1400x1080.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!vgpM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F053e75cb-f754-4a44-9fa4-16898ce26a03_1400x1080.svg" width="1456" height="1123" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/053e75cb-f754-4a44-9fa4-16898ce26a03_1400x1080.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1123,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:7214,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/218666073?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F053e75cb-f754-4a44-9fa4-16898ce26a03_1400x1080.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!vgpM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F053e75cb-f754-4a44-9fa4-16898ce26a03_1400x1080.svg 424w, https://substackcdn.com/image/fetch/$s_!vgpM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F053e75cb-f754-4a44-9fa4-16898ce26a03_1400x1080.svg 848w, https://substackcdn.com/image/fetch/$s_!vgpM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F053e75cb-f754-4a44-9fa4-16898ce26a03_1400x1080.svg 1272w, https://substackcdn.com/image/fetch/$s_!vgpM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F053e75cb-f754-4a44-9fa4-16898ce26a03_1400x1080.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>State 6 dashboard. The NIC has used </em><code>D0</code><em> and DMA-written the incoming Ethernet frame into </em><code>B0</code><em>. </em><code>D0</code><em> is now complete, </em><code>B0</code><em> contains the frame bytes, the interrupt path has fired and NAPI is scheduled. </em><code>D1</code><em>&#8211;</em><code>D3</code><em> remain available, and </em><code>sk_buff</code><em> is still absent because the driver has not consumed the completion yet.</em></p><p>This is the first moment in the story where actual packet bytes exist inside the machine. The next transition moves ownership back toward the CPU: NAPI polls the RX queue, the driver consumes <code>D0</code>, and Linux creates or builds the <code>sk_buff</code> that will carry the packet into the networking stack.</p><h2>State 7: NAPI turns the completed receive into an <code>sk_buff</code></h2><p>In State 6 the interrupt handler scheduled NAPI, but that handoff has another important effect. Once NAPI owns the receive work, the driver should keep further interrupts for that NAPI instance masked until polling is finished, because another interrupt would only report work that the poller is already responsible for. Some devices mask the interrupt automatically, while other drivers do it explicitly before scheduling NAPI. The kernel documentation describes this as the normal NAPI scheduling pattern. <a href="https://docs.kernel.org/networking/napi.html">Linux NAPI documentation</a></p><p>The driver&#8217;s NAPI <code>poll()</code> function now examines the receive ring and finds <code>D0</code> complete. It obtains the packet data from the associated receive buffer, reads the metadata supplied by the NIC, and creates or prepares an <code>sk_buff</code> for the packet. The important point is that an <code>sk_buff</code> is primarily a metadata object. The packet bytes live in associated memory that the skb references, although individual drivers may instead copy some or all of the data into newly allocated skb storage. <a href="https://docs.kernel.org/networking/skbuff.html">Linux </a><code>sk_buff</code><a href="https://docs.kernel.org/networking/skbuff.html"> documentation</a></p><p>For our visualization we will follow one simple path: the packet data originating in <code>B0</code> becomes the data referenced by the new skb, while the driver refills <code>D0</code> with a fresh empty buffer, <code>B4</code>, so the RX ring can receive another frame. Real drivers may recycle the same page, copy small packets, use page pools, or manage completions differently, but the conceptual transition is the same: the completed receive resource is consumed, an skb is created, and the ring is replenished.</p><p>When the receive work has been drained, the driver can complete the NAPI cycle and allow RX interrupts again. We freeze the story immediately after the skb exists and the ring is ready again. In a real driver, the handoff into the generic receive path commonly happens inside the same NAPI poll callback, but keeping it for the next frame lets us see the boundary between the NIC/driver world and the generic Linux networking stack.</p><h3>State 7 dashboard</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!J36d!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9d3a8ff-a1e4-4e38-9e53-9df4c9fc57e6_1400x1120.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!J36d!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9d3a8ff-a1e4-4e38-9e53-9df4c9fc57e6_1400x1120.svg 424w, https://substackcdn.com/image/fetch/$s_!J36d!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9d3a8ff-a1e4-4e38-9e53-9df4c9fc57e6_1400x1120.svg 848w, https://substackcdn.com/image/fetch/$s_!J36d!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9d3a8ff-a1e4-4e38-9e53-9df4c9fc57e6_1400x1120.svg 1272w, https://substackcdn.com/image/fetch/$s_!J36d!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9d3a8ff-a1e4-4e38-9e53-9df4c9fc57e6_1400x1120.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!J36d!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9d3a8ff-a1e4-4e38-9e53-9df4c9fc57e6_1400x1120.svg" width="1456" height="1165" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b9d3a8ff-a1e4-4e38-9e53-9df4c9fc57e6_1400x1120.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1165,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:7978,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/218666073?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9d3a8ff-a1e4-4e38-9e53-9df4c9fc57e6_1400x1120.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!J36d!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9d3a8ff-a1e4-4e38-9e53-9df4c9fc57e6_1400x1120.svg 424w, https://substackcdn.com/image/fetch/$s_!J36d!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9d3a8ff-a1e4-4e38-9e53-9df4c9fc57e6_1400x1120.svg 848w, https://substackcdn.com/image/fetch/$s_!J36d!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9d3a8ff-a1e4-4e38-9e53-9df4c9fc57e6_1400x1120.svg 1272w, https://substackcdn.com/image/fetch/$s_!J36d!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb9d3a8ff-a1e4-4e38-9e53-9df4c9fc57e6_1400x1120.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>State 7 dashboard. NAPI consumes the completed </em><code>D0</code><em> entry while RX interrupts are suppressed, the driver builds an </em><code>sk_buff</code><em> for the received packet, and the ring is replenished with a fresh empty buffer. Once the queue is drained, NAPI can complete and the RX interrupt can be enabled again.</em></p><p>At this point the packet has crossed an important boundary. The RX ring is back in a reusable state, while Linux now has an <code>sk_buff</code> that can move independently through the networking stack. The next state follows that skb into the generic receive path, where Ethernet and IPv4 processing begin.</p><h2>State 8: the packet enters the generic Linux networking stack</h2><p>We now resume the packet at the conceptual handoff point we deliberately separated from State 7. In real driver code this handoff normally happens inside the NAPI poll function, before that polling cycle completes, but treating it as a separate frame lets us see the moment when the packet stops being primarily a driver concern and becomes a generic Linux networking object.</p><p>Before Linux can choose a Layer 3 handler, the Ethernet information has to tell it what kind of payload the frame contains. Drivers commonly use <code>eth_type_trans(skb, dev)</code> while preparing the skb for the receive path. Conceptually, this moves the skb past the Ethernet header and records the resulting protocol in <code>skb-&gt;protocol</code>. For our packet, the Ethernet EtherType identifies IPv4, so the skb is marked as <code>ETH_P_IP</code>. The driver then hands it into the generic receive machinery, commonly through <code>napi_gro_receive()</code>. GRO can combine compatible packets as an optimization, but with the single packet in our story we can treat it as passing through unchanged. <a href="https://docs.kernel.org/networking/skbuff.html">Linux </a><code>sk_buff</code><a href="https://docs.kernel.org/networking/skbuff.html"> documentation</a></p><p>The generic receive path can now dispatch the packet to IPv4 processing. The IPv4 handler validates and interprets the IP header, including the destination address, and the routing subsystem performs a route lookup. Conceptually, this is where Linux consults its <strong>FIB, Forwarding Information Base</strong>, using the routing state we created earlier to determine what should happen next.</p><p>This lookup is one of the major branching points in the networking stack. If the destination belongs to this machine, processing continues toward local delivery. If the destination should be reached through another interface and forwarding is enabled, the packet can enter the forwarding path. If Linux cannot produce a usable route, processing can terminate instead.</p><p>Our packet is addressed to <code>192.0.2.10</code>, which belongs to this host, so the lookup selects <strong>local delivery</strong>. We therefore continue toward TCP rather than following the forwarding path.</p><h3>State 8 dashboard</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rLJV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ac923dd-b068-4be7-b591-026a865d493d_1400x1120.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rLJV!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ac923dd-b068-4be7-b591-026a865d493d_1400x1120.svg 424w, https://substackcdn.com/image/fetch/$s_!rLJV!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ac923dd-b068-4be7-b591-026a865d493d_1400x1120.svg 848w, https://substackcdn.com/image/fetch/$s_!rLJV!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ac923dd-b068-4be7-b591-026a865d493d_1400x1120.svg 1272w, https://substackcdn.com/image/fetch/$s_!rLJV!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ac923dd-b068-4be7-b591-026a865d493d_1400x1120.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!rLJV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ac923dd-b068-4be7-b591-026a865d493d_1400x1120.svg" width="1456" height="1165" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0ac923dd-b068-4be7-b591-026a865d493d_1400x1120.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1165,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:7826,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/218666073?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ac923dd-b068-4be7-b591-026a865d493d_1400x1120.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!rLJV!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ac923dd-b068-4be7-b591-026a865d493d_1400x1120.svg 424w, https://substackcdn.com/image/fetch/$s_!rLJV!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ac923dd-b068-4be7-b591-026a865d493d_1400x1120.svg 848w, https://substackcdn.com/image/fetch/$s_!rLJV!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ac923dd-b068-4be7-b591-026a865d493d_1400x1120.svg 1272w, https://substackcdn.com/image/fetch/$s_!rLJV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ac923dd-b068-4be7-b591-026a865d493d_1400x1120.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>State 8 dashboard. The RX ring is reusable again while the </em><code>sk_buff</code><em> moves through the generic receive path. Ethernet processing identifies IPv4, IPv4 processing reads destination </em><code>192.0.2.10</code><em>, and the routing subsystem selects LOCAL DELIVERY. The packet has not yet been dispatched to a transport protocol or socket.</em></p><p>The important change is that the packet now belongs to the generic networking stack rather than to the NIC receive machinery. From this point onward, the RX ring can receive completely different frames while this skb continues independently toward the application. The next transition is local IPv4 delivery, where Linux reads the IP protocol field, enters the appropriate transport implementation, and begins looking for the destination socket.</p><h2>State 9: TCP finds the established socket</h2><p>State 8 ended when IPv4 routing decided that the packet belongs to this machine. Local IPv4 delivery can now inspect the IP <code>Protocol</code> field to decide which transport implementation should receive the packet. For our packet the value is <code>6</code>, which means TCP, so Linux passes the <code>sk_buff</code> into the TCP receive path, conceptually through a handler such as <code>tcp_v4_rcv()</code>.</p><p>To keep this journey focused on the receive path rather than turning it into an explanation of the TCP handshake, we will assume that a connection already exists. Our local application has an established TCP socket on <code>192.0.2.10:8080</code>, connected to a peer at <code>192.0.2.20:51514</code>, and the segment we are following contains in-order application data.</p><p>This is where ports finally become part of the routing of the packet inside the machine. IP routing brought the packet to the local host, but it did not decide which application should receive it. TCP now uses the connection identity, commonly described by the four values <code>source IP</code>, <code>source port</code>, <code>destination IP</code>, and <code>destination port</code>, together with TCP connection state, to find the matching established socket. <a href="https://man7.org/linux/man-pages/man7/socket.7.html">socket(7)</a></p><p>Once the socket has been found, TCP processes the segment according to the state of that connection, including its sequence and acknowledgement information, receive-window state, and checksum status as required. In our simple case the payload is the next expected in-order data, so TCP can accept it and place the received bytes into the socket&#8217;s receive state. If the application is sleeping while waiting for data, Linux can wake it.</p><p>There is another important abstraction change here. The application will not receive an Ethernet frame, an IP packet, or an <code>sk_buff</code>. TCP presents an ordered byte stream. The packet boundaries that were so important in the lower layers are no longer the interface that userspace sees. We therefore stop this state with data waiting on the established socket, just before the application calls <code>recv()</code> or <code>read()</code>.</p><h3>State 9 dashboard</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Z_5c!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F109ca0a7-523f-4854-b9dd-e84950a4453d_1400x1140.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Z_5c!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F109ca0a7-523f-4854-b9dd-e84950a4453d_1400x1140.svg 424w, https://substackcdn.com/image/fetch/$s_!Z_5c!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F109ca0a7-523f-4854-b9dd-e84950a4453d_1400x1140.svg 848w, https://substackcdn.com/image/fetch/$s_!Z_5c!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F109ca0a7-523f-4854-b9dd-e84950a4453d_1400x1140.svg 1272w, https://substackcdn.com/image/fetch/$s_!Z_5c!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F109ca0a7-523f-4854-b9dd-e84950a4453d_1400x1140.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!Z_5c!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F109ca0a7-523f-4854-b9dd-e84950a4453d_1400x1140.svg" width="1456" height="1186" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/109ca0a7-523f-4854-b9dd-e84950a4453d_1400x1140.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1186,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:7966,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/218666073?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F109ca0a7-523f-4854-b9dd-e84950a4453d_1400x1140.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Z_5c!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F109ca0a7-523f-4854-b9dd-e84950a4453d_1400x1140.svg 424w, https://substackcdn.com/image/fetch/$s_!Z_5c!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F109ca0a7-523f-4854-b9dd-e84950a4453d_1400x1140.svg 848w, https://substackcdn.com/image/fetch/$s_!Z_5c!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F109ca0a7-523f-4854-b9dd-e84950a4453d_1400x1140.svg 1272w, https://substackcdn.com/image/fetch/$s_!Z_5c!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F109ca0a7-523f-4854-b9dd-e84950a4453d_1400x1140.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p><em>State 9 dashboard. IPv4 local delivery identifies TCP, the TCP receive path matches the segment from </em><code>192.0.2.20:51514</code><em> to the established socket at </em><code>192.0.2.10:8080</code><em>, and the accepted in-order payload is queued for the application. The RX ring remains reusable and independent of this transport processing.</em></p><p>At this point the networking stack has answered the last kernel-side addressing question: not only does the packet belong to this machine, it belongs to this particular TCP connection and socket. The final transition is the boundary we have been moving toward from the beginning: the application calls <code>recv()</code>, and the queued TCP bytes cross from kernel-managed socket state into the application&#8217;s userspace buffer.</p><h2>State 10: the application receives the TCP byte stream</h2><p>State 9 ended with <code>128</code> bytes waiting in the receive state of our established TCP socket. The networking stack has already done the work needed to decide where those bytes belong, but they are still kernel-managed data. The application has not received them yet.</p><p>The final transition begins when the application calls something such as <code>recv(fd, buf, 4096, 0)</code>. That call crosses the userspace-to-kernel boundary and asks the socket layer to provide bytes that TCP has made available on this connection. For a normal copied receive path, Linux copies available stream data from the socket&#8217;s receive state into the buffer supplied by the process. <code>recv(2)</code><a href="https://man7.org/linux/man-pages/man2/recvmsg.2.html"> / </a><code>recvmsg(2)</code><a href="https://man7.org/linux/man-pages/man2/recvmsg.2.html"> documentation</a></p><p>For our simplified example, the application&#8217;s buffer is larger than the <code>128</code> bytes waiting on the socket, so one <code>recv()</code> call consumes all of them and returns <code>128</code>. The socket itself remains established. What changes is the data ownership: the receive queue drops from <code>128</code> bytes to <code>0</code>, while the process now has those <code>128</code> bytes in its own userspace memory.</p><p>A real TCP read does not have to line up with the segment that originally carried the data. <code>recv()</code> may return fewer bytes than requested, multiple TCP segments may contribute to one read, and one segment&#8217;s data may be consumed across multiple reads. That is exactly the point of TCP&#8217;s byte-stream abstraction. In our one-packet teaching path, however, we deliberately consume the entire payload at once so that the final lifecycle transition remains visible.</p><p>Once all data associated with our packet has been consumed and nothing else still references that packet storage, the corresponding <code>sk_buff</code> and backing resources can be released or recycled. The application never sees that cleanup. From its point of view, <code>recv()</code> simply returns bytes.</p><h3>State 10 dashboard</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5r9U!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0513823a-948e-4732-a391-f157ba364972_1400x1140.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5r9U!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0513823a-948e-4732-a391-f157ba364972_1400x1140.svg 424w, https://substackcdn.com/image/fetch/$s_!5r9U!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0513823a-948e-4732-a391-f157ba364972_1400x1140.svg 848w, https://substackcdn.com/image/fetch/$s_!5r9U!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0513823a-948e-4732-a391-f157ba364972_1400x1140.svg 1272w, https://substackcdn.com/image/fetch/$s_!5r9U!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0513823a-948e-4732-a391-f157ba364972_1400x1140.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!5r9U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0513823a-948e-4732-a391-f157ba364972_1400x1140.svg" width="1456" height="1186" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0513823a-948e-4732-a391-f157ba364972_1400x1140.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1186,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:8055,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/218666073?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0513823a-948e-4732-a391-f157ba364972_1400x1140.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5r9U!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0513823a-948e-4732-a391-f157ba364972_1400x1140.svg 424w, https://substackcdn.com/image/fetch/$s_!5r9U!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0513823a-948e-4732-a391-f157ba364972_1400x1140.svg 848w, https://substackcdn.com/image/fetch/$s_!5r9U!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0513823a-948e-4732-a391-f157ba364972_1400x1140.svg 1272w, https://substackcdn.com/image/fetch/$s_!5r9U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0513823a-948e-4732-a391-f157ba364972_1400x1140.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p><em>State 10 dashboard. The application calls </em><code>recv()</code><em>, the established socket&#8217;s receive queue goes from 128 bytes to 0, and those 128 bytes appear in the process&#8217;s userspace buffer. The RX ring remains ready for unrelated traffic, while the packet-side </em><code>sk_buff</code><em> can be released once its data has been fully consumed.</em></p><p>That completes the journey. The same network data began as an electrical or optical signal outside the machine, became bytes in a DMA receive buffer, passed through descriptor and NAPI processing as an <code>sk_buff</code>, moved through Ethernet, IPv4 and TCP, waited on a socket, and finally became ordinary bytes in a userspace buffer.</p><p>The most useful lesson is not the exact function sequence, because drivers, kernel versions, offloads and configuration can change many details. It is the sequence of <strong>representations, ownership changes and boundaries</strong>. The NIC does not write directly into an application&#8217;s buffer, the driver does not hand Ethernet frames directly to a process, and TCP does not expose packets to the application. Linux repeatedly transforms the same underlying data until the abstraction visible to the program is simply an ordered stream of bytes.</p><h2>And what about sending?</h2><p>The transmit path reuses many of the same actors, but it is not simply the receive path played backward. On receive, hardware introduces the data into the machine and Linux gradually turns it into something an application can consume. On transmit, the application already owns the bytes, and the kernel gradually turns them into something the hardware can put onto the link.</p><p>Suppose our application calls <code>send()</code> or <code>write()</code> on the established TCP socket. TCP accepts those bytes into the outgoing stream and prepares the transport data that must be transmitted. IPv4 processing and routing then determine the outgoing path, while the lower networking layers prepare the packet for the selected interface. Before the driver sends it to hardware, the packet will typically pass through the interface&#8217;s egress queueing machinery, where Linux can queue and schedule transmission.</p><p>The driver then prepares the hardware-facing side. It DMA-maps the packet memory as required, places references to that memory into TX descriptors, and makes the descriptors available to the NIC. This time the DMA direction is the opposite of receive: instead of the NIC writing incoming bytes into RAM, the NIC <strong>reads</strong> packet data from RAM and transmits the resulting Ethernet frame onto the link. After the hardware finishes, it reports completion so the driver can reclaim TX descriptors and release or recycle resources. Offloads can move work such as checksum calculation or segmentation into the NIC, but they do not change this basic ownership flow. <a href="https://docs.kernel.org/networking/netdevices.html">Linux network device driver documentation</a> <a href="https://docs.kernel.org/core-api/dma-api-howto.html">Linux DMA API documentation</a></p><h3>Short transmit-path view</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!PGdd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f8d4bbb-5c61-4dbb-85de-08a7a78f7971_1400x650.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!PGdd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f8d4bbb-5c61-4dbb-85de-08a7a78f7971_1400x650.svg 424w, https://substackcdn.com/image/fetch/$s_!PGdd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f8d4bbb-5c61-4dbb-85de-08a7a78f7971_1400x650.svg 848w, https://substackcdn.com/image/fetch/$s_!PGdd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f8d4bbb-5c61-4dbb-85de-08a7a78f7971_1400x650.svg 1272w, https://substackcdn.com/image/fetch/$s_!PGdd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f8d4bbb-5c61-4dbb-85de-08a7a78f7971_1400x650.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!PGdd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f8d4bbb-5c61-4dbb-85de-08a7a78f7971_1400x650.svg" width="1456" height="676" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7f8d4bbb-5c61-4dbb-85de-08a7a78f7971_1400x650.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:676,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:3704,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/218666073?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f8d4bbb-5c61-4dbb-85de-08a7a78f7971_1400x650.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!PGdd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f8d4bbb-5c61-4dbb-85de-08a7a78f7971_1400x650.svg 424w, https://substackcdn.com/image/fetch/$s_!PGdd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f8d4bbb-5c61-4dbb-85de-08a7a78f7971_1400x650.svg 848w, https://substackcdn.com/image/fetch/$s_!PGdd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f8d4bbb-5c61-4dbb-85de-08a7a78f7971_1400x650.svg 1272w, https://substackcdn.com/image/fetch/$s_!PGdd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7f8d4bbb-5c61-4dbb-85de-08a7a78f7971_1400x650.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Transmit-path overview. Application bytes move through the socket and protocol stack toward the egress interface, the driver publishes packet memory through the TX ring, and the NIC DMA-reads that memory before putting the frame onto the link.</em></p><p>We could follow every TX transition with the same level of detail as the receive path, including queueing disciplines, neighbor resolution, offloads and completion handling. For this article, that would mostly repeat machinery we now already recognize. The important addition is the direction of ownership: <strong>receive starts at the NIC and ends in userspace, while transmit starts in userspace and ends at the NIC.</strong></p><h2>Summary</h2><p>We did not cover every possible branch through the Linux networking stack. We did not follow forwarding or dropping packet by packet, and the transmit path above is intentionally only a compact overview rather than another full sequence of states.</p><p>But we did cover the main machinery that makes the stack work: the NIC and driver, administrative and operational link state, RX queues and descriptor rings, DMA, interrupts and NAPI, <code>sk_buff</code>, Ethernet and IP processing, routing, TCP, sockets, userspace delivery, and finally the shape of the path back out of the machine.</p><p>Forwarding, dropping and the detailed transmit path add their own decisions, queues and protocol-specific behavior, but they build on the same machinery. Once these objects, boundaries and ownership transitions are clear, the rest stops looking like a completely different system.</p><h2>What is next</h2><p>In the final part of this series, we will look at how one physical machine can become an entire network by using Linux virtualization tools.</p><p>We will take the networking machinery we have already built and use virtual interfaces, network namespaces, and related Linux primitives to create multiple isolated hosts and connect them together inside one system.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/p/inside-the-linux-networking-stack?utm_source=substack&utm_medium=email&utm_content=share&action=share&quot;,&quot;text&quot;:&quot;Share&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.softwareinthegrid.com/p/inside-the-linux-networking-stack?utm_source=substack&utm_medium=email&utm_content=share&action=share"><span>Share</span></a></p><h2>Sources</h2><ul><li><p><em>Understanding Linux Network Internals</em> by <strong>Christian Benvenuti</strong></p></li><li><p><em>Linux Kernel Networking: Implementation and Theory</em> by <strong>Rami Rosen</strong></p></li><li><p><a href="https://docs.kernel.org/">Linux kernel documentation</a></p></li></ul><h2>Assistance</h2><p>ChatGPT, GPT-5.6 Sol</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.softwareinthegrid.com/subscribe?"><span>Subscribe now</span></a></p><h3>Next Article:</h3><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;a5f4d07c-a333-4d0d-811e-8f8e119b15f4&quot;,&quot;caption&quot;:&quot;Previous Article:&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Networking Machinery for Software Engineers Part 4: Rebuilding a Network Inside One Linux Machine&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer in the energy sector. I publish Software in the Grid, exploring how software works inside modern power infrastructure.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-10-17T20:33:10.640Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!7DWE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76d0fb2a-9816-4860-b7bb-2d139b51347a_1672x941.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/networking-machinery-for-software-323&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:220904040,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><h3>Series Hub:</h3><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;5cb25fe9-a3c8-43f4-a342-937bd2b3e8cb&quot;,&quot;caption&quot;:&quot;I have worked with networked software for years, but for most of that time the network was something I used rather than something I really understood. I could open a socket, call an API, connect to an IP address, and continue with the part of the system I was responsible for.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;lg&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Networking in the Power Grid for Software Developers&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer in the energy sector. I publish Software in the Grid, exploring how software works inside modern power infrastructure.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-08-27T21:18:02.367Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!sXgD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2f83a8-82b3-42d5-817b-5266707341bb_1672x941.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/networking-in-the-power-grid-for&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:213058272,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div>]]></content:encoded></item><item><title><![CDATA[Building Your Own Web Server — Part 4: Single-threaded non-blocking server]]></title><description><![CDATA[This article is part of Software Foundations, where I explore networking, protocols, operating systems, and software systems from first principles.]]></description><link>https://www.softwareinthegrid.com/p/building-your-own-web-server-part-5c0</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/building-your-own-web-server-part-5c0</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Mon, 28 Sep 2026 12:42:21 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!04yy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74f37138-d902-4049-87f4-f4f38d17b266_1000x389.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!04yy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74f37138-d902-4049-87f4-f4f38d17b266_1000x389.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!04yy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74f37138-d902-4049-87f4-f4f38d17b266_1000x389.webp 424w, https://substackcdn.com/image/fetch/$s_!04yy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74f37138-d902-4049-87f4-f4f38d17b266_1000x389.webp 848w, https://substackcdn.com/image/fetch/$s_!04yy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74f37138-d902-4049-87f4-f4f38d17b266_1000x389.webp 1272w, https://substackcdn.com/image/fetch/$s_!04yy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74f37138-d902-4049-87f4-f4f38d17b266_1000x389.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!04yy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74f37138-d902-4049-87f4-f4f38d17b266_1000x389.webp" width="1000" height="389" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/74f37138-d902-4049-87f4-f4f38d17b266_1000x389.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:389,&quot;width&quot;:1000,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:37658,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/217819342?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F957f60f1-cc7f-46d4-a752-b4c407bdcb5d_1000x421.webp&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!04yy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74f37138-d902-4049-87f4-f4f38d17b266_1000x389.webp 424w, https://substackcdn.com/image/fetch/$s_!04yy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74f37138-d902-4049-87f4-f4f38d17b266_1000x389.webp 848w, https://substackcdn.com/image/fetch/$s_!04yy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74f37138-d902-4049-87f4-f4f38d17b266_1000x389.webp 1272w, https://substackcdn.com/image/fetch/$s_!04yy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74f37138-d902-4049-87f4-f4f38d17b266_1000x389.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>This article is part of Software Foundations, where I explore networking, protocols, operating systems, and software systems from first principles. These foundations support the broader work of <a href="https://www.softwareinthegrid.com/">Software in the Grid</a>.</em></p><div><hr></div><h2><strong>All articles in this series</strong></h2><ol><li><p><a href="https://www.softwareinthegrid.com/p/0c55774e-8b08-4ccf-9ebd-470a0d29d0c5">Building Your Own Web Server: Part 1 &#8212; Theory and Foundations</a></p></li><li><p><a href="https://www.softwareinthegrid.com/p/6a23363c-71d3-42e7-bce4-2bdc3931fd60">Building Your Own Web Server: Part 2 &#8212; Plan and Implementation of HTTP and Configuration parser</a></p></li><li><p><a href="https://www.softwareinthegrid.com/p/000b7742-1f55-4e1e-b324-dc91656a4be0">Building Your Own Web Server &#8212; Part 3: Blocking Single and Multithreaded Server</a></p></li><li><p><strong>Building Your Own Web Server &#8212; Part 4: Single-threaded non-blocking server</strong></p></li></ol><h2>Preface</h2><p>Hello friend ,</p><p>if you are reading these lines it means that you achieved the 4th part of our series where we are trying to understand how web servers work under the hood, what challenges it faces, what approaches and concepts are used, and what pros and cons they have. If you are already here, you already learned or refreshed so many things: structure of http protocol, threads in Linux, lexical analyse, sockets, basics of networking and servers. It is already much more than some programmers know. I&#8217;m very proud of you! And it is an honour to make this journey with you. So to sum up, we&#8217;ve already gone through many things together in the first three articles:</p><ul><li><p>what is http, and how it works</p></li><li><p>which features and version it has</p></li><li><p>how we can handle http requests and send responses</p></li><li><p>how we can configure server and setup routing</p></li><li><p>how we can crash the whole server just with one persistent connection by using one blocking thread</p></li><li><p>how we can gobble all memory in our machine up with multithreaded server</p></li></ul><p>But it was just preparation, just a basis to be ready for the final and the most sophisticated topic.</p><p>Do you want to meet the final boss? &#128526; Let&#8217;s go.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.softwareinthegrid.com/subscribe?"><span>Subscribe now</span></a></p><h2>Intro</h2><p>Let me remind you. <a href="https://www.softwareinthegrid.com/p/000b7742-1f55-4e1e-b324-dc91656a4be0">Last article</a>: we finished with implementation of the <a href="https://github.com/DmytroHuzz/build_own_webserver/blob/main/server_v2.py">multithreaded web server.</a></p><p>And also we compared it performance to single threaded server. And we have noticed that not everything is so good with that approach. Threads required a lot of additional time and recourses and it affect our performance. And this &#8220;non-blocking&#8221; multithreaded approach&#8230; actually isn&#8217;t really non-blocking &#128517;.</p><blockquote><p>&#128161; recv() still block every thread and consume a lot of time and resources for nothing.</p></blockquote><p>But is there a way to use benefits of every of this approach and avoid problems follows to them?</p><p>Can we combine simplicity of single thread and avoid blocking? Can we do not waste a cpu time for fruitless waiting? And can we still have opportunity to handle modern loading and scaling.</p><p>Hopefully yes, and answer is I/O event notification mechanism!</p><p>Let&#8217;s talk about it more.</p><div><hr></div><h2><strong>So&#8230; what is I/O event notification mechanism and epoll?</strong></h2><p>To explain it more visually, let&#8217;s try to find a nice analogy. Let&#8217;s imagine that you are a mail assistant in a big apartment building and responsible for managing hundreds of mailboxes of every apartment. You have to pick up the mail every time it arrives in any mailbox and reply on it.</p><p>With our first implementation with a blocking single threaded server your workflow would look like this.</p><p><strong>First implementation</strong></p><p>You are standing on the main entrance of the building and waiting for the post man, when he comes and brings the first mail, you immediately pick it up, write an answer, and then just staying and waiting for the new mail for the same flat. And if postman comes with mails for other flat you just sending him away and saying that you are busy, and waiting for only one special mail for your first flat.</p><p><strong>Second implementation</strong></p><p>Multithreaded approach looks very similar, but instead of that you are only one persona who should manage mailing of every apartment, we have a personal assistance for every flat, which is most of the time just waiting for the new post for his flat. Imagine how expensive and inefficient that is.</p><p><strong>New approach</strong></p><p>Now let&#8217;s imagine that you do not need to wait for the postman or check boxes or wait for particular post. You just comfortable sitting in you office in the building and every time when postman has some messages for any flat in your house he brings them directly to you. He ring in your bell and live messages in your postbox. So you can just pick them up, and reply on every. In that way your resources and efforts are used only for usefull work and only when they are needed. This is how I/O event notification mechanism works. And this mechanism is implemented by epoll system calls on Linux.</p><div><hr></div><h3><strong>&#9889; epoll in action</strong></h3><p>Let&#8217;s look at what this approach looks like in code.</p><p>When using epoll, you don&#8217;t check every socket in a loop. Instead, you wait once &#8212; and the kernel gives you a list of sockets that are ready. You simply pick them up and handle them.<br></p><pre><code><code>events = epoll_wait()
for each ready_socket in events:
    read data
</code></code></pre><p>It&#8217;s simple. You <strong>don&#8217;t waste time</strong> checking sockets that have nothing to say. You just process the ones that are ready &#8212; and go back to waiting.</p><p>This is fundamentally different from blocking or even multithreaded models:</p><ul><li><p>In the blocking version, you could only wait on one socket at a time.</p></li><li><p>In the multithreaded version, you created a thread per socket and they all waited separately (wasting resources).</p></li><li><p>But with epoll, one thread can wait for thousands of sockets and act <strong>only</strong> when something meaningful happens.</p></li></ul><p>This is why it&#8217;s so efficient &#8212; and why it&#8217;s used in high-performance servers like NGINX and runtimes like Node.js and Python&#8217;s async ecosystem.</p><div><hr></div><h3><strong>How it works under the hood</strong></h3><p>Let&#8217;s now step away from the analogy and look at how epoll actually works at the system level.</p><ul><li><p>epoll is a Linux kernel feature designed for <strong>I/O event notification</strong>.</p></li><li><p>It allows a single thread to monitor <strong>thousands of file descriptors</strong> &#8212; sockets, pipes, files &#8212; without constantly looping over them.</p></li><li><p>Instead of <em>asking</em> each socket &#8220;Are you ready?&#8221;, you simply register them once, and the kernel will <strong>inform you</strong> when any of them is ready to be read from or written to.</p></li></ul><p>This saves CPU time, avoids unnecessary system calls, and lets you scale your server efficiently.</p><div><hr></div><h3><strong>Triggering modes:</strong></h3><p>There are two ways you can receive notifications from epoll, and they behave differently:</p><ul><li><p><strong>Level-triggered</strong> (default):</p><p>The kernel keeps notifying you <strong>as long as</strong> a socket remains in a ready state.</p><p>This is simpler to implement and works well in most cases.</p></li><li><p><strong>Edge-triggered</strong>:</p><p>You get notified <strong>only once</strong> &#8212; the moment a socket <em>becomes</em> ready. If you don&#8217;t read all available data immediately, you <strong>won&#8217;t get notified again</strong>.</p><p>This mode is more efficient, but it requires extra care: you must drain all the data (or write as much as possible) in one go, or you might miss future events.</p></li></ul><blockquote><p>&#128161; In our Python implementation, we&#8217;ll stick with level-triggered behavior &#8212; it&#8217;s easier to reason about and already gives us great performance.</p></blockquote><div><hr></div><h3><strong>Typical usage flow</strong></h3><p>Let&#8217;s quickly walk through how epoll is typically used in practice. Whether in C or Python (via selectors), the core steps are the same:</p><ol><li><p><strong>Create an epoll instance</strong></p><p>This is your central &#8220;inbox&#8221; &#8212; a place where all events will be collected.</p></li><li><p><strong>Register sockets you&#8217;re interested in</strong></p><p>You tell the kernel: &#8220;Please watch this socket and notify me when it&#8217;s ready to read or write.&#8221;</p></li><li><p><strong>Call epoll_wait() (or selector.select() in Python)</strong></p><p>Your program now pauses, efficiently waiting. It doesn&#8217;t consume CPU cycles &#8212; it just sleeps until something meaningful happens.</p></li><li><p><strong>Handle only the sockets that reported an event</strong></p><p>When epoll_wait() returns, it gives you a list of sockets that are ready.</p><p>You process each one: read the data, write the response, or close the connection &#8212; then go back to waiting.</p></li></ol><blockquote><p>&#129496;&#8205;&#9794;&#65039; The beauty of this approach is that your server stays completely calm and efficient &#8212; only acting when there&#8217;s real work to do.</p></blockquote><div><hr></div><p>&#128214; Want more depth? Here&#8217;s the official man page:</p><p>&#128279; <a href="https://man7.org/linux/man-pages/man7/epoll.7.html">https://man7.org/linux/man-pages/man7/epoll.7.html</a></p><div><hr></div><h2>How does Nginx use it?</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!w6Yq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15bc3c54-d509-4197-a6ae-8174aa33b9a8_800x411.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!w6Yq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15bc3c54-d509-4197-a6ae-8174aa33b9a8_800x411.webp 424w, https://substackcdn.com/image/fetch/$s_!w6Yq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15bc3c54-d509-4197-a6ae-8174aa33b9a8_800x411.webp 848w, https://substackcdn.com/image/fetch/$s_!w6Yq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15bc3c54-d509-4197-a6ae-8174aa33b9a8_800x411.webp 1272w, https://substackcdn.com/image/fetch/$s_!w6Yq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15bc3c54-d509-4197-a6ae-8174aa33b9a8_800x411.webp 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!w6Yq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15bc3c54-d509-4197-a6ae-8174aa33b9a8_800x411.webp" width="800" height="411" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/15bc3c54-d509-4197-a6ae-8174aa33b9a8_800x411.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:411,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Nginx non-blocking&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Nginx non-blocking" title="Nginx non-blocking" srcset="https://substackcdn.com/image/fetch/$s_!w6Yq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15bc3c54-d509-4197-a6ae-8174aa33b9a8_800x411.webp 424w, https://substackcdn.com/image/fetch/$s_!w6Yq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15bc3c54-d509-4197-a6ae-8174aa33b9a8_800x411.webp 848w, https://substackcdn.com/image/fetch/$s_!w6Yq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15bc3c54-d509-4197-a6ae-8174aa33b9a8_800x411.webp 1272w, https://substackcdn.com/image/fetch/$s_!w6Yq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15bc3c54-d509-4197-a6ae-8174aa33b9a8_800x411.webp 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I encourage you to read this <a href="https://blog.nginx.org/blog/inside-nginx-how-we-designed-for-performance-scale">amazing official article from Nginx about their architecture</a>. They describe nicely not only how the non blocking approach work for them. But evolution and the whole architecture of the fastest server in the world.</p><p>I will add just a few takes away from the article about main concept of non-blicking approach:</p><blockquote><p>Think of the state machine like the rules for chess. Each HTTP transaction is a chess game. On one side of the chessboard is the web server &#8211; a grandmaster who can make decisions very quickly. On the other side is the remote client &#8211; the web browser that is accessing the site or application over a relatively slow network.</p><p>However, the rules of the game can be very complicated. For example, the web server might need to communicate with other parties (proxying to an upstream application) or talk to an authentication server. Third&#8209;party modules in the web server can even extend the rules of the game.</p><p>&#8230;</p><h3><strong>NGINX is a True Grandmaster</strong></h3><p>Perhaps you&#8217;ve heard of <a href="http://en.wikipedia.org/wiki/Simultaneous_exhibition">simultaneous exhibition</a> games, where one chess grandmaster plays dozens of opponents at the same time?</p><p>That&#8217;s how an NGINX worker process plays &#8220;chess.&#8221; Each worker (remember &#8211; there&#8217;s usually one worker for each CPU core) is a grandmaster that can play hundreds (in fact, hundreds of thousands) of games simultaneously.</p><ol><li><p>The worker waits for events on the listen and connection sockets.</p></li><li><p>Events occur on the sockets and the worker handles them:</p><ul><li><p>An event on the listen socket means that a client has started a new chess game. The worker creates a new connection socket.</p></li><li><p>An event on a connection socket means that the client has made a new move. The worker responds promptly.</p></li></ul></li></ol><p>A worker never blocks on network traffic, waiting for its &#8220;opponent&#8221; (the client) to respond. When it has made its move, the worker immediately proceeds to other games where moves are waiting to be processed, or welcomes new players in the door.</p></blockquote><p>I do not think if it makes sense to try me to rephrase or summaries the whole article. It is written too eloquent to try to replace it with something else. Therefore I truly recommend to check it out and enjoy it. ;)</p><h2>What does it have common with Node.js?</h2><p>There is also one very popular technology which in the end uses the same approach- Node.js.</p><p>Node.js is built on <strong>libuv</strong>, a cross-platform library that provides an event loop and non-blocking I/O. On Linux, libuv internally uses epoll to efficiently manage multiple I/O operations.</p><p>That means when your Node.js app listens for network connections, reads files, or waits for timers &#8212; it doesn&#8217;t block. Instead, all those events are registered with epoll, and Node.js reacts <strong>only</strong> when something is ready, just like we described earlier.</p><p>This is how Node.js achieves <strong>high concurrency in a single thread</strong> &#8212; exactly the same concept we&#8217;re exploring in our server.</p><p>I can&#8217;t avoid adding this beautiful article with nice visualisation of event loop and role of epoll in it:</p><p><a href="https://medium.com/preezma/node-js-event-loop-architecture-go-deeper-node-core-c96b4cec7aa4">https://medium.com/preezma/node-js-event-loop-architecture-go-deeper-node-core-c96b4cec7aa4</a>. It is absolutely a side topic. But if you are interested in it, I recommend you to read it. It gives you a deep understanding of one more technology. Consider it as 1+1 sale, two items with price of one ;)</p><div><hr></div><h2><strong>How does Python use epoll?</strong></h2><p>Now that we understand what epoll is and why it&#8217;s powerful, you might wonder:</p><p><strong>&#8220;Do I need to use low-level C syscalls to access it?&#8221;</strong></p><p>The answer is: <strong>not at all</strong> &#8212; Python gives us a clean, high-level way to use epoll through its <a href="https://docs.python.org/3/library/selectors.html">selectors module.</a></p><h3><strong>The idea</strong></h3><p>Python wraps the system&#8217;s best available I/O strategy &#8212; whether it&#8217;s select, poll, kqueue, or epoll &#8212; and gives us a consistent interface. On Linux, this wrapper uses epoll under the hood.</p><p>So when we write:<br></p><pre><code><code>import selectors
sel = selectors.DefaultSelector()
</code></code></pre><p>Python automatically chooses the best mechanism for us. On Linux, this is:<br></p><pre><code><code>&lt;class 'selectors.EpollSelector'&gt;
</code></code></pre><p>That means we&#8217;re already using epoll &#8212; <strong>without doing anything special</strong>.</p><div><hr></div><h3><strong>Why is this great?</strong></h3><p>It gives us the power of epoll (massively scalable I/O) without needing to dive into C APIs or system-level programming. You just write Python code that says:</p><ul><li><p>&#8220;Watch this socket and tell me when it&#8217;s ready.&#8221;</p></li><li><p>Then react only when something happens.</p></li></ul><div><hr></div><h3><strong>Simple example:</strong></h3><pre><code><code>sock.setblocking(False)
sel.register(sock, selectors.EVENT_READ, data=...)
</code></code></pre><p>Later in your event loop:<br></p><pre><code><code>events = sel.select(timeout=1)
for key, mask in events:
    handle(key.fileobj)
</code></code></pre><div><hr></div><h3>How can we use this approach in our server?</h3><p>Now that we&#8217;ve seen how epoll works &#8212; both conceptually and in other technologies like NGINX and Node.js &#8212; let&#8217;s bring all of that to life in our own server.</p><p>Instead of using threads, we&#8217;ll build a <strong>single-threaded, event-driven server</strong> using Python&#8217;s selectors module, which wraps around epoll (on Linux) or the best available alternative on other systems.</p><p>We&#8217;ll still support everything we&#8217;ve done before: parsing requests, routing, handling static files, and supporting keep-alive &#8212; but now, all of it will happen inside one lightweight, non-blocking event loop.</p><p>Take a deep breath. The code might look longer, but it&#8217;s structured and commented for clarity. And once you see how it works, you&#8217;ll understand why this model powers some of the fastest servers in the world.</p><p>Let&#8217;s build it.<br></p><pre><code><code>import socket
import selectors
from typing import Tuple, Optional
from config_parser import load_config, ServerConfig
from http_parser import HTTPParser, HTTPMessage

# -------------------------
# Route Matching Logic
# -------------------------

class RouteMatcher:
    @staticmethod
    def match_location(locations, uri: str):
        # Find the longest prefix-matching location block
        matched_location = None
        longest_prefix = -1
        for path, root_dir in locations.items():
            if uri.startswith(path) and len(path) &gt; longest_prefix:
                matched_location = root_dir
                longest_prefix = len(path)
        return matched_location

# -------------------------
# Data Buffer
# -------------------------

class DataProvider:
    def __init__(self):
        self._data = b""

    @property
    def data(self) -&gt; bytes:
        return self._data

    @data.setter
    def data(self, chunk: bytes):
        # Append new data to the buffer
        self._data += chunk

    def reduce_data(self, size: int):
        # Remove processed data from the buffer
        self._data = self._data[size:]

# -------------------------
# Message Processor
# -------------------------

class HTTPProcessor:
    def __init__(self, data_provider: DataProvider):
        self.data_provider = data_provider

    def get_one_http_message(self) -&gt; Optional[HTTPMessage]:
        try:
            # Attempt to parse a single HTTP message from the buffer
            message, consumed = HTTPParser.parse_message(self.data_provider.data)
            if message:
                # Remove the parsed message from the buffer
                self.data_provider.reduce_data(consumed)
            return message
        except Exception:
            return None

# -------------------------
# Server Entrypoint
# -------------------------

class Server:
    """
    Main server class. Reads config, binds to the correct port, and handles requests.
    """

    # ===================================================
    # Main epoll-based server loop:
    # 1. Create a non-blocking server socket.
    # 2. Register it with a selector to watch for incoming connections.
    # 3. Enter the event loop:
    #     a. Wait for events using selector.select().
    #     b. If the event is on the server socket, accept a new client.
    #     c. If the event is on a client socket, read data and respond.
    # 4. Parse requests and route them using our config and HTTP parser.
    # 5. Serve files or respond with a 404.
    # ===================================================

    def __init__(self, config_path: str):
        self.config = load_config(config_path)
        self.selector = selectors.DefaultSelector()

    def start(self):
        port = self.config.listen_ports[0]
        server_sock = socket.socket()
        server_sock.bind(("", port))
        server_sock.listen()
        server_sock.setblocking(False)
        # Register the server socket to accept new connections
        self.selector.register(server_sock, selectors.EVENT_READ, data=None)
        print(f"[Server] Listening on port {port}")

        try:
            while True:
                # Wait for events on registered sockets
                events = self.selector.select(timeout=1)
                # Iterate over the events returned by the selector
                # Each event corresponds to a socket ready for I/O
                for key, mask in events:
                    if key.data is None:
                        # Accept a new incoming connection from a client.
                        self._accept_connection(key.fileobj)
                    else:
                        # Handle incoming data from a client socket.
                        self._service_connection(key, mask)
        except KeyboardInterrupt:
            print("[Server] Shutting down")
        finally:
            # Clean up resources on shutdown
            self.selector.close()
            server_sock.close()

    def _accept_connection(self, sock):
        # Accept a new incoming connection from a client.
        # Set it to non-blocking and register it with the selector.
        conn, addr = sock.accept()
        print(f"[Server] Accepted connection from {addr}")
        conn.setblocking(False)
        # Create a new data provider for the connection
        data_provider = DataProvider()
        # Register the connection for reading
        self.selector.register(conn, selectors.EVENT_READ, data=data_provider)

    def _service_connection(self, key, mask):
        # Handle incoming data from a client socket.
        # Read data and trigger request processing if data is received.
        sock = key.fileobj
        data_provider = key.data
        addr = sock.getpeername()
        if mask &amp; selectors.EVENT_READ:
            try:
                # Read data from the socket
                data = sock.recv(1024)
            except ConnectionResetError:
                data = None
            if data:
                # Add received data to the buffer
                data_provider.data = data
                self._handle_request(sock, data_provider)
            else:
                # Close the connection if no data is received
                print(f"[Server] Closing connection to {addr}")
                self.selector.unregister(sock)
                sock.close()

    def _handle_request(self, sock, data_provider):
        # Parse the buffered data into an HTTP request message.
        http_processor = HTTPProcessor(data_provider)
        while request := http_processor.get_one_http_message():
            # Determine the correct file path based on requested URL.
            url = request.url
            root = 'html'  # Default root directory
            if url == "/":
                url = "/index.html"
            else:
                # Match the location block for the requested URL
                root = RouteMatcher.match_location(self.config.routes[self.config.listen_ports[0]], url)

            file_path = f"{root}{url}"
            print(f"[Request] {url} =&gt; {file_path}")

            # Try to read and serve the requested file.
            try:
                with open(file_path, "rb") as f:
                    body = f.read()
                headers = (
                    "HTTP/1.1 200 OK\r\n"
                    f"Content-Length: {len(body)}\r\n"
                    "Content-Type: text/plain\r\n"
                )
                # Check if connection should be kept alive or closed.
                if "keep-alive" in request.headers.get("connection", "").lower():
                    headers += "Connection: keep-alive\r\n"
                else:
                    # Close the connection if not keep-alive
                    self.selector.unregister(sock)
                    sock.close()
                    return
                headers += "\r\n"
                sock.sendall(headers.encode() + body)
            # If something goes wrong (e.g., file not found), send a 404.
            except Exception as e:
                print(f"[Error] {e}")
                self._send_404(sock)
                self.selector.unregister(sock)
                sock.close()
                return

    def _send_404(self, sock):
        # Helper method to respond with a 404 Not Found status.
        msg = b"404 Not Found"
        headers = (
            "HTTP/1.1 404 Not Found\r\n"
            f"Content-Length: {len(msg)}\r\n"
            "Content-Type: text/plain\r\n\r\n"
        )
        sock.sendall(headers.encode() + msg)

# -------------------------
# Start Server
# -------------------------

if __name__ == "__main__":
    # Load the server configuration and start the server
    server = Server("config.conf")
    server.start()
</code></code></pre><p>Please, find the full implementation <a href="https://github.com/DmytroHuzz/build_own_webserver/blob/main/server_v3.py">here</a>.</p><p>When I implemented this approach, I was so excited to measure it performance. I believe you are as well ;) Let&#8217;s check it out:</p><h2><strong>&#128202; Benchmark Results (All 4 Scenarios)</strong></h2><p><strong>#:</strong> 1<br><strong>Scenario:</strong> Single request, no keep-alive<br><strong>Command:</strong> ab -n 100000<br><strong>Requests/sec:</strong> 9897.79<br><strong>Time:</strong> 10.103</p><p><strong>#:</strong> 2<br><strong>Scenario:</strong> Single request, keep-alive<br><strong>Command:</strong> ab -n 100000 -k<br><strong>Requests/sec:</strong> 18247.78<br><strong>Time:</strong> 5.480</p><p><strong>#:</strong> 3<br><strong>Scenario:</strong> Concurrent (50x), no keep-alive<br><strong>Command:</strong> ab -n 100000 -c 50<br><strong>Requests/sec:</strong> 9887.54<br><strong>Time:</strong> 10.114</p><p><strong>#:</strong> 4<br><strong>Scenario:</strong> Concurrent (50x), with keep-alive<br><strong>Command:</strong> ab -n 100000 -c 50 -k<br><strong>Requests/sec:</strong> 27261.97<br><strong>Time:</strong> 3.668</p><h3><strong>&#128202; Performance Comparison Table</strong></h3><p><strong>Scenario:</strong> <strong>1. Single request, no keep-alive</strong><br><strong>Command:</strong> ab -n 100000<br><strong>Single-threaded:</strong> 10308.65 req/sec<br><strong>Multithreaded Server:</strong> 7871.07 req/sec<br><strong>Non-blocking epoll:</strong> <strong>9,897.79 req/sec</strong></p><p><strong>Scenario:</strong> <strong>2. Single request, with keep-alive</strong><br><strong>Command:</strong> ab -n 100000 -k<br><strong>Single-threaded:</strong> 19351.89 req/sec<br><strong>Multithreaded Server:</strong> 19139.16 req/sec<br><strong>Non-blocking epoll:</strong> <strong>18,247.78 req/sec</strong></p><p><strong>Scenario:</strong> <strong>3. Concurrent (50x), no keep-alive</strong><br><strong>Command:</strong> ab -n 100000 -c 50<br><strong>Single-threaded:</strong> 22733.18 req/sec<br><strong>Multithreaded Server:</strong> 7182.58 req/sec<br><strong>Non-blocking epoll:</strong> <strong>9,887.54 req/sec</strong></p><p><strong>Scenario:</strong> <strong>4. Concurrent (50x), with keep-alive</strong><br><strong>Command:</strong> ab -n 100000 -c 50 -k<br><strong>Single-threaded:</strong> &#10060; Crashed<br><strong>Multithreaded Server:</strong> 13777.80 req/sec<br><strong>Non-blocking epoll:</strong> <strong>27,261.97 req/sec</strong></p><h2><strong>&#129514; Interpreting the Benchmarks &#8212; What do they really tell us?</strong></h2><p>The numbers we&#8217;ve seen aren&#8217;t just data points &#8212; they reveal how each architecture behaves under real-world pressure.</p><p>Here&#8217;s the story behind the stats:</p><h3><strong>&#129525; Multithreaded server</strong></h3><p>At first glance, it might seem like the multithreaded version should dominate &#8212; more threads, more parallelism, right?</p><p>But the reality is more nuanced. Each thread adds overhead: memory, context switching, and blocking on recv() calls. That overhead starts to hurt, especially when connection count rises.</p><p>So while multithreading helped us avoid complete blocking, it didn&#8217;t scale efficiently.</p><h3><strong>&#128683; Naive single-threaded server</strong></h3><p>Surprisingly, the original single-threaded version performed well in some cases &#8212; particularly under low concurrency.</p><p>Why? It&#8217;s simple: there&#8217;s almost no overhead. But the moment multiple concurrent connections pile up, this model hits its limits. It blocks on one socket and ignores the rest. That&#8217;s why it crashes in the final scenario.</p><h3><strong>&#9889; Epoll-based non-blocking server</strong></h3><p>This is where things change.</p><p>Under high concurrency with keep-alive (-c 50 -k), this version soars past the others &#8212; <strong>27,000+ requests/sec</strong>. That&#8217;s not a small jump. That&#8217;s architectural advantage in action.</p><p>Why does it work so well?</p><ul><li><p>We wait only when we must.</p></li><li><p>We act only when sockets are ready.</p></li><li><p>We scale without threads.</p></li></ul><p>This version does <strong>more work with fewer resources</strong>, and it shows.</p><p>So yes &#8212; non-blocking I/O isn&#8217;t just a theoretical advantage. It&#8217;s a practical performance booster. Especially in the kind of high-connection environments modern servers live in.</p><p>This is the power of event-driven architecture. And now you&#8217;ve seen it, measured it, and built it with your own hands. &#128170;</p><div><hr></div><h2><strong>&#127919; Final Thoughts</strong></h2><p>So&#8230; we made it.</p><p>We started with the most naive blocking approach, hit the limits of multithreading, and finally built something truly powerful &#8212; a non-blocking, single-threaded server that can handle tens of thousands of connections with grace.</p><p>Looking at the benchmarks, the difference is clear.</p><p>It&#8217;s not just about raw numbers &#8212; it&#8217;s about <em>how</em> we use our machine&#8217;s resources.</p><ul><li><p>No wasted CPU time.</p></li><li><p>No useless threads sleeping in the background.</p></li><li><p>Just one calm loop, doing real work only when needed.</p></li></ul><p>This architecture isn&#8217;t just a toy. It&#8217;s how real-world servers like NGINX, Node.js, and many modern async frameworks work. And now you&#8217;ve built your own version of it &#8212; from scratch.</p><p>That&#8217;s a huge achievement. Be proud of it.</p><p>And if it feels like magic &#8212; it kind of is. But it&#8217;s the kind of magic you now understand deeply.</p><p>This was the last topic I planned to cover in that series. And the planned articles are complete. But it does not mean that the topic is exhaustive. There are still so many concepts, features and topics which we partially mentioned during this series and which exist in modern web.</p><p>But where do we go from here? Should we build a proxy mode? Serve files smarter? Add SSL? Or maybe even&#8230; write our own async framework?</p><p>Now it totally depends on you. Please share your ideas and let me know what you&#8217;d like to build next.</p><p>Please, let me know. Because this project &#8212; just like the web &#8212; is full of new paths to explore.&#128640;</p><p><a href="https://www.softwareinthegrid.com/p/18c4d9c2-334a-42b4-b412-4a36ae930029">Series hub: Building a Web Server from Scratch</a></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Software in the Grid is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Building Your Own Web Server — Part 3: Blocking Single and Multithreaded Server]]></title><description><![CDATA[This article is part of Software Foundations, where I explore networking, protocols, operating systems, and software systems from first principles.]]></description><link>https://www.softwareinthegrid.com/p/building-your-own-web-server-part-fa1</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/building-your-own-web-server-part-fa1</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Mon, 28 Sep 2026 12:40:54 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!tBgn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2c1e202-77d7-4aa7-b93d-d10402b8cdec_1000x380.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tBgn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2c1e202-77d7-4aa7-b93d-d10402b8cdec_1000x380.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tBgn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2c1e202-77d7-4aa7-b93d-d10402b8cdec_1000x380.webp 424w, https://substackcdn.com/image/fetch/$s_!tBgn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2c1e202-77d7-4aa7-b93d-d10402b8cdec_1000x380.webp 848w, https://substackcdn.com/image/fetch/$s_!tBgn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2c1e202-77d7-4aa7-b93d-d10402b8cdec_1000x380.webp 1272w, https://substackcdn.com/image/fetch/$s_!tBgn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2c1e202-77d7-4aa7-b93d-d10402b8cdec_1000x380.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tBgn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2c1e202-77d7-4aa7-b93d-d10402b8cdec_1000x380.webp" width="1000" height="380" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e2c1e202-77d7-4aa7-b93d-d10402b8cdec_1000x380.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:380,&quot;width&quot;:1000,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:34832,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/217819257?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35f93e27-5ecc-4654-bbfc-ab764b10845c_1000x421.webp&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!tBgn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2c1e202-77d7-4aa7-b93d-d10402b8cdec_1000x380.webp 424w, https://substackcdn.com/image/fetch/$s_!tBgn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2c1e202-77d7-4aa7-b93d-d10402b8cdec_1000x380.webp 848w, https://substackcdn.com/image/fetch/$s_!tBgn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2c1e202-77d7-4aa7-b93d-d10402b8cdec_1000x380.webp 1272w, https://substackcdn.com/image/fetch/$s_!tBgn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe2c1e202-77d7-4aa7-b93d-d10402b8cdec_1000x380.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>This article is part of Software Foundations, where I explore networking, protocols, operating systems, and software systems from first principles. These foundations support the broader work of <a href="https://www.softwareinthegrid.com/">Software in the Grid</a>.</em></p><div><hr></div><h2><strong>All articles in this series</strong></h2><ol><li><p><a href="https://www.softwareinthegrid.com/p/0c55774e-8b08-4ccf-9ebd-470a0d29d0c5">Building Your Own Web Server: Part 1 &#8212; Theory and Foundations</a></p></li><li><p><a href="https://www.softwareinthegrid.com/p/6a23363c-71d3-42e7-bce4-2bdc3931fd60">Building Your Own Web Server: Part 2 &#8212; Plan and Implementation of HTTP and Configuration parser</a></p></li><li><p><a href="https://www.softwareinthegrid.com/p/000b7742-1f55-4e1e-b324-dc91656a4be0">Building Your Own Web Server &#8212; Part 3: Blocking Single and Multithreaded Server</a></p></li><li><p><a href="https://www.softwareinthegrid.com/p/051d629f-b465-4f38-95db-987ea8c412ae">Building Your Own Web Server &#8212; Part 4: Single-threaded non-blocking server</a></p></li></ol><h2><strong>&#128588; Preface</strong></h2><p>Let me start with a small note. I&#8217;m very happy we didn&#8217;t jump into the implementation of the server right from the beginning. By first building out modules like the configuration parser and the HTTP request parser, we now have a solid foundation that we can rely on &#8212; and that allows us to focus this part purely on the server logic.</p><p>This article continues our journey of implementing a web server from scratch, and here we&#8217;ll cover the most important part: <strong>handling TCP connections and serving HTTP traffic</strong>.</p><p>We&#8217;ll go through three types of server models step-by-step:</p><ol><li><p><strong>Blocking single-threaded server</strong> &#8212; the simplest possible form</p></li><li><p><strong>Blocking server with keep-alive support</strong> &#8212; to match HTTP/1.1 behaviour</p></li><li><p><strong>Multithreaded non-blocking server</strong> &#8212; real-world concurrency and performance</p></li></ol><p>For each of them, we&#8217;ll walk through the algorithm, real Python implementation, and performance benchmarks with ApacheBench.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.softwareinthegrid.com/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><h2><strong>&#129504; What You&#8217;ll Learn</strong></h2><p>In this part of the series, you&#8217;ll get a hands-on understanding of how real web servers operate at the socket and HTTP level.</p><p>By the end of the article, you&#8217;ll know how to:</p><ul><li><p>&#9989; Implement a <strong>blocking TCP server</strong> that serves HTTP requests</p></li><li><p>&#128257; Extend it to support <strong>HTTP keep-alive</strong> connections (used by all modern browsers)</p></li><li><p>&#129525; Use <strong>threads</strong> to handle multiple clients in parallel</p></li><li><p>&#129521; Structure your code with clean, testable building blocks (HTTPSession, HTTPProcessor, DataProvider)</p></li><li><p>&#129517; Parse and route requests using a <strong>configuration file</strong> with server and location blocks (NGINX-style)</p></li><li><p>&#128200; Benchmark your server using ab (ApacheBench) and analyze the results</p></li><li><p>&#9878;&#65039; Compare performance between <strong>single-threaded</strong> and <strong>multithreaded</strong> architectures</p></li><li><p>&#128104;&#8205;&#128187; Prepare your architecture for the next level: <strong>non-blocking I/O and event loops</strong></p></li></ul><div><hr></div><h2><strong>&#129521; 1. Blocking Server (No Keep-Alive)</strong></h2><p>Let&#8217;s start from the most minimal working implementation.</p><h3><strong>&#10067; What is a Blocking Server?</strong></h3><p>This type of server does one thing at a time:</p><ul><li><p>It listens for incoming TCP connections</p></li><li><p>When a client connects, it reads the request</p></li><li><p>Sends a response</p></li><li><p>Closes the connection and exits</p></li></ul><p>This version is single-threaded and serves only one request. If the client is slow or does not send anything &#8212; the server just waits (blocks). It&#8217;s not usable in practice, but is a great place to start.</p><div><hr></div><h3><strong>&#129513; Algorithm Description (Beginner Friendly)</strong></h3><ol><li><p><strong>Create a socket</strong> using Python&#8217;s socket module</p></li><li><p><strong>Bind</strong> it to a host and port so the OS knows where to route connections</p></li><li><p><strong>Listen</strong> for incoming client connections</p></li><li><p><strong>Accept</strong> the first connection &#8212; this blocks the server until a client connects</p></li><li><p><strong>Receive data</strong> from the client &#8212; this also blocks if nothing is sent</p></li><li><p>If data is received:</p><ul><li><p>Compose a basic HTTP 200 OK response</p></li><li><p>Send the response</p></li></ul></li><li><p><strong>Close the connection</strong> and exit the server</p></li></ol><p>That&#8217;s it! Here&#8217;s the code.</p><div><hr></div><h3><strong>&#128187; Python Implementation (With Comments)</strong></h3><pre><code><code>import socket

class Server:
    def __init__(self, host='', port=8080):
        self.HOST = host  # Empty string means "listen on all available interfaces"
        self.PORT = port  # Default port we&#8217;ll serve on

    def start_server(self):
        # Step 1: Create a TCP socket
        with socket.socket() as s:
            # Step 2: Bind the socket to the host and port
            s.bind((self.HOST, self.PORT))

            # Step 3: Start listening for connections
            s.listen()

            print(f"[Server] Listening on {self.HOST}:{self.PORT}")

            # Step 4: Accept a connection (blocking call)
            connection, client_address = s.accept()

            # Step 5: Use the connection
            with connection:
                print(f"[Server] Connected by address: {client_address}")

                # Step 6: Receive data (up to 1024 bytes)
                received_data = connection.recv(1024)

                if received_data:
                    # Step 7: Build a basic HTTP response
                    response = (
                        "HTTP/1.1 200 OK\r\n"
                        "Content-Length: 5\r\n"
                        "Content-Type: text/plain\r\n"
                        "\r\n"
                        "Hello"
                    )

                    # Step 8: Send response back to the client
                    connection.sendall(response.encode())

                # Step 9: Connection is closed automatically by 'with' block
</code></code></pre><div><hr></div><h3><strong>&#9989; Pros and &#10060; Cons</strong></h3><p><strong>&#9989; Pros:</strong> Very easy to understand and implement<br><strong>&#10060; Cons:</strong> Can only handle <strong>one</strong> connection ever</p><p><strong>&#9989; Pros:</strong> Good for debugging and experimentation<br><strong>&#10060; Cons:</strong> <strong>Blocks</strong> on every operation (accept, recv)</p><p><strong>&#9989; Pros:</strong> No concurrency &#8212; zero scalability<br><strong>&#10060; Cons:</strong> Not compatible with modern clients using keep-alive</p><div><hr></div><h2><strong>&#128257; 2. Blocking Server with Keep-Alive</strong></h2><p>In the previous section, we implemented the most basic version of a web server. It accepted a single connection, processed a single HTTP request, returned a dummy response, and then shut down. It worked, but it wasn&#8217;t realistic. Browsers and clients don&#8217;t behave that way &#8212; and servers shouldn&#8217;t either.</p><p>Let&#8217;s now move to the next step and support persistent TCP connections &#8212; i.e., <strong>keep-alive</strong> &#8212; which is the default in HTTP/1.1.</p><div><hr></div><h2><strong>&#128218; What is Keep-Alive?</strong></h2><p>By default, modern HTTP clients (including all browsers) expect that one TCP connection will be reused for multiple requests and responses. This saves a lot of time by avoiding repeated handshakes and allows for faster page loads.</p><p>But in our first server version, we closed the connection after a single response. This breaks keep-alive and forces the client to re-open a new connection every time.</p><p>Our goal now is to make the server:</p><ul><li><p>keep the connection open</p></li><li><p>accept multiple requests from the same socket</p></li><li><p>return multiple responses</p></li></ul><div><hr></div><h2><strong>&#9888;&#65039; Reminder:</strong></h2><h2><strong>recv()</strong></h2><h2><strong>Blocks</strong></h2><p>In Python, calling socket.recv(1024) is a <strong>blocking operation</strong>. It stops your thread and waits until:</p><ul><li><p>some data is available in the socket buffer, or</p></li><li><p>the client closes the connection</p></li></ul><p>This is dangerous in a real-world setup because it means a slow or idle client can block your whole server. For now, we accept this limitation and handle it in the next section using threads.</p><div><hr></div><h2><strong>&#129521; Introducing</strong></h2><h2><strong>HTTPSession,DataProvider, and HTTPProcessor</strong></h2><p>To build a robust and flexible design, we need to decompose our logic into smaller, clear components. Instead of shoving everything into a giant while-loop, we separate responsibilities.</p><div><hr></div><h3><strong>&#129504; HTTPSession: Manages a Single Client Connection</strong></h3><p>This class takes over the entire handling of a single TCP connection:</p><ul><li><p>It reads incoming bytes using recv()</p></li><li><p>Feeds the bytes into a DataProvider buffer</p></li><li><p>Parses full HTTP requests using HTTPProcessor</p></li><li><p>Generates responses (reads files from disk, builds HTTP headers, sends back data)</p></li><li><p>Decides whether to keep the connection alive or close it based on the request</p></li></ul><p>This gives us clean isolation: one class = one responsibility = easier maintenance.</p><div><hr></div><h3><strong>&#128230; DataProvider : Input Buffer for Raw Data</strong></h3><p>recv() gives us unpredictable chunks of data &#8212; possibly partial, multiple, or garbage. DataProvider:</p><ul><li><p>stores all incoming data</p></li><li><p>exposes a read-only .data property</p></li><li><p>allows dropping the bytes we already processed</p></li></ul><pre><code><code>class DataProvider:
    def __init__(self):
        self._data = b""

    @property
    def data(self) -&gt; bytes:
        return self._data

    @data.setter
    def data(self, new_data: bytes):
        self._data += new_data

    def reduce_data(self, size: int):
        self._data = self._data[size:]
</code></code></pre><div><hr></div><h3><strong>&#129504; HTTPProcessor: Extracts One Message from Buffer</strong></h3><p>Each time data is received, HTTPProcessor checks whether we can extract a <strong>full HTTP message</strong> from it.<br></p><pre><code><code>class HTTPProcessor:
    def __init__(self, data_provider: DataProvider):
        self.data_provider = data_provider

    def get_one_http_message(self) -&gt; Optional['HTTPMessage']:
        try:
            http_message, bytes_consumed = HTTPParser.parse_message(self.data_provider.data)
            if http_message:
                self.data_provider.reduce_data(bytes_consumed)
            return http_message
        except RuntimeError:
            return None
</code></code></pre><div><hr></div><h2><strong>&#129504; How Everything Works Together</strong></h2><p>Let&#8217;s walk through the entire server behaviuor:</p><h3><strong>&#128260; Step-by-step Overview</strong></h3><ol><li><p>The Server accepts a new socket connection.</p></li><li><p>It passes the connection to a new HTTPSession object.</p></li><li><p>The session enters a loop:</p><ul><li><p>It calls recv() and adds data to the buffer</p></li><li><p>It tries to parse a full HTTP message</p></li><li><p>If it succeeds, it sends the response</p></li><li><p>If the connection is not marked as keep-alive, it exits</p></li></ul></li><li><p>On exit, the connection is closed.</p></li></ol><div><hr></div><h3><strong>&#129514; Pseudo-Code Flow</strong></h3><pre><code><code>Start server
    While True:
        Accept new connection
        Create HTTPSession(connection)
        session.handle()

HTTPSession.handle():
    While connection is active:
        data = recv()  # blocks here!
        append data to buffer
        While True:
            message = parse one message from buffer
            if no message: break
            process request, generate response
            if no keep-alive:
                exit session
</code></code></pre><div><hr></div><h2><strong>&#128187; Implementation</strong></h2><p>Now let&#8217;s look at the full code:<br></p><pre><code><code>import socket
from typing import Tuple, Optional, Dict

class HTTPMessage:
    def __init__(self, start_line: str, headers: Dict[str, str], body: bytes):
        self.start_line = start_line
        self.headers = headers
        self.body = body

class DataProvider:
    def __init__(self):
        self._data = b""

    @property
    def data(self) -&gt; bytes:
        return self._data

    @data.setter
    def data(self, new_data: bytes):
        self._data += new_data

    def reduce_data(self, size: int):
        self._data = self._data[size:]

class HTTPProcessor:
    def __init__(self, data_provider: DataProvider):
        self.data_provider = data_provider

    def get_one_http_message(self) -&gt; Optional[HTTPMessage]:
        try:
            msg, used = HTTPParser.parse_message(self.data_provider.data)
            if msg:
                self.data_provider.reduce_data(used)
            return msg
        except RuntimeError:
            return None

class HTTPSession:
    def __init__(self, conn: socket.socket, addr: Tuple[str, int]):
        self.connection = conn
        self.addr = addr
        self.data_provider = DataProvider()
        self.http_processor = HTTPProcessor(self.data_provider)
        self.active = True

    def handle(self):
        print(f"Connected by {self.addr}")
        while self.active:
            data = self.connection.recv(1024)
            if not data:
                break
            self.data_provider.data = data

            while request := self.http_processor.get_one_http_message():
                uri = request.start_line.split(" ")[1][1:] or "index.html"
                if uri == "favicon.ico":
                    continue
                try:
                    with open(uri) as f:
                        content = f.read().encode()
                        headers = (
                            "HTTP/1.1 200 OK\r\n"
                            f"Content-Length: {len(content)}\r\n"
                            "Content-Type: text/plain\r\n"
                        )
                        if 'keep-alive' in request.headers.get('connection', ''):
                            headers += "Connection: keep-alive\r\n"
                        else:
                            self.active = False
                        headers += "\r\n"
                        self.connection.sendall(headers.encode() + content)
                except Exception:
                    msg = b"404 Not Found"
                    headers = (
                        "HTTP/1.1 404 Not Found\r\n"
                        f"Content-Length: {len(msg)}\r\n"
                        "Content-Type: text/plain\r\n\r\n"
                    )
                    self.connection.sendall(headers.encode() + msg)
        self.connection.close()

class Server:
    def __init__(self, host: str = "", port: int = 8080):
        self.HOST = host
        self.PORT = port

    def start_server(self):
        with socket.socket() as s:
            s.bind((self.HOST, self.PORT))
            s.listen()
            print(f"Server is listening on port {self.PORT}")
            while True:
                conn, addr = s.accept()
                session = HTTPSession(conn, addr)
                session.handle()

if __name__ == '__main__':
    Server().start_server()
</code></code></pre><div><hr></div><h2><strong>&#128295; Adding Configuration Support with NGINX-style Routing</strong></h2><p>At this point, our server is fully functional: it handles TCP sockets, parses HTTP messages, supports keep-alive connections, and even serves files based on URI. But &#8212; there&#8217;s one big thing missing.</p><p>We want the server behavior to be <strong>configurable</strong>.</p><p>In the previous part of this series, we built a configuration parser inspired by how NGINX works. Now it&#8217;s time to <strong>plug that logic into our actual server</strong>.</p><p>To do that, we&#8217;ll:</p><ul><li><p>Use the config to define the <strong>listening port</strong></p></li><li><p>Use NGINX-like server and location blocks to define <strong>route-to-file mappings</strong></p></li><li><p>Build a simplified <strong>route matcher</strong> that selects the correct root for each request</p></li></ul><p>Let&#8217;s first understand how route matching in NGINX actually works.</p><div><hr></div><h2><strong>&#129517; How Route Matching Works (NGINX-style)</strong></h2><p>In NGINX, route matching follows a <strong>block-based, hierarchical structure</strong> using server and location directives. These define which traffic goes where, and what content to serve.</p><h3><strong>&#128270; Matching Steps</strong></h3><ol><li><p><strong>Match the server block</strong>:</p><ul><li><p>The request is routed to the server block matching the listening port.</p></li></ul></li><li><p><strong>Match a location inside that server</strong>:</p><ul><li><p>All location blocks are compared to the request URI.</p></li><li><p><strong>Each location uses prefix matching</strong> &#8212; does the URI start with this prefix?</p></li><li><p>Out of all matching locations, we select <strong>only one</strong>: the <strong>longest matching prefix</strong>.</p></li></ul></li><li><p><strong>Determine the root directory</strong> for this location.</p></li><li><p><strong>Build the full path</strong> by combining the root and the <strong>entire original URI</strong>.</p></li></ol><div><hr></div><h3><strong>&#129504; Example: Longest Prefix Matching</strong></h3><p>Let&#8217;s say we have this config:<br></p><pre><code><code>server {
    listen 8080;

    location / {
        root html;
    }

    location /docs/ {
        root docs;
    }

    location /docs/tutorials/ {
        root tutorials;
    }
}
</code></code></pre><p>Now the request comes in:<br></p><pre><code><code>GET /docs/tutorials/python.html HTTP/1.1
</code></code></pre><p>All of these location blocks match the URI prefix:</p><ul><li><p>/ &#8594; matches everything</p></li><li><p>/docs/ &#8594; matches /docs/tutorials/python.html</p></li><li><p>/docs/tutorials/ &#8594; matches /docs/tutorials/python.html</p></li></ul><p>So what do we choose?</p><p>&#9989; <strong>Only /docs/tutorials/</strong>, because it is the <strong>longest matching prefix</strong>.</p><p>This is how NGINX works: multiple matches are fine, but <strong>only the most specific one wins</strong>.</p><p>Final path to serve:<br></p><pre><code><code>tutorials/docs/tutorials/python.html
</code></code></pre><p>Yes, it includes the full URI even if it overlaps &#8212; NGINX does that unless alias is used (we&#8217;re following the default root behavior here).</p><div><hr></div><h3><strong>&#129504; Summary</strong></h3><ul><li><p>You can match multiple location blocks, but only the longest match matters.</p></li><li><p>This gives us a <strong>clean priority system</strong>.</p></li><li><p>We&#8217;ll replicate this logic using a RouteMatcher helper class.</p></li></ul><p>Let&#8217;s now implement this routing logic in Python, connect it to our server, and make it driven by the config file we previously built.</p><h2><strong>&#128187; Full Server Implementation (With Config + NGINX-Style Routing)</strong></h2><pre><code><code>import socket
from typing import Tuple, Optional, Dict
from config_parser import load_config, ServerConfig  # Your config parser from previous part
from http_parser import HTTPParser, HTTPMessage  # Your existing HTTP parser

# -------------------------
# Route Matching Logic
# -------------------------

class RouteMatcher:
    """
    Selects the server block based on port and matches location blocks using longest URI prefix.
    """
    @staticmethod
    def match_location(locations, uri: str):
        """
        Finds the location block with the longest prefix match.
        """
        matched_location = None
        longest_prefix = -1
        for path, root_dir in locations.items():
            if uri.startswith(path) and len(path) &gt; longest_prefix:
                matched_location = root_dir
                longest_prefix = len(path)
        return matched_location

# -------------------------
# Data Buffer
# -------------------------

class DataProvider:
    """
    A simple buffer that accumulates received data and lets us consume it safely.
    """
    def __init__(self):
        self._data = b""

    @property
    def data(self) -&gt; bytes:
        return self._data

    @data.setter
    def data(self, chunk: bytes):
        self._data += chunk

    def reduce_data(self, size: int):
        self._data = self._data[size:]

# -------------------------
# Message Processor
# -------------------------

class HTTPProcessor:
    """
    Handles parsing of buffered data into HTTPMessage objects.
    """
    def __init__(self, data_provider: DataProvider):
        self.data_provider = data_provider

    def get_one_http_message(self) -&gt; Optional[HTTPMessage]:
        try:
            message, consumed = HTTPParser.parse_message(self.data_provider.data)
            if message:
                self.data_provider.reduce_data(consumed)
            return message
        except Exception:
            return None

# -------------------------
# Client Connection Session
# -------------------------

class HTTPSession:
    """
    Handles the lifecycle of a single HTTP connection.
    """
    def __init__(
        self,
        connection: socket.socket,
        client_address: Tuple[str, int],
        port: int,
        server_config: ServerConfig,
    ):
        self.connection = connection
        self.addr = client_address
        self.data_provider = DataProvider()
        self.http_processor = HTTPProcessor(self.data_provider)
        self.port = port
        self.server_config = server_config
        self.active = True

    def handle(self):
        print(f"[Session] Connected from {self.addr}")
        while self.active:
            data = self.connection.recv(1024)
            if not data:
                break

            self.data_provider.data = data

            while request := self.http_processor.get_one_http_message():
                url = request.url
                root = 'html'  # Default root directory
                if url == "/":
                    url = "/index.html"
                else:
                    # Get root path
                    root = RouteMatcher.match_location(self.server_config.routes[self.port], url)

                file_path = f"{root}{url}"
                print(f"[Request] {url} =&gt; {file_path}")

                try:
                    with open(file_path, "rb") as f:
                        body = f.read()
                    headers = (
                        "HTTP/1.1 200 OK\r\n"
                        f"Content-Length: {len(body)}\r\n"
                        "Content-Type: text/plain\r\n"
                    )
                    if "keep-alive" in request.headers.get("connection", "").lower():
                        headers += "Connection: keep-alive\r\n"
                    else:
                        self.active = False
                    headers += "\r\n"
                    self.connection.sendall(headers.encode() + body)
                except Exception as e:
                    print(f"[Error] {e}")
                    self._send_404()

        self.connection.close()

    def _send_404(self):
        msg = b"404 Not Found"
        headers = (
            "HTTP/1.1 404 Not Found\r\n"
            f"Content-Length: {len(msg)}\r\n"
            "Content-Type: text/plain\r\n\r\n"
        )
        self.connection.sendall(headers.encode() + msg)

# -------------------------
# Server Entrypoint
# -------------------------

class Server:
    """
    Main server class. Reads config, binds to the correct port, and handles requests.
    """
    def __init__(self, config_path: str):
        self.config = load_config(config_path)

    def start(self):
        port = self.config.listen_ports[0]
        with socket.socket() as s:
            s.bind(("", port))
            s.listen()
            print(f"[Server] Listening on port {port}")
            while True:
                conn, addr = s.accept()
                session = HTTPSession(conn, addr, port, self.config)
                session.handle()

# -------------------------
# Start Server
# -------------------------

if __name__ == "__main__":
    server = Server("config.conf")
    server.start()
</code></code></pre><p>Full version is here: <a href="https://github.com/DmytroHuzz/build_own_webserver/blob/main/server_v1.py">https://github.com/DmytroHuzz/build_own_webserver/blob/main/server_v1.py</a></p><div><hr></div><h3><strong>&#9989; Summary</strong></h3><ul><li><p>&#129517; We now support <strong>NGINX-style routing</strong> with longest prefix matching</p></li><li><p>&#9881;&#65039; Server behaviuor is <strong>fully configurable</strong> via config.conf</p></li><li><p>&#128450; Each request is matched to a location block and served from its root</p></li><li><p>&#129504; All logic is split into clean, beginner-friendly classes</p></li></ul><h2><strong>&#128202; Benchmark Results (All 4 Scenarios)</strong></h2><p><strong>#:</strong> 1<br><strong>Scenario:</strong> Single request, no keep-alive<br><strong>Command:</strong> ab -n 100000<br><strong>Requests/sec:</strong> 10308.65<br><strong>Time:</strong> 9.701</p><p><strong>#:</strong> 2<br><strong>Scenario:</strong> Single request, keep-alive<br><strong>Command:</strong> ab -n 100000 -k<br><strong>Requests/sec:</strong> 19351.89<br><strong>Time:</strong> 5.167</p><p><strong>#:</strong> 3<br><strong>Scenario:</strong> Concurrent (50x), no keep-alive<br><strong>Command:</strong> ab -n 100000 -c 50<br><strong>Requests/sec:</strong> 22733.18<br><strong>Time:</strong> 4.399</p><p><strong>#:</strong> 4<br><strong>Scenario:</strong> Concurrent (50x), with keep-alive<br><strong>Command:</strong> ab -n 100000 -c 50 -k<br><strong>Requests/sec:</strong> &#10060; Crashed<br><strong>Time:</strong> &#8212;</p><div><hr></div><h2><strong>&#128269; Benchmark Takeaways</strong></h2><ul><li><p>Adding keep-alive nearly <strong>doubles performance</strong> in single-client tests</p></li><li><p>Concurrent clients improve speed &#8212; until the server crashes on concurrent keep-alive (recv() + blocking)</p></li><li><p>We <strong>need threading</strong> to support parallel persistent clients &#8212; coming next!</p></li></ul><div><hr></div><h2><strong>&#129525; Multithreaded Server &#8212; Make It Scalable</strong></h2><p>We already built a functional server &#8212; it listens, accepts connections, parses requests, and sends responses. But there&#8217;s still a serious limitation: it&#8217;s <strong>single-threaded</strong>.</p><p>If one client connects and <strong>keeps the connection open</strong> (which browsers often do with keep-alive), our server gets stuck. It can&#8217;t accept or serve any new requests until that one client is done.</p><p>And here comes the fix: <strong>threads</strong>.</p><div><hr></div><h2><strong>&#129504; Why Threads?</strong></h2><p>Let&#8217;s pause here and make something very clear. Threads are one of the simplest tools in programming that allow us to <strong>handle multiple tasks at the same time</strong> &#8212; or more precisely, to <strong>interleave work</strong> so that one task doesn&#8217;t block everything else.</p><p>In the context of our web server, here&#8217;s the core issue:</p><blockquote><p>If we use only</p><p><strong>one thread</strong></p></blockquote><p>This happens because of this function:<br></p><pre><code><code>received_data = connection.recv(1024)
</code></code></pre><p>recv() is a <strong>blocking call</strong> &#8212; meaning it will stop everything and wait until data arrives from the client. If no data comes, we sit there doing nothing. That&#8217;s okay for a toy server, but completely unacceptable in real-world scenarios.</p><p>So how do we fix it?</p><div><hr></div><h3><strong>&#128260; Introducing Threads</strong></h3><p>A <strong>thread</strong> is a lightweight execution unit &#8212; like a mini-program inside your main program. With threads, you can <strong>let one thread wait on a blocking call</strong> like recv(), while the main thread (or other threads) <strong>continue doing useful work</strong>.</p><p>In our case:</p><ul><li><p>Main thread listens for new connections</p></li><li><p>Every client connection is handled in its <strong>own thread</strong></p></li><li><p>So if one client stalls, it affects <strong>only its own thread</strong>, not the others</p></li></ul><p>Simple, powerful.</p><div><hr></div><h3><strong>&#128013; But Wait &#8212; What About Python&#8217;s GIL?</strong></h3><p>Yes, let&#8217;s talk about that.</p><p>Python (specifically CPython, the most common interpreter) has something called the <strong>Global Interpreter Lock (GIL)</strong>. The GIL makes sure that <strong>only one thread executes Python bytecode at a time</strong>, even on multi-core CPUs.</p><p>Sounds bad, right?</p><p>&#129504; Not always. Because when a thread <strong>waits on I/O</strong>, like reading from a socket or a file, Python <strong>releases the GIL</strong> temporarily. That means <strong>other threads can run during that time</strong>.</p><p>So even though Python threads aren&#8217;t great for CPU-heavy tasks (like math, AI, or video processing), they are <strong>very effective for I/O-bound programs</strong> &#8212; like our web server, where most time is spent waiting for users or reading files.</p><div><hr></div><h3><strong>&#9878;&#65039; Summary: Threads in Our Web Server</strong></h3><ul><li><p>Without threads: One slow client can freeze the entire server</p></li><li><p>With threads: Each client is isolated in its own thread</p></li><li><p>Blocking functions like recv() no longer harm the whole server</p></li><li><p>Python&#8217;s GIL does <strong>not</strong> prevent this from working, because I/O releases it</p></li><li><p>Threads are easy to use and scale okay up to a point (until you need async/event loops)</p></li></ul><div><hr></div><h2><strong>&#129517; Pseudocode: Multithreaded Server</strong></h2><p>To visualize how this version of the server works, let&#8217;s outline the flow in a simplified pseudocode diagram:<br></p><pre><code><code>+----------------------------+
| Main Thread               |
|---------------------------|
| 1. Listen on a port       |
| 2. Accept connection      |
| 3. Start new thread       |
| 4. Pass connection to it  |
+----------------------------+
            |
            v
  +-------------------------+
  | Per-Client Thread       |
  |-------------------------|
  | 1. Receive data         |
  | 2. Parse request        |
  | 3. Send response        |
  | 4. Close (or keep alive)|
  +-------------------------+
</code></code></pre><div><hr></div><h2><strong>&#128187; Python Implementation (Threaded Version)</strong></h2><p>Let&#8217;s now implement this idea in code. Below is the full server logic, adapted to support multithreading. Each client is handled in a separate thread. This avoids blocking the main thread and enables our server to handle multiple users simultaneously.</p><p>All classes are commented and kept minimal for clarity.<br></p><pre><code><code>import socket
from typing import Tuple, Optional, Dict
from config_parser import load_config, ServerConfig  # Your config parser from previous part
from http_parser import HTTPParser, HTTPMessage  # Your existing HTTP parser
from threading import Thread

# -------------------------
# Route Matching Logic
# -------------------------

class RouteMatcher:
    """
    Selects the server block based on port and matches location blocks using longest URI prefix.
    """
    @staticmethod
    def match_location(locations, uri: str):
        """
        Finds the location block with the longest prefix match.
        """
        matched_location = None
        longest_prefix = -1
        for path, root_dir in locations.items():
            if uri.startswith(path) and len(path) &gt; longest_prefix:
                matched_location = root_dir
                longest_prefix = len(path)
        return matched_location

# -------------------------
# Data Buffer
# -------------------------

class DataProvider:
    """
    A simple buffer that accumulates received data and lets us consume it safely.
    """
    def __init__(self):
        self._data = b""

    @property
    def data(self) -&gt; bytes:
        return self._data

    @data.setter
    def data(self, chunk: bytes):
        self._data += chunk

    def reduce_data(self, size: int):
        self._data = self._data[size:]

# -------------------------
# Message Processor
# -------------------------

class HTTPProcessor:
    """
    Handles parsing of buffered data into HTTPMessage objects.
    """
    def __init__(self, data_provider: DataProvider):
        self.data_provider = data_provider

    def get_one_http_message(self) -&gt; Optional[HTTPMessage]:
        try:
            message, consumed = HTTPParser.parse_message(self.data_provider.data)
            if message:
                self.data_provider.reduce_data(consumed)
            return message
        except Exception:
            return None

# -------------------------
# Client Connection Session
# -------------------------

class HTTPSession:
    """
    Handles the lifecycle of a single HTTP connection.
    """
    def __init__(
        self,
        connection: socket.socket,
        client_address: Tuple[str, int],
        port: int,
        server_config: ServerConfig,
    ):
        self.connection = connection
        self.addr = client_address
        self.data_provider = DataProvider()
        self.http_processor = HTTPProcessor(self.data_provider)
        self.port = port
        self.server_config = server_config
        self.active = True

    def handle(self):
        print(f"[Session] Connected from {self.addr}")
        while self.active:
            data = self.connection.recv(1024)
            if not data:
                break

            self.data_provider.data = data

            while request := self.http_processor.get_one_http_message():
                url = request.url
                root = 'html'  # Default root directory
                if url == "/":
                    url = "/index.html"
                else:
                    # Get root path
                    root = RouteMatcher.match_location(self.server_config.routes[self.port], url)

                file_path = f"{root}{url}"
                print(f"[Request] {url} =&gt; {file_path}")

                try:
                    with open(file_path, "rb") as f:
                        body = f.read()
                    headers = (
                        "HTTP/1.1 200 OK\r\n"
                        f"Content-Length: {len(body)}\r\n"
                        "Content-Type: text/plain\r\n"
                    )
                    if "keep-alive" in request.headers.get("connection", "").lower():
                        headers += "Connection: keep-alive\r\n"
                    else:
                        self.active = False
                    headers += "\r\n"
                    self.connection.sendall(headers.encode() + body)
                except Exception as e:
                    print(f"[Error] {e}")
                    self._send_404()

        self.connection.close()

    def _send_404(self):
        msg = b"404 Not Found"
        headers = (
            "HTTP/1.1 404 Not Found\r\n"
            f"Content-Length: {len(msg)}\r\n"
            "Content-Type: text/plain\r\n\r\n"
        )
        self.connection.sendall(headers.encode() + msg)

# -------------------------
# Server Entrypoint
# -------------------------

class Server:
    """
    Main server class. Reads config, binds to the correct port, and handles requests.
    """
    def __init__(self, config_path: str):
        self.config = load_config(config_path)

    def start(self):
        port = self.config.listen_ports[0]
        with socket.socket() as s:
            s.bind(("", port))
            s.listen()
            print(f"[Server] Listening on port {port}")
            while True:
                conn, addr = s.accept()
                session = HTTPSession(conn, addr, port, self.config)
                thread = Thread(target=session.handle, daemon=True)
                thread.start()

# -------------------------
# Start Server
# -------------------------

if __name__ == "__main__":
    server = Server("config.conf")
    server.start()
</code></code></pre><p>Full version: <a href="https://github.com/DmytroHuzz/build_own_webserver/blob/main/server_v2.py">https://github.com/DmytroHuzz/build_own_webserver/blob/main/server_v2.py</a></p><div><hr></div><h2><strong>&#128202; Benchmarks &amp; Performance Analysis</strong></h2><p>Here are your benchmark results using ab (ApacheBench):</p><p><strong>#:</strong> 1<br><strong>Scenario:</strong> Single client<br><strong>Command:</strong> ab -n 100000<br><strong>Concurrency:</strong> 1<br><strong>Keep-Alive:</strong> &#10060;<br><strong>Requests/sec:</strong> 7871.07<br><strong>Time:</strong> 12.705</p><p><strong>#:</strong> 2<br><strong>Scenario:</strong> Single client + Keep-Alive<br><strong>Command:</strong> ab -n 100000 -k<br><strong>Concurrency:</strong> 1<br><strong>Keep-Alive:</strong> &#9989;<br><strong>Requests/sec:</strong> 19139.16<br><strong>Time:</strong> 5.225</p><p><strong>#:</strong> 3<br><strong>Scenario:</strong> 50 concurrent clients<br><strong>Command:</strong> ab -n 100000 -c 50<br><strong>Concurrency:</strong> 50<br><strong>Keep-Alive:</strong> &#10060;<br><strong>Requests/sec:</strong> 7182.58<br><strong>Time:</strong> 13.923</p><p><strong>#:</strong> 4<br><strong>Scenario:</strong> 50 concurrent + Keep-Alive<br><strong>Command:</strong> ab -n 100000 -c 50 -k<br><strong>Concurrency:</strong> 50<br><strong>Keep-Alive:</strong> &#9989;<br><strong>Requests/sec:</strong> 13777.80<br><strong>Time:</strong> 7.258</p><div><hr></div><h2><strong>&#128202; Blocking vs Multithreaded Server &#8212; Performance Comparison</strong></h2><p>Now that we&#8217;ve implemented both a blocking (single-threaded) server and a multithreaded version, let&#8217;s compare how they behave under different real-world usage patterns using ApacheBench.</p><p><strong>#:</strong> 1<br><strong>Scenario:</strong> Single client, no keep-alive<br><strong>Command:</strong> ab -n 100000<br><strong>Concurrency:</strong> 1<br><strong>Keep-Alive:</strong> &#10060;<br><strong>Blocking Server:</strong> 10308.65 req/sec<br><strong>Multithreaded Server:</strong> 7871.07 req/sec</p><p><strong>#:</strong> 2<br><strong>Scenario:</strong> Single client, keep-alive<br><strong>Command:</strong> ab -n 100000 -k<br><strong>Concurrency:</strong> 1<br><strong>Keep-Alive:</strong> &#9989;<br><strong>Blocking Server:</strong> 19351.89 req/sec<br><strong>Multithreaded Server:</strong> 19139.16 req/sec</p><p><strong>#:</strong> 3<br><strong>Scenario:</strong> 50 clients, no keep-alive<br><strong>Command:</strong> ab -n 100000 -c 50<br><strong>Concurrency:</strong> 50<br><strong>Keep-Alive:</strong> &#10060;<br><strong>Blocking Server:</strong> 22733.18 req/sec<br><strong>Multithreaded Server:</strong> 7182.58 req/sec</p><p><strong>#:</strong> 4<br><strong>Scenario:</strong> 50 clients, keep-alive<br><strong>Command:</strong> ab -n 100000 -c 50 -k<br><strong>Concurrency:</strong> 50<br><strong>Keep-Alive:</strong> &#9989;<br><strong>Blocking Server:</strong> &#10060; Crashed<br><strong>Multithreaded Server:</strong> 13777.80 req/sec</p><div><hr></div><h3><strong>&#129504; Analysis</strong></h3><ul><li><p>&#9989; <strong>Multithreaded server handles concurrency correctly</strong>: it doesn&#8217;t crash or stall with multiple clients.</p></li><li><p>&#129525; <strong>Thread overhead exists</strong>: single-thread performance slightly drops due to thread management.</p></li><li><p>&#128293; <strong>Keep-Alive is a huge win</strong> for both versions &#8212; especially in single-client scenarios.</p></li><li><p>&#10060; The blocking server simply <strong>cannot scale</strong> with concurrency &#8212; it either stalls or crashes.</p></li></ul><div><hr></div><h3><strong>&#128172; Final Thoughts</strong></h3><ul><li><p>The <strong>blocking server</strong> is great for understanding the basics but unusable beyond a single request at a time.</p></li><li><p>The <strong>multithreaded server</strong> is a practical step toward a real web server: it supports multiple clients, concurrent connections, and persistent TCP streams.</p></li><li><p>But we&#8217;re still not done &#8212; with many threads, we&#8217;ll eventually hit memory and scheduling limits.</p></li></ul><p>&#129517; In the next part <a href="https://www.softwareinthegrid.com/p/051d629f-b465-4f38-95db-987ea8c412ae">next part</a>, we&#8217;ll move to <strong>non-blocking I/O</strong> and event-driven architecture &#8212; the kind of foundation used by NGINX, Node.js, and other modern high-performance servers.</p><p><a href="https://www.softwareinthegrid.com/p/18c4d9c2-334a-42b4-b412-4a36ae930029">Series hub: Building a Web Server from Scratch</a></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Software in the Grid is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item><item><title><![CDATA[Building Your Own Web Server: Part 2 — Plan and Implementation of HTTP and Configuration parser]]></title><description><![CDATA[This article is part of Software Foundations, where I explore networking, protocols, operating systems, and software systems from first principles.]]></description><link>https://www.softwareinthegrid.com/p/building-your-own-web-server-part-3e0</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/building-your-own-web-server-part-3e0</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Mon, 28 Sep 2026 12:38:28 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!rFDk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6371e093-ee1e-4ee6-80f6-b1a3d6c44a90_1000x421.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rFDk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6371e093-ee1e-4ee6-80f6-b1a3d6c44a90_1000x421.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rFDk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6371e093-ee1e-4ee6-80f6-b1a3d6c44a90_1000x421.webp 424w, https://substackcdn.com/image/fetch/$s_!rFDk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6371e093-ee1e-4ee6-80f6-b1a3d6c44a90_1000x421.webp 848w, https://substackcdn.com/image/fetch/$s_!rFDk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6371e093-ee1e-4ee6-80f6-b1a3d6c44a90_1000x421.webp 1272w, https://substackcdn.com/image/fetch/$s_!rFDk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6371e093-ee1e-4ee6-80f6-b1a3d6c44a90_1000x421.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rFDk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6371e093-ee1e-4ee6-80f6-b1a3d6c44a90_1000x421.webp" width="1000" height="421" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6371e093-ee1e-4ee6-80f6-b1a3d6c44a90_1000x421.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:421,&quot;width&quot;:1000,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:316298,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/217819146?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6371e093-ee1e-4ee6-80f6-b1a3d6c44a90_1000x421.webp&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!rFDk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6371e093-ee1e-4ee6-80f6-b1a3d6c44a90_1000x421.webp 424w, https://substackcdn.com/image/fetch/$s_!rFDk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6371e093-ee1e-4ee6-80f6-b1a3d6c44a90_1000x421.webp 848w, https://substackcdn.com/image/fetch/$s_!rFDk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6371e093-ee1e-4ee6-80f6-b1a3d6c44a90_1000x421.webp 1272w, https://substackcdn.com/image/fetch/$s_!rFDk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6371e093-ee1e-4ee6-80f6-b1a3d6c44a90_1000x421.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>This article is part of Software Foundations, where I explore networking, protocols, operating systems, and software systems from first principles. These foundations support the broader work of <a href="https://www.softwareinthegrid.com/">Software in the Grid</a>.</em></p><h2><strong>All articles in this series</strong></h2><ol><li><p><a href="https://www.softwareinthegrid.com/p/0c55774e-8b08-4ccf-9ebd-470a0d29d0c5">Building Your Own Web Server: Part 1 &#8212; Theory and Foundations</a></p></li><li><p><a href="https://www.softwareinthegrid.com/p/6a23363c-71d3-42e7-bce4-2bdc3931fd60">Building Your Own Web Server: Part 2 &#8212; Plan and Implementation of HTTP and Configuration parser</a></p></li><li><p><a href="https://www.softwareinthegrid.com/p/000b7742-1f55-4e1e-b324-dc91656a4be0">Building Your Own Web Server &#8212; Part 3: Blocking Single and Multithreaded Server</a></p></li><li><p><a href="https://www.softwareinthegrid.com/p/051d629f-b465-4f38-95db-987ea8c412ae">Building Your Own Web Server &#8212; Part 4: Single-threaded non-blocking server</a></p></li></ol><h2><strong>&#128591; Thank You!</strong></h2><p>After the first article, I received a lot of really nice and positive feedback. It was super pleasant for me &#8212; it gave me the feeling that this topic might actually be interesting and useful for many of you, and it gave me huge motivation to continue working on it. Thanks to all of you for such great support! And please keep sharing your feedback and ideas with me &#8212; it helps me improve my work and bring more value for you. &#128521;</p><div><hr></div><h2><strong>&#128221; Preface</strong></h2><p>This is the second article in the &#8220;Building Your Own Web Server&#8221; series. You can find the first one here:</p><p>&#128073; <a href="https://www.softwareinthegrid.com/p/0c55774e-8b08-4ccf-9ebd-470a0d29d0c5">Part 1 &#8212; Theory and Foundation</a></p><p>At the beginning, I thought the best way to move forward would be to start directly with building the actual server: open a socket, handle a connection, receive a message&#8230; and then gradually add more functionality, like parsing HTML or working with a config file and implementing other server&#8217;s approaches. That approach worked well enough, and I was planning to stick with it &#8212; but while working on it, I ran into a problem. The development process quickly became chaotic, less structured, and full of constant rewriting and refactoring. Maybe that&#8217;s fine for a learning exercise, but definitely not for building something solid &#8212; or writing about it in a clean way.</p><p>So I stopped and rethought the structure.</p><p>In the first article, we identified two essential parts of a web server:</p><p><strong>HTTP parsing</strong> and <strong>server configuration</strong>. These are core features we&#8217;ll need no matter what kind of server we build &#8212; and while experimenting with different server architectures (blocking, multithreaded, and single-threaded non-blocking), I realized something:</p><blockquote><p>These two parts stay the same. They don&#8217;t need to change.</p></blockquote><p>That gave me a much better idea: instead of starting with the server, I&#8217;ll start by implementing these two independent services first.</p><p>I really liked this decision. It gives us a strong foundation &#8212; and more importantly, we&#8217;ll have two modular, reusable components that we can use later in every version of the server we build. It also lets us dig deeper into interesting topics like the structure of HTTP messages and a new concept (at least for me): <strong>lexical tokenization</strong>, which is heavily used in compilers.</p><p>And one more thing: in this article, I&#8217;ll also include a quick roadmap &#8212; a kind of overview of what we&#8217;re planning to build in the upcoming parts. That way you&#8217;ll know where we&#8217;re going and how each piece fits in.</p><p>So that&#8217;s it for the preface &#8212; let&#8217;s jump into the implementation. I hope you enjoy the article and that it gives you something useful or at least interesting. &#128522;</p><blockquote><p>&#128279; Full source code is available here:</p><p><a href="https://github.com/DmytroHuzz/build_own_webserver">build_own_webserver</a></p></blockquote><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.softwareinthegrid.com/subscribe?"><span>Subscribe now</span></a></p><div><hr></div><h2><strong>&#128203; Implementation Plan</strong></h2><p>Here&#8217;s what we&#8217;re going to build &#8212; both in this article and the next ones.</p><h3><strong>1. Implement basic services of the web server</strong></h3><p>This article focuses on building two independent and reusable components:</p><ul><li><p>The <strong>HTTP parser</strong></p></li><li><p>The <strong>configuration parser</strong></p></li></ul><h3><strong>2. Implement server v1 and v2: blocking and multithreaded</strong></h3><p>In the next article, we&#8217;ll try to reach the point where we can run the first version of our web server &#8212; a single-threaded, blocking version. We&#8217;ll test its performance, and I&#8217;ll show you what kind of problems appear with a blocking thread. Then we&#8217;ll fix those issues by switching to a multi-threaded approach and see how it affects performance in different cases.</p><h3><strong>3. Implement server v3: I/O multiplexing</strong></h3><p>In the last article, I want to try a different approach &#8212; where a single thread works in a non-blocking way. We&#8217;ll talk about I/O multiplexing, Python&#8217;s selectors module, and how NGINX architecture works.</p><p>At the end, we&#8217;ll build the final version of the server based on this approach &#8212; and check how it performs.</p><p>So&#8230; let&#8217;s go! &#128640;</p><div><hr></div><h2><strong>&#127760; HTTP Parser</strong></h2><p>Obviously, if we want to build a web server, we need something that helps us transform raw HTTP message bytes received from a socket into a structured and readable format. Of course, there are tons of libraries and packages that already do this &#8212; like <a href="https://github.com/python/cpython/blob/main/Lib/http/server.py">http.server</a> in Python. But hey &#8212; why use a ready-made solution when we can build our own? &#128521;</p><p>Let&#8217;s first define what exactly our parser should be responsible for.</p><p>It sounds simple: the parser should be able to receive data and return HTTP data in a structured format. But how should it receive that data? Should it have access to the socket? Or the connection? Should the input be in bytes or in str format?</p><p>These are the kinds of questions that come up when we start writing the implementation. Let&#8217;s break them down one by one &#8212; it&#8217;ll help us better understand what we&#8217;re building and how.</p><div><hr></div><blockquote><p>But how should the parser receive the data? Should it have access to the socket or the connection?</p></blockquote><p>We want to keep our HTTP parser as independent as possible &#8212; that way, it&#8217;s reusable and separated from the server&#8217;s architecture. The server will be responsible for handling sockets and connections, and this logic might be very different depending on whether we&#8217;re using blocking, non-blocking, or async I/O.</p><p>So we don&#8217;t want the parser to depend on that. What we do want is to make sure the <strong>server handles everything related to getting the data</strong>, and the <strong>parser focuses only on parsing that data</strong>.</p><p>That means we want the parser to have one clear responsibility:</p><p>Take raw input data and return a parsed HTTP message.</p><div><hr></div><p>&#9888;&#65039; <strong>Important note:</strong> because of persistent connections, we can&#8217;t guarantee that the data received from the socket will contain a full HTTP message. That&#8217;s why we need to handle this case in our parser. Basically, we shouldn&#8217;t trust the received data blindly &#8212; the parser should try to extract one valid HTTP message from the input.</p><p>Also, in addition to returning the message itself, the parser should return the number of bytes it consumed &#8212; so that the server can know how much of the buffer was handled and how much is left.</p><p>And this answers the last question too:</p><p>We&#8217;ll work with <strong>bytes</strong> instead of strings &#8212; this makes it easier to track how much data we&#8217;ve processed.</p><p>Bellow I will show the code of implementation and provide comments to every interesting step.<br></p><pre><code><code>from typing import Dict, Optional, Tuple

# -----------------------------------------------------------------------------
# Custom exception classes for precise error handling in our HTTP parser.
# -----------------------------------------------------------------------------
class IncompleteMessageError(Exception):
    """
    Raised when the parser determines that the data buffer does not yet
    contain a full HTTP message. Signals to the server: &#8220;this input is
    valid so far, but you need to read more bytes before retrying parse.&#8221;
    """
    pass

class InvalidMessageError(Exception):
    """
    Raised when the parser finds a structural or syntactic problem in the
    data buffer that cannot be fixed by reading more bytes. Signals to the
    server: &#8220;this request is malformed&#8212;respond with an error (e.g. 400 Bad Request).&#8221;
    """
    pass

class HTTPMessage:
    """
    Represents a complete HTTP message (request or response).

    Attributes:
        method:  HTTP method (e.g. 'GET', 'POST') or response status code.
        url:     Request target (e.g. '/index.html') or response reason phrase.
        version: HTTP version (e.g. 'HTTP/1.1').
        headers: dict of header-name (lowercased) &#8594; header-value.
        body:    Raw bytes of the message body.
    """
    def __init__(
        self,
        method: str,
        url: str,
        version: str,
        headers: Dict[str, str],
        body: bytes
    ):
        self.method = method
        self.url = url
        self.version = version
        self.headers = headers
        self.body = body

    def __repr__(self):
        snippet = self.body[:100]  # preview first 100 bytes of body
        return (
            f"HTTPMessage(method={self.method!r}, url={self.url!r}, "
            f"version={self.version!r}, headers={self.headers!r}, "
            f"body={snippet!r}...)"
        )

class HTTPParser:
    """
    A simple HTTP message parser that can extract one message at a time
    from a byte buffer.

    Exceptions:
      - IncompleteMessageError: the buffer is valid so far but incomplete.
      - InvalidMessageError:   the buffer is malformed and cannot be parsed.
    """
    @staticmethod
    def parse_message(data: bytes) -&gt; Tuple[Optional[HTTPMessage], int]:
        """
        Parse exactly one HTTP message from the start of `data`.

        :param data: Bytes that may contain zero, one, or multiple messages.
        :return: A tuple (message, bytes_consumed). If data is empty, (None, 0).
        :raises IncompleteMessageError: headers or body are incomplete.
        :raises InvalidMessageError:    data is syntactically invalid.
        """
        # --- A) Empty buffer: nothing to parse yet.
        if not data:
            return None, 0

        # --- B) Locate end of headers ("\r\n\r\n").
        sep = b"\r\n\r\n"
        idx = data.find(sep)
        if idx == -1:
            # Missing header terminator &#8594; need more data.
            raise IncompleteMessageError(
                "Incomplete headers: missing CRLF CRLF separator."
            )

        # Split header block from potential body.
        header_text = data[:idx].decode("iso-8859-1", errors="replace")
        rest = data[idx + len(sep):]

        # --- C) Break headers into lines.
        lines = header_text.split("\r\n")
        start_line = lines[0]
        header_lines = lines[1:]

        # --- D) Parse start line into method, URL/status, version.
        parts = start_line.split(" ", 2)
        if len(parts) != 3:
            # Syntax error cannot be fixed by more data &#8594; invalid.
            raise InvalidMessageError(f"Malformed start line: {start_line!r}")
        method, url, version = parts

        # --- E) Parse headers into dict.
        headers: Dict[str, str] = {}
        for line in header_lines:
            if not line:
                continue  # skip stray blank lines
            if ":" not in line:
                raise InvalidMessageError(f"Bad header line: {line!r}")
            name, value = line.split(":", 1)
            headers[name.strip().lower()] = value.strip()

        # --- F) Determine body length via Content-Length, if present.
        length_hdr = headers.get("content-length")
        if length_hdr is not None:
            try:
                length = int(length_hdr)
            except ValueError:
                # Non-integer length cannot be corrected &#8594; invalid.
                raise InvalidMessageError(
                    f"Invalid Content-Length value: {length_hdr!r}"
                )
            if len(rest) &lt; length:
                # Not enough data for full body &#8594; incomplete.
                raise IncompleteMessageError(
                    f"Body incomplete: expected {length} bytes, got {len(rest)}."
                )
            body = rest[:length]
            consumed = idx + len(sep) + length
        else:
                # No Content-Length &#8212; assume no body (e.g. for GET, HEAD).
            body = b""
            consumed = idx + len(sep)
        message = HTTPMessage(method, url, version, headers, body)
        return message, consumed
</code></code></pre><p>The final full code of the http parser can be found here: <a href="https://github.com/DmytroHuzz/build_own_webserver/blob/main/http_parser.py">https://github.com/DmytroHuzz/build_own_webserver/blob/main/http_parser.py</a>. Now let&#8217;s move to the second service: the configuration parser.</p><div><hr></div><h2>&#9881;&#65039; Configuration parser</h2><h3>&#128172; Preface</h3><p>At first glance, this part seemed simple &#8212; at least to me. But once I started diving into the world of compilers and interpreters, reading up on parsing techniques, I quickly realized it&#8217;s actually a deep and surprisingly complex topic. Things like lexical analysis and token streams were new to me.</p><p>I started reading docs and searching for guides, but there weren&#8217;t many good explanations of how config parsers work under the hood. So I turned to source code &#8212; specifically, the NGINX source: <a href="https://github.com/nginx/nginx/blob/master/src/core/ngx_conf_file.c">src/core/ngx_conf_file.c</a>. That&#8217;s where I first came across the idea of lexical analysis, which became my starting point.</p><p>From there, with some help from ChatGPT to validate my findings, I pieced things together. What started as a &#8220;simple&#8221; part of the project turned into the most interesting and insightful one for me. Now I want to share what I learned with you &#8212; and I hope it will be just as fun for you to follow.</p><h3>&#129534; Requirements</h3><p>The web server requires to have some part of functionality configurable. To this functionality relate: listening port, rules for routing included URI and resource locations and far more. To implement this requirements Nginx uses configuration file with strictly specific format. Here is possible to read in very details about that format of configuration file in Nginx: <a href="https://nginx.org/en/docs/beginners_guide.html#conf_structure">https://nginx.org/en/docs/beginners_guide.html#conf_structure</a>.</p><p>From the same source we can take the basic description about format of the configuration file:</p><blockquote><p><strong>Configuration File&#8217;s Structure</strong></p><p>nginx consists of modules which are controlled by directives specified in the configuration file. Directives are divided into simple directives and block directives. A simple directive consists of the name and parameters separated by spaces and ends with a semicolon (<code>;</code>). A block directive has the same structure as a simple directive, but instead of the semicolon it ends with a set of additional instructions surrounded by braces (<code>{</code> and <code>}</code>). If a block directive can have other directives inside braces, it is called a context (examples: <a href="https://nginx.org/en/docs/ngx_core_module.html#events">events</a>, <a href="https://nginx.org/en/docs/http/ngx_http_core_module.html#http">http</a>, <a href="https://nginx.org/en/docs/http/ngx_http_core_module.html#server">server</a>, and <a href="https://nginx.org/en/docs/http/ngx_http_core_module.html#location">location</a>).</p><p>Directives placed in the configuration file outside of any contexts are considered to be in the <a href="https://nginx.org/en/docs/ngx_core_module.html">main</a> context. The <code>events</code> and <code>http</code> directives reside in the <code>main</code> context, <code>server</code> in <code>http</code>, and <code>location</code> in <code>server</code>.</p><p>The rest of a line after the <code>#</code> sign is considered a comment.</p></blockquote><p>We will take this description as a specification and will implement the same format. As we agreed in our requirements, we will start simple and implement first serving static files only. At the beginning we will start only with a few basic directives and its configurations.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!VGBq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faad9f89c-67f3-42a2-85cf-e12a6541303d_800x1200.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!VGBq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faad9f89c-67f3-42a2-85cf-e12a6541303d_800x1200.webp 424w, https://substackcdn.com/image/fetch/$s_!VGBq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faad9f89c-67f3-42a2-85cf-e12a6541303d_800x1200.webp 848w, https://substackcdn.com/image/fetch/$s_!VGBq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faad9f89c-67f3-42a2-85cf-e12a6541303d_800x1200.webp 1272w, https://substackcdn.com/image/fetch/$s_!VGBq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faad9f89c-67f3-42a2-85cf-e12a6541303d_800x1200.webp 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!VGBq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faad9f89c-67f3-42a2-85cf-e12a6541303d_800x1200.webp" width="800" height="1200" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/aad9f89c-67f3-42a2-85cf-e12a6541303d_800x1200.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1200,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Conf file structure diagram&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Conf file structure diagram" title="Conf file structure diagram" srcset="https://substackcdn.com/image/fetch/$s_!VGBq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faad9f89c-67f3-42a2-85cf-e12a6541303d_800x1200.webp 424w, https://substackcdn.com/image/fetch/$s_!VGBq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faad9f89c-67f3-42a2-85cf-e12a6541303d_800x1200.webp 848w, https://substackcdn.com/image/fetch/$s_!VGBq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faad9f89c-67f3-42a2-85cf-e12a6541303d_800x1200.webp 1272w, https://substackcdn.com/image/fetch/$s_!VGBq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faad9f89c-67f3-42a2-85cf-e12a6541303d_800x1200.webp 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>We will implement the server directive which is responsible for server&#8217;s settings. And define there next configurations: listen and location. So we can define the port which server should listen and routing rules.<br></p><pre><code><code>http { 
    server {
    listen 8080;

    location / {
        root /data/www;
    }
  }
}
</code></code></pre><p>First of all, we will start with creating a parser for the defined format. And after that we can test the parser with our basic configuration file.</p><div><hr></div><h3><strong>Configuration Parsing, Part 1: Lexer</strong></h3><p>In this part, we&#8217;re going to implement the first step of our configuration parsing system: the <strong>lexer</strong>. But before we dive into code, let&#8217;s clarify how the config parsing process works overall.</p><div><hr></div><h4><strong>1. Overview: Configuration Parsing System</strong></h4><p>Our configuration parser consists of three main parts:</p><ol><li><p><strong>Lexer</strong> &#8211; reads raw configuration text and breaks it into tokens (words, symbols, etc.).</p></li><li><p><strong>Parser</strong> &#8211; takes those tokens and builds a structured, nested configuration.</p></li><li><p><strong>ServerConfig</strong> &#8211; the resulting object that our server code will use to access config values.</p></li></ol><p>This design may seem overkill for a small project, but it has clear benefits:</p><ul><li><p>Each part does one thing and is easy to test.</p></li><li><p>Parsing becomes less error-prone and easier to understand.</p></li><li><p>We follow the same approach real servers like NGINX use, which makes the system more realistic and extensible.</p></li></ul><p>In next part, we&#8217;ll focus on implementing the <strong>lexer</strong>.</p><div><hr></div><h4><strong>2. Lexer Implementation</strong></h4><h5><strong>What Is a Lexer?</strong></h5><p>The lexer (or tokenizer) is the first component that reads the raw config file line by line and splits it into <strong>tokens</strong>.</p><p>For example, this input:<br></p><pre><code><code>server {
  listen 8080;
  location / {
    root /data/www;
  }
}
</code></code></pre><p>Will be split into a sequence of tokens like:<br></p><pre><code><code>WORD(server)
LBRACE({
WORD(listen)
WORD(8080)
SEMICOLON(;)
...
</code></code></pre><h4><strong>Why Do We Need It?</strong></h4><p>While it&#8217;s possible to parse the config text directly, separating the lexer gives us better structure and separation of concerns. The lexer removes irrelevant details (like whitespace or comments) and leaves us with a clean, uniform stream of tokens to work with.</p><p>This makes the parser&#8217;s job significantly easier.</p><div><hr></div><h4><strong>3. Python Implementation</strong></h4><p>Here&#8217;s a simple lexer class that extracts relevant tokens. I tried to add explicit comments to every block of the code, so that it should be clear how it works.<br></p><pre><code><code>import re
from typing import List, Tuple

# Each token is represented as a tuple: (type, value)
Token = Tuple[str, str]

class SimpleConfigLexer:
    """
    A basic lexer for NGINX-style config files.
    It recognizes:
    - comments (starting with #)
    - symbols: { } ;
    - quoted strings
    - plain words: directives, numbers, paths
    """

    TOKEN_PATTERNS = [
        ("COMMENT", r"#.*"),
        ("LBRACE", r"\{"),
        ("RBRACE", r"\}"),
        ("SEMICOLON", r";"),
        ("STRING", r'"[^"]*"'),
        ("WORD", r"[a-zA-Z0-9_./\-]+"),
        ("WHITESPACE", r"[ \t\r\n]+"),
    ]

    def __init__(self, config_text: str):
        self.config_text = config_text
        self.tokens = self.tokenize()

    def tokenize(self) -&gt; List[Token]:
        pattern = "|".join(f"(?P&lt;{name}&gt;{regex})" for name, regex in self.TOKEN_PATTERNS)
        token_re = re.compile(pattern)

        pos = 0
        tokens: List[Token] = []

        while pos &lt; len(self.config_text):
            match = token_re.match(self.config_text, pos)
            if not match:
                raise SyntaxError(f"Unexpected character at position {pos}: {self.config_text[pos]!r}")

            kind = match.lastgroup
            value = match.group()

            if kind in ("WHITESPACE", "COMMENT"):
                pass  # skip it
            elif kind == "STRING":
                tokens.append((kind, value.strip('"')))  # remove quotes
            else:
                tokens.append((kind, value))

            pos = match.end()

        return tokens
</code></code></pre><div><hr></div><h4><strong>4. Testing the Lexer</strong></h4><p>Let&#8217;s run a quick test to see how it works.<br></p><pre><code><code>config_text = '''
server {
  listen 8080;
  location / {
    root /var/www;
  }
}
'''

lexer = SimpleConfigLexer(config_text)

for token_type, value in lexer.tokens:
    print(f"{token_type:&lt;10} -&gt; {value}")
</code></code></pre><p><strong>Output:</strong><br></p><pre><code><code>WORD       -&gt; server
LBRACE     -&gt; {
WORD       -&gt; listen
WORD       -&gt; 8080
SEMICOLON  -&gt; ;
WORD       -&gt; location
WORD       -&gt; /
LBRACE     -&gt; {
WORD       -&gt; root
WORD       -&gt; /var/www
SEMICOLON  -&gt; ;
RBRACE     -&gt; }
RBRACE     -&gt; }
</code></code></pre><div><hr></div><h4><strong>5. Optional: Visualizing the Token Stream</strong></h4><p>Here&#8217;s a simple helper function to visualize the nesting structure. It doesn&#8217;t parse the config yet, but it gives us a good idea of where blocks open and close.<br></p><pre><code><code>def visualize_token_stream(tokens: List[Token]) -&gt; None:
    indent = 0
    for token_type, value in tokens:
        if token_type == "RBRACE":
            indent -= 1
        print("  " * indent + f"{token_type:10}: {value}")
        if token_type == "LBRACE":
            indent += 1
</code></code></pre><p><strong>Example output:</strong><br></p><pre><code><code>WORD      : server
LBRACE    : {
  WORD      : listen
  WORD      : 8080
  SEMICOLON : ;
  WORD      : location
  WORD      : /
  LBRACE    : {
    WORD      : root
    WORD      : /var/www
    SEMICOLON : ;
  RBRACE    : }
RBRACE    : }
</code></code></pre><p>This shows block structure in a readable way without needing a full parser yet.</p><div><hr></div><h3>&#128736; Configuration Parsing, Part 2: Parser</h3><p>We now have a working lexer, which takes a raw config file and splits it into a list of tokens. Now we&#8217;ll implement the parser &#8212; the part that takes that token stream and transforms it into a structured object the server can actually use.</p><div><hr></div><h4>1. What the Parser Does</h4><p>The parser takes a flat list of tokens and builds a <strong>nested configuration tree</strong> based on blocks and directives.</p><p>Example config:<br></p><pre><code><code>http {
  server {
    listen 8080;
    location / {
      root /data/www;
    }
  }
}

</code></code></pre><p>The parser will convert this into something like:<br></p><pre><code><code>{
  "http": {
    "server": {
      "listen": "8080",
      "location": {
        "/": {
          "root": "/data/www"
        }
      }
    }
  }
}

</code></code></pre><p>This structure will later be used to create a <code>ServerConfig</code> object or whatever internal structure we want.</p><div><hr></div><h4>2. How the Parser Works (Conceptual Overview)</h4><p>The parser uses a technique called <strong>recursive descent</strong>. It walks through the list of tokens one by one, and:</p><ul><li><p>When it sees a key followed by <code>{</code>, it knows it&#8217;s starting a <strong>block</strong>, and calls itself recursively to parse that block.</p></li><li><p>When it sees a key followed by one or more values and then <code>;</code>, it stores them as a <strong>directive</strong>.</p></li><li><p>When it sees arguments before <code>{</code>, it understands it&#8217;s a <strong>block with arguments</strong> (e.g., <code>location / {</code>).</p></li></ul><blockquote><p><strong>Note</strong> on context validation: This parser is designed for educational clarity and intentionally does <strong>not.</strong> While real-world servers like NGINX enforce these rules, we chose to skip this complexity here to focus on the core parsing logic.</p></blockquote><div><hr></div><p>Here&#8217;s a visual breakdown:<br></p><pre><code><code>[WORD] &#8594; key
  |
  |-- [WORD] + [LBRACE] &#8594; block with arguments
  |     &#8594; assign key: { arg: { nested config } }
  |
  |-- [LBRACE] &#8594; block without arguments
  |     &#8594; assign key: { nested config }
  |
  |-- [WORD(s)] + SEMICOLON &#8594; directive
        &#8594; assign key: value or list of values

</code></code></pre><blockquote><p><strong>Note:</strong> While our parser technically supports blocks with multiple arguments (like <code>WORD WORD WORD {</code>), such constructs are <strong>not valid in real NGINX configurations</strong>. To stay faithful to NGINX-style syntax, we assume that a block can have <strong>at most one argument</strong> (e.g., <code>location / {</code>). You can easily enforce this by validating the number of arguments if needed.</p><div><hr></div></blockquote><h4>3. Parser Implementation (Step-by-Step)</h4><p>Now we&#8217;re getting into the core part of the parser. I know &#8212; at first glance, the code might look long or even a bit intimidating. But don&#8217;t worry. I encourage you to take your time and walk through it slowly.</p><p>I&#8217;ve added detailed comments throughout the code to make each part as clear as possible. If something still feels confusing or unclear, feel free to ask questions in the comments &#8212; I&#8217;ll do my best to explain or improve it further.</p><p>And if you still feel a bit lost, that&#8217;s okay too. You can treat this parser as a black box for now &#8212; understanding the overall idea is enough to follow the rest of the article. The full implementation is here mostly for those who want to dig into the internals.<br></p><pre><code><code>from typing import List, Tuple, Union

# A token is a pair: (type, value), e.g. ("WORD", "listen")
Token = Tuple[str, str]

# The parsed config will be a nested dictionary structure
ConfigDict = dict[str, Union[str, "ConfigDict", list]]

class SimpleConfigParser:
    """
    Parses a list of tokens into a nested configuration dictionary.

    This parser assumes a simplified NGINX-style format where:
    - Each line is either a directive (ends with ';') or a block (enclosed in { ... }).
    - Blocks can be nested.
    - Blocks may take one argument (e.g. 'location / { ... }').
    """

    def __init__(self, tokens: List[Token]):
        self.tokens = tokens
        self.pos = 0  # keeps track of which token we're currently parsing

    def parse(self) -&gt; ConfigDict:
        """
        Entry point: parse the full list of tokens and return a nested dictionary.
        This handles the top-level of the configuration (e.g., the main context).
        """
        return self._parse_block()

    def _parse_block(self) -&gt; ConfigDict:
        """
        Parses a block of configuration. This is a recursive function:
        - Called when entering a new { ... } block.
        - Returns a dictionary representing the contents of that block.
        """
        config: ConfigDict = {}

        while self.pos &lt; len(self.tokens):
            token_type, token_value = self.tokens[self.pos]

            # If we reach a closing brace, it means the current block is finished.
            if token_type == "RBRACE":
                self.pos += 1  # consume the '}'
                return config

            # Each line must start with a directive or block name (a WORD).
            if token_type != "WORD":
                raise SyntaxError(f"Expected directive name (WORD), but got {token_type} '{token_value}'")

            # Save the directive or block name.
            key = token_value
            self.pos += 1  # move to the next token

            args = []  # used to collect parameters like '8080' or '/'

            # Now we gather the rest of the tokens for this line,
            # which will be either:
            # - a list of arguments followed by a SEMICOLON (simple directive),
            # - or a list of arguments followed by LBRACE (start of a nested block).
            while self.pos &lt; len(self.tokens):
                t_type, t_value = self.tokens[self.pos]

                if t_type == "LBRACE":
                    # We&#8217;ve found a new block. This is something like:
                    # location / { ... }
                    if len(args) &gt; 1:
                        raise SyntaxError(f"Block '{key}' can only have one argument. Found: {args}")

                    self.pos += 1  # consume the '{'
                    block = self._parse_block()  # recursively parse what's inside

                    if args:
                        # Example: location / { ... }
                        # We treat 'location' as the key and '/' as a subkey.
                        arg_key = args[0]
                        if key not in config:
                            config[key] = {}
                        if not isinstance(config[key], dict):
                            raise SyntaxError(f"Cannot nest block under non-dictionary directive '{key}'")
                        config[key][arg_key] = block
                    else:
                        # Example: server { ... }
                        # If there are multiple server blocks, store them as a list.
                        if key in config:
                            if isinstance(config[key], list):
                                config[key].append(block)
                            else:
                                config[key] = [config[key], block]
                        else:
                            config[key] = block
                    break  # done processing this block directive

                elif t_type == "SEMICOLON":
                    # We've reached the end of a simple directive like:
                    # listen 8080;
                    self.pos += 1  # consume the ';'
                    value = args[0] if len(args) == 1 else args

                    # If the same directive appears multiple times, store values in a list.
                    if key in config:
                        if isinstance(config[key], list):
                            config[key].append(value)
                        else:
                            config[key] = [config[key], value]
                    else:
                        config[key] = value
                    break  # done processing this simple directive

                elif t_type != "WORD":
                    # We only expect WORDs as arguments before we hit '{' or ';'
                    raise SyntaxError(f"Unexpected token in argument list: {t_type} '{t_value}'")

                else:
                    # This is an argument &#8212; e.g., the '8080' in `listen 8080;`
                    args.append(t_value)
                    self.pos += 1

            # If we exited the loop without encountering RBRACE (in a block) or SEMICOLON (in root), that's invalid.
            else:
                raise SyntaxError(f"Unexpected end of input after key '{key}' &#8212; expected ';' or '{{'.")
        # If we reached the end of the token stream (top-level block), return what we've built so far.
        return config
</code></code></pre><div><hr></div><h4>4. Example Walkthrough</h4><p>Let&#8217;s walk through what happens when parsing this block:<br></p><pre><code><code>http {
  server {
    listen 8080;
    location / {
      root /data/www;
    }
    location /static {
      root /data/static;
    }
  }

  server {
    listen 8081;
    location / {
      root /data/api;
    }
  }
}

</code></code></pre><h4><strong>Step-by-Step Parsing</strong></h4><ol><li><p>Parser sees http followed by { &#8594; enters a block.</p></li><li><p>Inside http:</p><ul><li><p>Sees server + { &#8594; enters a new server block</p><ul><li><p>Parses listen 8080; &#8594; adds &#8220;listen&#8221;: &#8220;8080&#8221;</p></li><li><p>Parses location / { root /data/www; } &#8594; nested block under location with path /</p></li><li><p>Parses location /static { root /data/static; } &#8594; second block under location with path /static</p></li></ul></li><li><p>Sees another server block &#8594; enters second server</p><ul><li><p>Parses listen 8081; &#8594; &#8220;listen&#8221;: &#8220;8081&#8221;</p></li><li><p>Parses location / { root /data/api; }</p></li></ul></li></ul></li></ol><p>Final structure:<br></p><pre><code><code>{
  "http": {
    "server": [
      {
        "listen": "8080",
        "location": {
          "/": {
            "root": "/data/www"
          },
          "/static": {
            "root": "/data/static"
          }
        }
      },
      {
        "listen": "8081",
        "location": {
          "/": {
            "root": "/data/api"
          }
        }
      }
    ]
  }
}

</code></code></pre><div><hr></div><h3><strong>&#128736; Configuration Parsing, Part 3: ServerConfig Object</strong></h3><p>Now that we&#8217;ve built the lexer and parser, which convert a raw config file into a structured nested dictionary, we&#8217;ll take the final step: wrapping that dictionary in a <strong>clean interface</strong> called ServerConfig.</p><div><hr></div><h4><strong>1. Why Wrap the Dictionary?</strong></h4><p>The parser gives us a powerful structure like:<br></p><pre><code><code>{
  "http": {
    "server": [
      {
        "listen": "8080",
        "location": {
          "/": {
            "root": "/data/www"
          }
        }
      },
      {
        "listen": "8081",
        "location": {
          "/": {
            "root": "/data/alt"
          }
        }
      }
    ]
  }
}
</code></code></pre><p>That&#8217;s great &#8212; but working directly with raw dictionaries is messy.</p><p>We&#8217;d rather write:<br></p><pre><code><code>config.listen_ports
config.routes
</code></code></pre><p>Than:<br></p><pre><code><code>config["http"]["server"][0]["location"]["/"]["root"]
</code></code></pre><div><hr></div><h4><strong>2. What Will ServerConfig Do?</strong></h4><ul><li><p>Provide <strong>typed, user-friendly access</strong> to key values.</p></li><li><p>Handle <strong>optional and default values</strong> gracefully.</p></li><li><p>Expose common patterns (like mapping ports to route trees).</p></li><li><p>Hide the nested structure from the rest of the server logic.</p></li></ul><div><hr></div><h4><strong>3. Full Implementation of ServerConfig</strong></h4><pre><code><code>class ServerConfig:
    """
    Wraps parsed configuration into a higher-level object with useful accessors.
    This class makes it easier to access settings like ports and routes.

    Expected format: output of SimpleConfigParser.parse()
    """

    def __init__(self, config_dict: dict):
        self.config = config_dict

    def get_servers(self) -&gt; list[dict]:
        """
        Returns a list of server blocks inside the http block.

        Handles:
        - No 'http' block present
        - One or more server blocks (as object or list)
        """
        http_block = self.config.get("http", {})
        servers = http_block.get("server", [])

        if isinstance(servers, dict):
            return [servers]  # single server block

        return servers  # list of servers or empty

    @property
    def listen_ports(self) -&gt; list[int]:
        """
        Extracts all port numbers from server blocks.
        Assumes port is defined via 'listen' directive.
        """
        ports = []
        for server in self.get_servers():
            port = server.get("listen")
            if port:
                try:
                    ports.append(int(port))
                except ValueError:
                    raise ValueError(f"Invalid port number: {port!r}")
        return ports

    @property
    def routes(self) -&gt; dict[int, dict[str, str]]:
        """
        Builds a routing table for each server block.

        Returns a mapping like:
        {
            8080: {"/": "/data/www"},
            8081: {"/": "/data/alt"}
        }

        It pulls 'root' directive from 'location' blocks.
        """
        mapping = {}
        for server in self.get_servers():
            port = int(server.get("listen", 80))  # default fallback
            route_map = {}

            location_block = server.get("location", {})
            for path, inner in location_block.items():
                if isinstance(inner, dict) and "root" in inner:
                    route_map[path] = inner["root"]

            mapping[port] = route_map

        return mapping
</code></code></pre><div><hr></div><h4><strong>4. Usage Example</strong></h4><p>Let&#8217;s see how you&#8217;d use ServerConfig in practice:<br></p><pre><code><code>config = ServerConfig(parsed_dict)

print(config.listen_ports)
# &#8594; [8080, 8081]

print(config.routes)
# &#8594; {8080: {"/": "/data/www"}, 8081: {"/": "/data/alt"}}
</code></code></pre><p>Much simpler than traversing a raw nested dictionary!</p><div><hr></div><h2><strong>5. One-Liner Wrapper Function:</strong></h2><h2><strong>load_config()</strong></h2><p>Here&#8217;s a function that brings everything together:<br></p><pre><code><code>def load_config(path: str) -&gt; ServerConfig:
    """
    Reads a config file, tokenizes and parses it, then wraps in ServerConfig.
    """
    with open(path, "r", encoding="utf-8") as f:
        config_text = f.read()

    lexer = SimpleConfigLexer(config_text)
    parser = SimpleConfigParser(lexer.tokens)
    parsed_dict = parser.parse()

    return ServerConfig(parsed_dict)
</code></code></pre><p>Now in your server, you can do:<br></p><pre><code><code>config = load_config("server.conf")
</code></code></pre><p>&#8230;and get a full parsed, typed configuration object.</p><p>And the full implementation you can find here: <a href="https://github.com/DmytroHuzz/build_own_webserver/blob/main/config_parser.py">https://github.com/DmytroHuzz/build_own_webserver/blob/main/config_parser.py</a></p><div><hr></div><p>We&#8217;ve completed our configuration system! The full pipeline is:</p><ol><li><p><strong>Lexer</strong> &#8211; splits raw config text into tokens</p></li><li><p><strong>Parser</strong> &#8211; builds nested dictionary from tokens</p></li><li><p><strong>ServerConfig</strong> &#8211; gives user-friendly access to config values</p></li></ol><p>This modular approach mirrors how real servers like NGINX parse their config files &#8212; but with an implementation that&#8217;s small, clean, and easy to understand.</p><h2><strong>&#129513; Wrapping Up</strong></h2><p>In this article, we built two critical components of our web server infrastructure: an <strong>HTTP parser</strong> and a <strong>configuration parser</strong>. These foundational tools will support every version of the server we build later &#8212; from simple blocking to advanced non-blocking architectures.</p><p>Here&#8217;s what we accomplished:</p><ul><li><p>Implemented a robust <strong>HTTP parser</strong> that can handle incomplete or malformed requests &#8212; a must-have for real-world networking.</p></li><li><p>Built a <strong>config parser pipeline</strong> consisting of:</p><ul><li><p>A <strong>lexer</strong> to tokenize raw config text</p></li><li><p>A <strong>parser</strong> that constructs a structured, nested dictionary</p></li><li><p>A clean ServerConfig wrapper for easy access to ports and routing</p></li></ul></li></ul><p>By separating each component clearly, we&#8217;ve made our system modular, testable, and much easier to extend &#8212; just like in production-grade servers like NGINX.</p><div><hr></div><p>In the <a href="https://www.softwareinthegrid.com/p/000b7742-1f55-4e1e-b324-dc91656a4be0">next article</a>, we&#8217;ll use these building blocks to implement our first working server: a <strong>single-threaded, blocking web server</strong>. We&#8217;ll measure its performance, understand its limitations, and prepare for more scalable designs.</p><p>Thanks again for reading &#8212; and feel free to share your thoughts, questions, or improvements!</p><p><a href="https://www.softwareinthegrid.com/p/18c4d9c2-334a-42b4-b412-4a36ae930029">Series hub: Building a Web Server from Scratch</a></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Software in the Grid is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item><item><title><![CDATA[Building Your Own Web Server: Part 1 — Theory and Foundations]]></title><description><![CDATA[This article is part of Software Foundations, where I explore networking, protocols, operating systems, and software systems from first principles.]]></description><link>https://www.softwareinthegrid.com/p/building-your-own-web-server-part</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/building-your-own-web-server-part</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Mon, 28 Sep 2026 12:36:40 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!UjmF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d40ef1-6dc3-448a-be5d-61044e8c1db4_1000x399.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UjmF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d40ef1-6dc3-448a-be5d-61044e8c1db4_1000x399.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UjmF!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d40ef1-6dc3-448a-be5d-61044e8c1db4_1000x399.webp 424w, https://substackcdn.com/image/fetch/$s_!UjmF!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d40ef1-6dc3-448a-be5d-61044e8c1db4_1000x399.webp 848w, https://substackcdn.com/image/fetch/$s_!UjmF!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d40ef1-6dc3-448a-be5d-61044e8c1db4_1000x399.webp 1272w, https://substackcdn.com/image/fetch/$s_!UjmF!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d40ef1-6dc3-448a-be5d-61044e8c1db4_1000x399.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!UjmF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d40ef1-6dc3-448a-be5d-61044e8c1db4_1000x399.webp" width="1000" height="399" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/37d40ef1-6dc3-448a-be5d-61044e8c1db4_1000x399.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:399,&quot;width&quot;:1000,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:32840,&quot;alt&quot;:&quot;Cover image for Building Your Own Web Server: Part 1 &#8212; Theory and Foundations&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/webp&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Cover image for Building Your Own Web Server: Part 1 &#8212; Theory and Foundations" title="Cover image for Building Your Own Web Server: Part 1 &#8212; Theory and Foundations" srcset="https://substackcdn.com/image/fetch/$s_!UjmF!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d40ef1-6dc3-448a-be5d-61044e8c1db4_1000x399.webp 424w, https://substackcdn.com/image/fetch/$s_!UjmF!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d40ef1-6dc3-448a-be5d-61044e8c1db4_1000x399.webp 848w, https://substackcdn.com/image/fetch/$s_!UjmF!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d40ef1-6dc3-448a-be5d-61044e8c1db4_1000x399.webp 1272w, https://substackcdn.com/image/fetch/$s_!UjmF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37d40ef1-6dc3-448a-be5d-61044e8c1db4_1000x399.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>This article is part of Software Foundations, where I explore networking, protocols, operating systems, and software systems from first principles. These foundations support the broader work of <a href="https://www.softwareinthegrid.com/">Software in the Grid</a>.</em></p><h2><strong>All articles in this series</strong></h2><ol><li><p><a href="https://www.softwareinthegrid.com/p/0c55774e-8b08-4ccf-9ebd-470a0d29d0c5">Building Your Own Web Server: Part 1 &#8212; Theory and Foundations</a></p></li><li><p><a href="https://www.softwareinthegrid.com/p/6a23363c-71d3-42e7-bce4-2bdc3931fd60">Building Your Own Web Server: Part 2 &#8212; Plan and Implementation of HTTP and Configuration parser</a></p></li><li><p><a href="https://www.softwareinthegrid.com/p/000b7742-1f55-4e1e-b324-dc91656a4be0">Building Your Own Web Server &#8212; Part 3: Blocking Single and Multithreaded Server</a></p></li><li><p><a href="https://www.softwareinthegrid.com/p/051d629f-b465-4f38-95db-987ea8c412ae">Building Your Own Web Server &#8212; Part 4: Single-threaded non-blocking server</a></p></li></ol><h2>Introduction</h2><p><em>This is Part 1 of a multi-part series where we will build a complete HTTP web server from scratch.</em></p><p>In this series of articles, I want to show how to create an HTTP web server <strong>from scratch</strong>.</p><p>The goal isn&#8217;t to build a production-ready system &#8212; it&#8217;s to explore different approaches to implementing a server: starting from a simple, naive, single-threaded server and moving toward asynchronous, non-blocking designs similar to those used by modern high-performance servers like <strong>Nginx</strong>.</p><p>At each step, I&#8217;ll measure performance and share the results with you.</p><p>The main motivation behind this article is to take a <strong>deep look under the hood</strong> of how web servers work and to truly understand the fundamental concepts involved.</p><p>When I started writing, I had two goals in mind:</p><ol><li><p>Understand it thoroughly myself.</p></li><li><p>Explain it clearly to you, step-by-step.</p></li></ol><p>However, as I dove deeper, I realized that building a server also touches on many other foundational topics &#8212; like sockets, the HTTP protocol, and concurrency.</p><p>This led me down a bit of a rabbit hole! I had to make some choices about <strong>how deep to go</strong> into each topic without overwhelming you or oversimplifying important concepts.</p><p>Because of this, I&#8217;ve structured the article into two main parts:</p><ul><li><p><strong>Theory</strong> &#8212; covering everything we need to know before we start coding.</p></li><li><p><strong>Implementation</strong> &#8212; where we&#8217;ll build different versions of our server.</p></li></ul><p>Feel free to skim the theory if you&#8217;re already familiar with some topics, but I highly recommend at least glancing through it, as I&#8217;ll refer back to key concepts throughout the implementation stages.</p><p>In theory section we will <strong>learn:</strong></p><ul><li><p>What a web server is and what it does</p></li><li><p>How HTTP defines the rules of communication</p></li><li><p>Why sockets are essential for network connections</p></li><li><p>The structure of an HTTP message</p></li><li><p>How persistent connections impact parsing</p></li><li><p>What functionality we need to implement in our server</p><p></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.softwareinthegrid.com/subscribe?"><span>Subscribe now</span></a></p></li></ul><div><hr></div><h2><strong>&#127760; What Is a Web Server?</strong></h2><p>Let&#8217;s start with a simple definition.</p><p>From a user&#8217;s perspective, a web server is an application that allows you to <strong>request specific information</strong> from a remote computer &#8212; and receive that information in a format you expect.</p><p>&#128161; So we know <em>what</em> a server does: <strong>serves information</strong>.</p><p>Now we need to understand <em>how</em> it does this.</p><p>The first step is enabling communication between the user and the remote machine &#8212; defining <strong>how</strong> to ask for specific resources and <strong>how</strong> to understand the response.</p><p>This is exactly what the <strong>HTTP protocol</strong> was created for: it defines the rules for communication between clients and servers, ensuring they can understand each other.</p><div><hr></div><h2><strong>&#128225; HTTP &#8211; The Language of the Web</strong></h2><p>Now that we know a web server&#8217;s job is to deliver resources on request, we need to understand the <strong>language</strong> it uses to communicate: <strong>HTTP (HyperText Transfer Protocol)</strong>.</p><p>HTTP defines <strong>how</strong> a client (like a browser) asks for a resource, and <strong>how</strong> the server answers.</p><p>Fortunately for us, we don&#8217;t need to dive deep into the full HTTP specification to build our first server.</p><p>We just need a basic understanding of:</p><ul><li><p>What an HTTP message looks like</p></li><li><p>How to parse it correctly</p></li><li><p>Why certain headers (like Content-Length and Connection) are critical</p></li></ul><p>If you&#8217;re curious and want to explore further, the full spec is here: <a href="https://datatracker.ietf.org/doc/html/rfc7230">RFC 7230</a>.</p><h3><strong>&#128232; Basic Structure of an HTTP Message</strong></h3><p>An HTTP <strong>request</strong> sent by the browser typically looks like this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SqDb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ca7f7c-a417-4684-91e0-8bb4faa0fccd_800x434.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SqDb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ca7f7c-a417-4684-91e0-8bb4faa0fccd_800x434.webp 424w, https://substackcdn.com/image/fetch/$s_!SqDb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ca7f7c-a417-4684-91e0-8bb4faa0fccd_800x434.webp 848w, https://substackcdn.com/image/fetch/$s_!SqDb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ca7f7c-a417-4684-91e0-8bb4faa0fccd_800x434.webp 1272w, https://substackcdn.com/image/fetch/$s_!SqDb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ca7f7c-a417-4684-91e0-8bb4faa0fccd_800x434.webp 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!SqDb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ca7f7c-a417-4684-91e0-8bb4faa0fccd_800x434.webp" width="800" height="434" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a9ca7f7c-a417-4684-91e0-8bb4faa0fccd_800x434.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:434,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;HTTP request&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="HTTP request" title="HTTP request" srcset="https://substackcdn.com/image/fetch/$s_!SqDb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ca7f7c-a417-4684-91e0-8bb4faa0fccd_800x434.webp 424w, https://substackcdn.com/image/fetch/$s_!SqDb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ca7f7c-a417-4684-91e0-8bb4faa0fccd_800x434.webp 848w, https://substackcdn.com/image/fetch/$s_!SqDb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ca7f7c-a417-4684-91e0-8bb4faa0fccd_800x434.webp 1272w, https://substackcdn.com/image/fetch/$s_!SqDb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9ca7f7c-a417-4684-91e0-8bb4faa0fccd_800x434.webp 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Where <code>cr</code> (Carriage Return) (ASCII 13, \r), <code>lf</code> ( Line Feed) (ASCII 10, \n) are used to note the termination of a line.<br>The blank line (\r\n) separates the <strong>headers</strong> from the <strong>body</strong>.</p><p>In many requests, especially GET, there may be no body at all.</p><p>Similarly, an <strong>HTTP response</strong> from the server looks like this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kIky!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b1dbb5-2dc9-4a7c-8a9e-dbc9f317781f_799x421.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kIky!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b1dbb5-2dc9-4a7c-8a9e-dbc9f317781f_799x421.webp 424w, https://substackcdn.com/image/fetch/$s_!kIky!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b1dbb5-2dc9-4a7c-8a9e-dbc9f317781f_799x421.webp 848w, https://substackcdn.com/image/fetch/$s_!kIky!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b1dbb5-2dc9-4a7c-8a9e-dbc9f317781f_799x421.webp 1272w, https://substackcdn.com/image/fetch/$s_!kIky!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b1dbb5-2dc9-4a7c-8a9e-dbc9f317781f_799x421.webp 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!kIky!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b1dbb5-2dc9-4a7c-8a9e-dbc9f317781f_799x421.webp" width="799" height="421" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/74b1dbb5-2dc9-4a7c-8a9e-dbc9f317781f_799x421.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:421,&quot;width&quot;:799,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;HTTP response&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="HTTP response" title="HTTP response" srcset="https://substackcdn.com/image/fetch/$s_!kIky!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b1dbb5-2dc9-4a7c-8a9e-dbc9f317781f_799x421.webp 424w, https://substackcdn.com/image/fetch/$s_!kIky!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b1dbb5-2dc9-4a7c-8a9e-dbc9f317781f_799x421.webp 848w, https://substackcdn.com/image/fetch/$s_!kIky!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b1dbb5-2dc9-4a7c-8a9e-dbc9f317781f_799x421.webp 1272w, https://substackcdn.com/image/fetch/$s_!kIky!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74b1dbb5-2dc9-4a7c-8a9e-dbc9f317781f_799x421.webp 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3><strong>&#9881;&#65039; Parsing an HTTP Message</strong></h3><p>According to the spec,<br></p><pre><code><code>The normal procedure for parsing an HTTP message is to read the
   start-line into a structure, read each header field into a hash table
   by field name until the empty line, and then use the parsed data to
   determine if a message body is expected.  If a message body has been
   indicated, then it is read as a stream until an amount of octets
   equal to the message body length is read or the connection is closed.
</code></code></pre><p>the basic parsing flow is:</p><ol><li><p>Read the <strong>start line</strong> (GET /index.html HTTP/1.1)</p></li><li><p>Read headers into a <strong>dictionary</strong> until you hit a blank line</p></li><li><p>If a Content-Length is present, read exactly that many bytes for the body</p></li><li><p>Done!</p></li></ol><p><strong>And that&#8217;s exactly what we&#8217;ll implement later.</strong></p><blockquote><p>&#127775; <strong>Tip:</strong> There&#8217;s a great summary of HTTP parsing in Python&#8217;s <a href="https://github.com/python/cpython/blob/main/Lib/http/server.py">http.server</a> module too - worth a look!</p></blockquote><h3><strong>&#127991;&#65039; Important: Content-Length and Persistent Connections</strong></h3><p>Earlier, we briefly mentioned that HTTP/1.1 introduced <strong>persistent connections</strong>.</p><p>Let&#8217;s dive deeper into what this means &#8212; because it has a huge impact on how our server will handle requests and parse incoming data.</p><h4><strong>&#128260; Persistent Connections: What Changes?</strong></h4><p>In HTTP/1.0, the typical behaviour was simple:</p><ul><li><p>Client opens a TCP connection</p></li><li><p>Sends one request</p></li><li><p>Receives one response</p></li><li><p>Server closes the connection</p></li></ul><p>Every request needed a brand new connection.</p><p>&#128994; Easy to understand.</p><p>&#128308; But expensive! Establishing a TCP connection involves a multi-step handshake, and doing that for every single image, CSS file, or small resource creates massive overhead.</p><p>&#128588; <strong>In HTTP/1.1, things changed.</strong></p><p><strong>Persistent connections</strong> (sometimes called <strong>Keep-Alive connections</strong>) became the default behaviour:</p><ul><li><p>The client and server <strong>keep the TCP connection open</strong> after a request-response cycle finishes.</p></li><li><p>The same connection can be used for multiple requests and multiple responses.</p></li></ul><p>This greatly improves performance &#8212; especially for pages with lots of resources.</p><h4><strong>Why Content-Length Matters So Much</strong></h4><p>Here&#8217;s the new problem persistent connections create:</p><p>When multiple requests and responses share the same socket, <strong>how can the server know where one message ends and the next one begins?</strong></p><p>When we read from a socket, the data arrives as a <strong>continuous stream of bytes</strong>.</p><p>Imagine you call recv(1024) &#8212; you could get:</p><ul><li><p>Only part of a request</p></li><li><p>Exactly one complete request</p></li><li><p>A request and half of another one</p></li><li><p>Three full requests packed together</p></li></ul><p>There is <strong>no guarantee</strong> that one recv() call equals one HTTP message.</p><p><strong>&#129504; It was a small but critical realization for me:</strong></p><blockquote><p><strong>TCP is a stream-based protocol, not a message-based one.</strong></p></blockquote><p>It does not respect HTTP message boundaries at all.</p><p>So how do we split the stream correctly?</p><p>&#128161; <strong>This is where Content-Length saves us.</strong></p><p>The Content-Length header tells us:</p><ul><li><p>Exactly how many bytes belong to the message <strong>body</strong>.</p></li><li><p>Once we parse the start line and headers, we use Content-Length to know how many bytes we must read to get the complete body.</p></li><li><p>After that, we know the next byte belongs to the start of a new message &#8212; or there might be no next message yet.</p></li></ul><h4><strong>&#128736;&#65039; In practice, parsing looks like this:</strong></h4><ol><li><p>Read the <strong>start line</strong> and <strong>headers</strong> from the stream.</p></li><li><p>Look for Content-Length in the headers.</p></li><li><p>If Content-Length exists:</p><ul><li><p>Read exactly that number of bytes to get the body.</p></li></ul></li><li><p>After the body is fully read:</p><ul><li><p>If more bytes are available, start parsing the next HTTP message immediately.</p></li></ul></li><li><p>If Content-Length is missing (and no Transfer-Encoding: chunked is used), we might have to infer the end of the body by other means (e.g., closing the connection).</p></li></ol><h4><strong>&#128293; Why This Matters for Our Server</strong></h4><p>Since we plan to implement a <strong>basic HTTP/1.1 server</strong> with <strong>persistent connections</strong>, our HTTP parser must:</p><ul><li><p>Correctly read and separate multiple messages arriving through the same connection.</p></li><li><p>Handle incomplete messages (e.g., when the body hasn&#8217;t fully arrived yet).</p></li><li><p>Never mix up message boundaries &#8212; even if multiple requests come one after another without any delays.</p></li></ul><p>Without correctly handling Content-Length, even a simple browser reload could completely break our server!</p><p>That&#8217;s why in our first implementation, <strong>we will strictly require</strong>:</p><ul><li><p>Every client request must include a Content-Length header if it has a body.</p></li><li><p>Our parser must rely on it to know exactly when a message body ends.</p></li></ul><h3><strong>&#128368;&#65039; HTTP Versions</strong></h3><p>Throughout this article, you may have noticed that we often referred to different versions of HTTP.</p><p>Therefore, it&#8217;s important to take a moment to discuss this concept more carefully.</p><p>Not all functionalities &#8212; especially modern ones &#8212; were available in the initial version of the protocol, <strong>HTTP/0.9</strong>.</p><p>The default and most widely used version today is <strong>HTTP/1.1</strong>, which already implements all the basic features necessary for building a functional web server.</p><p>In our implementation, we will use <strong>HTTP/1.1</strong> as the primary protocol version between client and server and will focus on supporting its core features.</p><p>However, HTTP/1.1 is not the final step in the evolution of the protocol.</p><p>Over time, HTTP has undergone several important improvements, introducing many features that are crucial for modern web applications &#8212; such as multiplexing, better performance, and faster connection setup.</p><p>If you&#8217;re interested in a deeper dive into the protocol&#8217;s history and evolution, I highly recommend reading this excellent resource: <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Evolution_of_HTTP">MDN Web Docs &#8212; Evolution of HTTP</a>.</p><p>To give you a clearer picture, here&#8217;s a simple table summarizing the major HTTP versions and the key features each one introduced:</p><p><strong>Version:</strong> <strong>HTTP/0.9</strong><br><strong>Year:</strong> 1991<br><strong>Key Features:</strong> - Very simple protocol- Only supports GET- No headers<br><strong>Limitations:</strong> - No status codes- No metadata- Plain HTML only</p><p><strong>Version:</strong> <strong>HTTP/1.0</strong><br><strong>Year:</strong> 1996<br><strong>Key Features:</strong> - Introduced headers- Status codes- Content type &amp; length<br><strong>Limitations:</strong> - Opens a new TCP connection for every request</p><p><strong>Version:</strong> <strong>HTTP/1.1</strong><br><strong>Year:</strong> 1997<br><strong>Key Features:</strong> - Persistent (Keep-Alive) connections- Chunked transfer encoding- Pipelining (limited use)- Better caching support<br><strong>Limitations:</strong> - Head-of-line blocking- Still sequential on a single connection</p><p><strong>Version:</strong> <strong>HTTP/2</strong><br><strong>Year:</strong> 2015<br><strong>Key Features:</strong> - Binary framing- Multiplexing over a single connection- Header compression- Prioritization of requests<br><strong>Limitations:</strong> - Still based on TCP (suffers from head-of-line blocking at transport layer)</p><p><strong>Version:</strong> <strong>HTTP/3</strong><br><strong>Year:</strong> 2022+<br><strong>Key Features:</strong> - Runs on QUIC (UDP-based)- Faster handshakes- Better performance on unreliable networks- Built-in encryption<br><strong>Limitations:</strong> - Newer, not fully supported everywhere yet- More complex to implement</p><div><hr></div><h2><strong>&#128066; Sockets &#8211; How Servers Hear You</strong></h2><p>Now that we understand the <em>language</em>, we need to understand the <em>ears</em> &#8212; the mechanism that allows a server to listen for incoming HTTP requests.</p><p>That mechanism is the <strong>socket</strong>.</p><h3><strong>&#128268; What Is a Socket?</strong></h3><p>At the operating system level, a socket is an object that connects:</p><ul><li><p>An IP address (like 127.0.0.1) and</p></li><li><p>A port (like 8080)</p></li></ul><p>It acts as a <strong>door</strong>: all network traffic targeting that address and port is handed to your application through the socket.</p><p>In Python, creating a socket looks like this:<br></p><pre><code><code>import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("127.0.0.1", 8080))
s.listen()
</code></code></pre><h4><strong>&#128260; How Server Sockets Work (Summary)</strong></h4><p>Here&#8217;s the typical life cycle:</p><ol><li><p><strong>Create</strong> a socket.</p></li><li><p><strong>Bind</strong> it to an address and port.</p></li><li><p><strong>Listen</strong> for incoming connections.</p></li><li><p><strong>Accept</strong> a connection.</p></li><li><p><strong>Receive</strong> a request via recv().</p></li><li><p><strong>Send</strong> a response via send().</p></li><li><p><strong>Close</strong> the connection &#8212; or keep it alive.</p></li></ol><div><hr></div><h2><strong>&#128203; Requirements: What Our Web Server Must Handle</strong></h2><p>Now that we understand the basic communication flow between client and server, it&#8217;s time to look at the web server from a <strong>developer&#8217;s perspective</strong>.</p><p>What tasks and challenges must we solve to build even the simplest working server?</p><p>Let&#8217;s break them down:</p><h3><strong>1. HTTP Parsing</strong></h3><p>When a user sends a request, it&#8217;s just raw data arriving through the socket.</p><p>The HTTP protocol defines how that data is structured &#8212; but it&#8217;s up to us to <strong>interpret it correctly</strong>.</p><p>&#127919; <strong>Goal:</strong> We need to implement a <strong>simple HTTP parser</strong> that:</p><ul><li><p>Reads the start line (like GET /index.html HTTP/1.1)</p></li><li><p>Extracts important information, such as the <strong>requested URL</strong></p></li><li><p>Processes headers (especially Content-Length)</p></li><li><p>Differentiates where one message ends and another begins (important for persistent connections)</p></li></ul><p>In our first version, we&#8217;ll focus mainly on supporting simple GET requests and parsing enough headers to correctly understand message boundaries.</p><h3><strong>&#128506;&#65039; 2. Configuration Management: Defining How the Server Behaves</strong></h3><p>Once we successfully parse an HTTP request and extract the <strong>requested URL</strong>, the next big question is:</p><p><strong>What should the server do with this request?</strong></p><p>Unlike hardcoded logic (where every request is manually handled in code), modern web servers rely heavily on <strong>configuration files</strong> to define behavior dynamically &#8212; without changing the server&#8217;s internal code.</p><p>Our server must also support a configuration system that tells it:</p><ul><li><p>Which resources it should serve directly</p></li><li><p>When and how to forward requests to other backend services</p></li></ul><p>This flexibility is absolutely crucial even for basic web servers.</p><h4><strong>&#9881;&#65039; Two Modes of Operation</strong></h4><p>Modern web servers usually operate in one of two modes (or a combination of both):</p><h5><strong>&#128450;&#65039; Mode 1: Serving Static Files</strong></h5><p>This is the simplest and most traditional use of a web server.</p><ul><li><p>When the server receives a request like /index.html, it looks into a <strong>specified directory</strong> on the server&#8217;s file system.</p></li><li><p>If the requested file exists (e.g., /var/www/html/index.html), it reads the file&#8217;s contents and sends it back as the HTTP response.</p></li><li><p>If the file is not found, the server returns a <strong>404 Not Found</strong> error.</p></li></ul><p>This mode is fast, efficient, and perfect for serving:</p><ul><li><p>HTML pages</p></li><li><p>CSS stylesheets</p></li><li><p>JavaScript files</p></li><li><p>Images (PNG, JPG, SVG, etc.)</p></li><li><p>Static JSON files</p></li></ul><p><strong>Example Configuration Rule for Static Files:</strong><br></p><pre><code><code>location /static/ {
    root /var/www/static/;
}
</code></code></pre><h5><strong>&#128256; Mode 2: Acting as a Reverse Proxy</strong></h5><p>In more complex architectures, the web server doesn&#8217;t always serve files itself.</p><p>Instead, it acts as a <strong>middleman</strong> between the client and a <strong>backend application</strong>.</p><ul><li><p>When the server receives a request, it forwards it to another application running elsewhere &#8212; often on a different port or even a different machine.</p></li><li><p>It waits for the backend application to respond (for example, a dynamic HTML page or JSON data).</p></li><li><p>Then it passes the backend&#8217;s response back to the original client.</p></li></ul><p>This mode is essential for building dynamic web applications where the content is generated on-the-fly (user dashboards, APIs, login systems, etc.).</p><p><strong>Example Configuration Rule for Reverse Proxying:</strong><br></p><pre><code><code>location /api/ {
    proxy_pass http://127.0.0.1:5000/;
}
</code></code></pre><p>Meaning: if a client requests /api/users, the server forwards the request to an application running locally on port 5000 (e.g., a Flask app).</p><h4><strong>&#128196; Configuration in Our Server</strong></h4><p>In our server, we will:</p><ul><li><p><strong>Start simple</strong>: focus only on serving static files first.</p></li><li><p><strong>Later extend</strong>: add support for reverse proxying once basic functionality is reliable.</p></li></ul><p>We will define a <strong>custom configuration file</strong> with a simple syntax inspired by Nginx.</p><p>Initially, the config file will:</p><ul><li><p>Map <strong>URL prefixes</strong> to <strong>file system directories</strong> for static serving.</p></li></ul><p>Later, it will:</p><ul><li><p>Map <strong>URL prefixes</strong> to <strong>backend services</strong> for proxying.</p></li></ul><div><hr></div><h2><strong>&#128218; Wrapping Up: What We Learned</strong></h2><p>In this first part, we took a deep look under the hood of web server architecture.</p><p>We explored:</p><ul><li><p>What a web server actually is and what it must do</p></li><li><p>How HTTP structures communication between clients and servers</p></li><li><p>Why parsing HTTP messages correctly is critical (especially with persistent connections)</p></li><li><p>How sockets act as the foundation for network communication</p></li><li><p>Why configuration files give servers the flexibility they need</p></li><li><p>The two main modes of a server: serving static files and acting as a reverse proxy</p></li></ul><p>These are the core concepts that will guide every decision we make in the implementation phase.</p><div><hr></div><h2><strong>&#128640; What&#8217;s Next</strong></h2><p>Now that we have a strong theoretical foundation, it&#8217;s time to move from ideas to action.</p><p>In the next articles, we&#8217;ll:</p><ul><li><p>Build our own basic web server step-by-step</p></li><li><p>Start with a simple, single-threaded, blocking version</p></li><li><p>Measure its performance</p></li><li><p>Then gradually evolve it into a concurrent, non-blocking, highly efficient server &#8212; inspired by real-world architectures like Nginx</p></li></ul><p>We&#8217;ll get our hands dirty with real code, but always staying grounded in the principles we just learned.</p><div><hr></div><h2><strong>&#128588; Thank You for Reading!</strong></h2><p>If you&#8217;ve made it this far, you already understand more about how web servers work than most developers ever do.</p><p>The next steps will be even more fun &#8212; we&#8217;ll see all these concepts come alive!</p><p>Next article: <a href="https://www.softwareinthegrid.com/p/6a23363c-71d3-42e7-bce4-2bdc3931fd60">Building Your Own Web Server: Part 2 &#8212; Plan and Implementation of HTTP and Configuration parser</a></p><p><em>Thanks for reading &#8212; I hope you found this deep dive as fascinating as I did while writing it. See you in the next part!</em></p><p><a href="https://www.softwareinthegrid.com/p/18c4d9c2-334a-42b4-b412-4a36ae930029">Series hub: Building a Web Server from Scratch</a></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Software in the Grid is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Building a Web Server from Scratch]]></title><description><![CDATA[This article is part of Software Foundations, where I explore networking, protocols, operating systems, and software systems from first principles.]]></description><link>https://www.softwareinthegrid.com/p/building-a-web-server-from-scratch</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/building-a-web-server-from-scratch</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Mon, 28 Sep 2026 12:35:34 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!nB-x!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b89608f-ff67-4c73-a8fd-6ebc4c4e20d1_1536x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nB-x!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b89608f-ff67-4c73-a8fd-6ebc4c4e20d1_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nB-x!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b89608f-ff67-4c73-a8fd-6ebc4c4e20d1_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!nB-x!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b89608f-ff67-4c73-a8fd-6ebc4c4e20d1_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!nB-x!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b89608f-ff67-4c73-a8fd-6ebc4c4e20d1_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!nB-x!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b89608f-ff67-4c73-a8fd-6ebc4c4e20d1_1536x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nB-x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b89608f-ff67-4c73-a8fd-6ebc4c4e20d1_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6b89608f-ff67-4c73-a8fd-6ebc4c4e20d1_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2341878,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/217819420?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b89608f-ff67-4c73-a8fd-6ebc4c4e20d1_1536x1024.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!nB-x!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b89608f-ff67-4c73-a8fd-6ebc4c4e20d1_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!nB-x!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b89608f-ff67-4c73-a8fd-6ebc4c4e20d1_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!nB-x!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b89608f-ff67-4c73-a8fd-6ebc4c4e20d1_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!nB-x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b89608f-ff67-4c73-a8fd-6ebc4c4e20d1_1536x1024.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>This article is part of Software Foundations, where I explore networking, protocols, operating systems, and software systems from first principles. These foundations support the broader work of <a href="https://www.softwareinthegrid.com/">Software in the Grid</a>.</em></p><p>What happens between a browser sending an HTTP request and a server returning a response?</p><p>In this four-part series, I build a web server in Python to work through that question. We start with HTTP and sockets, build the parsing and configuration components, then compare three server designs: blocking, multithreaded, and single-threaded with non-blocking I/O.</p><p>The goal is to understand the decisions inside a server by making them ourselves. This is a learning project, not a production-ready server.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.softwareinthegrid.com/subscribe?"><span>Subscribe now</span></a></p><h2>Read the series</h2><h3><a href="https://www.softwareinthegrid.com/p/0c55774e-8b08-4ccf-9ebd-470a0d29d0c5">Part 1 &#8212; Theory and Foundations</a></h3><p>What a web server does, how HTTP messages are structured, and how sockets connect an application to the network. We look at persistent connections, message boundaries in a TCP byte stream, and the requirements that will guide the implementation.</p><h3><a href="https://www.softwareinthegrid.com/p/6a23363c-71d3-42e7-bce4-2bdc3931fd60">Part 2 &#8212; Plan and Implementation of HTTP and Configuration Parser</a></h3><p>We build the components the server will depend on: an HTTP parser and an NGINX-style configuration system. The configuration pipeline moves from a lexer to a parser and then to a typed object the server can use.</p><h3><a href="https://www.softwareinthegrid.com/p/000b7742-1f55-4e1e-b324-dc91656a4be0">Part 3 &#8212; Blocking Single and Multithreaded Server</a></h3><p>We put the pieces together, starting with a blocking server. Then we add persistent connections, routing, and threads. ApacheBench experiments help us inspect how the designs behave under different request and connection patterns.</p><h3><a href="https://www.softwareinthegrid.com/p/051d629f-b465-4f38-95db-987ea8c412ae">Part 4 &#8212; Single-Threaded Non-Blocking Server</a></h3><p>We move to an event loop and explore I/O readiness, epoll, and Python&#8217;s selectors. The final implementation lets one thread work across multiple connections, and we compare its measured behavior with the earlier versions.</p><h2>How to use the series</h2><p>Read the parts in order if you want to follow the implementation. If you already know HTTP and sockets, Part 2 starts the build, Part 3 explores blocking and threads, and Part 4 focuses on non-blocking I/O.</p><p>The <a href="https://github.com/DmytroHuzz/build_own_webserver">source code</a> accompanies the articles. Treat the benchmark numbers as results from these experiments, not a general ranking of server architectures.</p><h2>Where this leads: TLS</h2><p>Once the server can move and interpret bytes, another question follows: how do we protect those bytes and know who we are communicating with?</p><p>My <a href="https://www.softwareinthegrid.com/p/rebuilding-tls-from-scratch-my-complete">Rebuilding TLS from Scratch</a> series explores that next layer. In <a href="https://www.softwareinthegrid.com/p/adding-homemade-tls-to-a-homemade">Adding Homemade TLS to a Homemade Web Server</a>, I bring the two projects together.</p><p>This series belongs to Software Foundations. It explores general networking and server architecture&#8212;the underlying software concepts that support the broader work of Software in the Grid.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Software in the Grid is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Networking Machinery for Software Engineers Part 2: Extending The Empire and Rebuilding a Global Network]]></title><description><![CDATA[We pushed our kingdom beyond the horizon. To keep it connected, we had to extend our Signal Tower system with Layer 3: IP addresses, subnets, gateways, routing tables, and DHCP.]]></description><link>https://www.softwareinthegrid.com/p/networking-machinery-for-software-f6b</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/networking-machinery-for-software-f6b</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Wed, 02 Sep 2026 16:02:36 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!JAas!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d96a595-7108-43f7-92b7-4c57c97c5f2a_1672x941.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JAas!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d96a595-7108-43f7-92b7-4c57c97c5f2a_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JAas!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d96a595-7108-43f7-92b7-4c57c97c5f2a_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!JAas!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d96a595-7108-43f7-92b7-4c57c97c5f2a_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!JAas!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d96a595-7108-43f7-92b7-4c57c97c5f2a_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!JAas!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d96a595-7108-43f7-92b7-4c57c97c5f2a_1672x941.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JAas!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d96a595-7108-43f7-92b7-4c57c97c5f2a_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0d96a595-7108-43f7-92b7-4c57c97c5f2a_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:3508483,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/213862386?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d96a595-7108-43f7-92b7-4c57c97c5f2a_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!JAas!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d96a595-7108-43f7-92b7-4c57c97c5f2a_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!JAas!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d96a595-7108-43f7-92b7-4c57c97c5f2a_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!JAas!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d96a595-7108-43f7-92b7-4c57c97c5f2a_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!JAas!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d96a595-7108-43f7-92b7-4c57c97c5f2a_1672x941.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Previous Article:</h2><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;7da8154b-8c47-46dc-9252-2341abd1913d&quot;,&quot;caption&quot;:&quot;Recently I started working on a networking series for software developers who enter the electrical-grid world and suddenly discover that the grid speaks in packets, interfaces, switches, routes, protocols and a suspicious number of acronyms.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Networking Machinery for Software Engineers\nPart 1: Rebuilding a Local Network with Medieval Signal Towers&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer exploring how complex systems are built. I take them apart, rebuild them from first principles, and trace the layers connecting software, networks, infrastructure, devices, and the physical world.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-08-28T09:48:20.438Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!Xg26!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81428888-7e1b-4174-8ad1-092e46214718_1672x941.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/networking-machinery-for-software&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:213120887,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!JM5w!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f89608f-4575-4fe4-9df4-7d6a25e088b2_1254x1254.png&quot;,&quot;belowTheFold&quot;:false,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><p><a href="https://www.softwareinthegrid.com/p/networking-machinery-for-software">We have just built our small kingdom</a>. One valley, a few villages, a few signal towers, and a local network that works surprisingly well for something invented by people who still believe that medicine is mostly a matter of balancing four bodily fluids.</p><p>Unfortunately, sooner or later power becomes the main goal of the most ambitious people in the kingdom, and sooner or later one kingdom becomes too small for them. Scouts discover settlements behind the mountains, armies march along roads that were previously used for sheep, and within a few years our neat little kingdom becomes an empire with several valleys somewhere beyond the horizon.</p><p>The moral dilemma is outside the scope of this article, and we, as network engineers in medieval Europe, are definitely not in a position to judge the military policy of our lords. What we do need to judge is whether the communication system from <a href="https://www.softwareinthegrid.com/p/networking-machinery-for-software">Part 1</a> can survive this expansion.</p><p>It cannot.</p><p>Our old system knows how to move a frame inside one valley, but it has no idea what a valley is, where its border lies, or what to do when a destination is hidden behind three mountain passes and somebody else&#8217;s tax system.</p><p>So we will build the larger system in the same way we built the local one. We will remain with our towers until messages can cross the whole empire, and only after the machinery works will we return to a real computer and the Internet. This order matters because IP addresses, gateways and routing tables are much easier to remember when they arrive as answers to problems we have already felt.</p><p>In this post we will discuss how IP addresses, network prefixes, gateways, routing tables and ARP turn local networks into a network of networks. We will then see how the same model appears on Linux, how DHCP gives a host the information it needs, and what changes while one packet crosses several routers.</p><p>The real-world part focuses on IPv4 carried over Ethernet. Other link technologies can carry IP without Ethernet, and IPv6 uses Neighbor Discovery instead of ARP, but one carefully bounded world is enough for now. Our empire is already difficult to govern without opening several additional continents.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://www.softwareinthegrid.com/subscribe?"><span>Subscribe now</span></a></p><h2>Two orders of names</h2><p>In our existing system every tower already has a local name such as <code>0A</code>, <code>0B</code> or <code>0C</code>, and that worked perfectly while the entire known world fitted inside one valley.</p><p>Then we acquired another valley.</p><p>It has its own towers, which may be called <code>1A</code>, <code>1B</code> and <code>1C</code>. They may also be called <code>0A</code>, <code>0B</code> and <code>0C</code>, because coordination between medieval kingdoms is apparently not much better than coordination between modern IT departments.</p><p>Now an order addressed to <code>0A</code> is ambiguous. There is an <code>0A</code> in Valley 1 and another <code>0A</code> in Valley 2, and the old name tells us who should receive a message only after we already know which local network we are talking about.</p><p>This is not a flaw in the old system. A local name was invented for local delivery, and inside one valley it still does that job perfectly. The empire has simply created a second question that the local name was never meant to answer:</p><blockquote><p>In which valley does the destination live?</p></blockquote><p>So we introduce another order of names. Tower <code>0A</code> keeps its local address and independently receives the wider address <code>V1.7</code>. A tower in Valley 2 may reuse the same local address <code>0A</code> while independently receiving <code>V2.12</code>. The local and wider addresses are not constructed from one another. They are separate identifiers assigned for different scopes.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LCQo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83cce10d-858c-4273-98ec-989757ccfc1d_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LCQo!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83cce10d-858c-4273-98ec-989757ccfc1d_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!LCQo!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83cce10d-858c-4273-98ec-989757ccfc1d_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!LCQo!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83cce10d-858c-4273-98ec-989757ccfc1d_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!LCQo!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83cce10d-858c-4273-98ec-989757ccfc1d_1672x941.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!LCQo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83cce10d-858c-4273-98ec-989757ccfc1d_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/83cce10d-858c-4273-98ec-989757ccfc1d_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2249090,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/213862386?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83cce10d-858c-4273-98ec-989757ccfc1d_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!LCQo!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83cce10d-858c-4273-98ec-989757ccfc1d_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!LCQo!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83cce10d-858c-4273-98ec-989757ccfc1d_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!LCQo!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83cce10d-858c-4273-98ec-989757ccfc1d_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!LCQo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F83cce10d-858c-4273-98ec-989757ccfc1d_1672x941.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 1. The local address </em><code>0A</code><em> can be reused in both valleys. The independent wider addresses </em><code>V1.7</code><em> and </em><code>V2.12</code><em> identify the towers across the empire, and neither is derived from </em><code>0A</code><em>.</em></p><p>We have just reconstructed the reason a machine can need both a MAC address and an IP address.</p><p>The MAC address is the local name. It identifies the immediate sender or receiver on one Ethernet network. The IP address is the wider name. It identifies the source and destination across many connected networks.</p><p>The two addresses do not compete, and one is not a more modern replacement for the other. They describe the same machine at different scopes, rather like a person&#8217;s room number and full postal address. A room number can be perfectly useful inside one building even though a letter crossing the country needs more information.</p><h3>Is the destination still inside our valley?</h3><p>Imagine that tower <code>0A</code> in Valley 1 receives an order:</p><blockquote><p>Deliver this message to <code>V1.12</code>.</p></blockquote><p>The destination begins with <code>V1</code>, and our tower also belongs to <code>V1</code>, so the destination is local. It can use exactly the machinery we built in Part 1. It discovers which local tower owns <code>V1.12</code>, learns that tower&#8217;s local address if necessary, and sends a frame through the valley.</p><p>Then another order arrives:</p><blockquote><p>Deliver this message to <code>V2.12</code>.</p></blockquote><p>This time the wider address tells us something important before a single signal is sent. The destination belongs to Valley 2, while our tower belongs to Valley 1. None of the local towers can deliver a frame directly through the mountain.</p><p>Our medieval rule can still be very simple:</p><pre><code><code>V1.*  local
everything else  beyond the valley

</code></code></pre><p>Modern networking calls the precise version of this boundary a network prefix, but we do not need the binary notation yet. For the moment, the important discovery is that an address must contain enough structure to tell us not only who the destination is, but also whether it belongs to our local world.</p><p>Once <code>0A</code> knows that <code>V2.12</code> is remote, it needs somewhere local to send the message.</p><h2>A gateway at the edge of the valley</h2><p>We build a special tower at the border of Valley 1. It can receive local frames from our valley, but it also has a road leading into another network. Let us call it <code>G1</code>.</p><p>Tower <code>0A</code> now learns one additional rule:</p><blockquote><p>If the final destination is outside Valley 1, give the packet to <code>G1</code>.</p></blockquote><p>This creates a situation that looks strange only until the two scopes become visible. Suppose <code>0A</code> wants to reach <code>V2.12</code>. The final destination is still <code>V2.12</code>, but the next tower that can physically receive a local frame is <code>G1</code>.</p><p>The message therefore carries two destinations:</p><pre><code><code>Final IP destination: V2.12
Local MAC destination: G1

</code></code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!S9s_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc704fc62-2439-4d16-b27f-78f0054e6665_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!S9s_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc704fc62-2439-4d16-b27f-78f0054e6665_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!S9s_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc704fc62-2439-4d16-b27f-78f0054e6665_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!S9s_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc704fc62-2439-4d16-b27f-78f0054e6665_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!S9s_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc704fc62-2439-4d16-b27f-78f0054e6665_1672x941.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!S9s_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc704fc62-2439-4d16-b27f-78f0054e6665_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c704fc62-2439-4d16-b27f-78f0054e6665_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2934167,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/213862386?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc704fc62-2439-4d16-b27f-78f0054e6665_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!S9s_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc704fc62-2439-4d16-b27f-78f0054e6665_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!S9s_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc704fc62-2439-4d16-b27f-78f0054e6665_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!S9s_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc704fc62-2439-4d16-b27f-78f0054e6665_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!S9s_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc704fc62-2439-4d16-b27f-78f0054e6665_1672x941.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 2. The local frame is an outer delivery envelope addressed to the next hop, </em><code>G1</code><em>. The packet inside keeps the final destination, </em><code>V2.12</code><em>.</em></p><p>The outer address gets the message across the current local network. The inner address survives beyond that network and tells every gateway where the journey should eventually end.</p><p>Gateway <code>G1</code> receives the frame because its own local address is written on the outside. It removes that local envelope and reads the wider address inside:</p><pre><code><code>Destination IP: V2.12

</code></code></pre><p>Now <code>G1</code> faces the same question that tower <code>0A</code> faced, only on a larger map. Where should this packet go next?</p><h2>A small map inside every gateway</h2><p>We hang a parchment inside <code>G1</code>:</p><pre><code><code>Valley 1          directly connected
Valley 2          eastern relay R1
Valley 3          northern relay R2
Everything else  royal highway G0

</code></code></pre><p>This parchment is our routing table.</p><p>It does not describe the complete road from Valley 1 to every tower in the empire. <code>G1</code> does not need to know every bridge, every mountain pass or every official who will lose the paperwork. It only needs to know the next useful step.</p><p>For <code>V2.12</code>, the table selects relay <code>R1</code>. If the link between <code>G1</code> and <code>R1</code> is another local Ethernet-like network, the wider address of the next hop is still not enough to send a frame. <code>G1</code> needs the local address of <code>R1</code> on that link.</p><p>This brings us back to the machinery from Part 1. If the mapping is not already known, <code>G1</code> asks the local network which MAC address belongs to the next-hop IP address. In IPv4 over Ethernet, this is ARP.</p><p>The forwarding process is therefore not one mysterious act called routing. It is a sequence of smaller questions:</p><pre><code><code>Where is the packet ultimately going?
        &#8595;
Which route best matches that destination?
        &#8595;
What is the next hop on that route?
        &#8595;
Which local address belongs to that next hop?
        &#8595;
Send one local frame

</code></code></pre><p>Routing chooses the direction. ARP, when the current link is IPv4 over Ethernet, supplies the local delivery address needed to take the next step.</p><h3>The same packet, a new local frame</h3><p>The route across our empire might look like this:</p><pre><code><code>Tower 0A in Valley 1
        &#8595;
Gateway G1
        &#8595;
Eastern relay R1
        &#8595;
Gateway G2
        &#8595;
Tower 0B in Valley 2

</code></code></pre><p>On the first hop, the local frame is addressed to <code>G1</code>. After <code>G1</code> opens that frame and chooses the next route, it creates a new local frame addressed to <code>R1</code>. Relay <code>R1</code> repeats the process and creates another frame addressed to <code>G2</code>. Inside Valley 2, <code>G2</code> finally creates a frame addressed to tower <code>0B</code>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qmAC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25b49c1d-311e-4d69-8e7c-f762a0c33139_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qmAC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25b49c1d-311e-4d69-8e7c-f762a0c33139_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!qmAC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25b49c1d-311e-4d69-8e7c-f762a0c33139_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!qmAC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25b49c1d-311e-4d69-8e7c-f762a0c33139_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!qmAC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25b49c1d-311e-4d69-8e7c-f762a0c33139_1672x941.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!qmAC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25b49c1d-311e-4d69-8e7c-f762a0c33139_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/25b49c1d-311e-4d69-8e7c-f762a0c33139_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2958392,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/213862386?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25b49c1d-311e-4d69-8e7c-f762a0c33139_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!qmAC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25b49c1d-311e-4d69-8e7c-f762a0c33139_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!qmAC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25b49c1d-311e-4d69-8e7c-f762a0c33139_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!qmAC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25b49c1d-311e-4d69-8e7c-f762a0c33139_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!qmAC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25b49c1d-311e-4d69-8e7c-f762a0c33139_1672x941.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 3. The blue end-to-end destination remains </em><code>V2.12</code><em>. Each gold local delivery ends at one next hop, after which a new local frame is created for the following link.</em></p><p>The IP destination does not become <code>G1</code>, then <code>R1</code>, then <code>G2</code>. It remains <code>V2.12</code>, because that is the end of the journey. What changes is the local delivery information wrapped around it.</p><p>This distinction gives us the mental model for the whole article:</p><blockquote><p>The IP packet describes the end-to-end conversation. The local frame describes only the next delivery.</p></blockquote><p>Every gateway repeats the same small procedure. It removes the local frame, reads the destination IP, consults its routing table, chooses a next hop, and creates whatever local frame the next link requires.</p><p>The routes also describe valleys rather than every individual tower. <code>G1</code> does not need separate rules for <code>V2.1</code>, <code>V2.2</code>, <code>V2.3</code> and every other address in Valley 2. One rule for <code>V2.*</code> is enough, because the next useful step is the same for all of them.</p><p>Our empire may eventually grow too large for routes to be written by hand. Routers can then exchange information and learn routes from one another, but that changes how the parchment is produced, not how a packet uses it. Forwarding still means reading the destination, selecting the best route and taking one local step.</p><p>We have now rebuilt the complete mechanism with towers. Local names move frames inside a valley. Wider addresses identify destinations across valleys. A boundary tells a tower whether the destination is local. A gateway accepts everything beyond that boundary. A routing table chooses the next hop, and each local network carries the packet one step farther.</p><p>Our little kingdom is no longer one network.</p><p>It is becoming a network of networks.</p><p>In other words, we have started building Layer 3.</p><p>Only now are we ready to leave the towers.</p><h2>Back to the real world</h2><p>Imagine one Linux machine connected to a home or office network:</p><pre><code><code>IP address:      192.168.1.23/24
Interface:       eth0
Default gateway: 192.168.1.1
MAC address:     3c:52:82:xx:xx:xx

</code></code></pre><p>This is almost exactly what our tower knew. The machine has a local Ethernet identity, a wider IPv4 identity, a description of its local boundary, and the address of a gateway that can accept packets leaving that boundary.</p><p>Suppose an application wants to reach <code>192.168.1.50</code>. Linux has a directly connected route for the local network, so the selected next hop is the destination itself. If the neighbor cache does not already contain the answer, ARP asks:</p><blockquote><p>Who has <code>192.168.1.50</code>?</p></blockquote><p>Once the machine learns a mapping such as <code>192.168.1.50 &#8594; aa:bb:cc:dd:ee:ff</code>, it can place the IP packet inside an Ethernet frame addressed directly to that MAC address.</p><p>Nothing particularly dramatic happened. We stayed inside one valley.</p><h3>Leaving the valley</h3><p>Now the same application wants to reach <code>8.8.8.8</code>.</p><p>Linux exposes the relevant routes with <code>ip route</code>:</p><pre><code><code>default via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0 scope link

</code></code></pre><p>At first this looks like the usual Linux habit of turning a simple idea into compressed hieroglyphics, but the table contains only two important rules. Destinations in <code>192.168.1.0/24</code> are directly reachable through <code>eth0</code>. Everything for which no more specific route exists goes through <code>192.168.1.1</code>.</p><p>For <code>8.8.8.8</code>, the local route does not match, so the default route selects <code>192.168.1.1</code> as the next hop. The packet remains addressed to <code>8.8.8.8</code>, while the first Ethernet frame is addressed to the MAC address of <code>192.168.1.1</code>.</p><p>If that MAC address is unknown, ARP asks:</p><blockquote><p>Who has <code>192.168.1.1</code>?</p></blockquote><p>There is one technical correction worth making explicit here. It is common to explain the host as if it first performs a separate subnet test and then, only for a remote destination, remembers that routing tables exist. The operating system actually performs a route lookup. Configuring <code>192.168.1.23/24</code> on <code>eth0</code> creates the directly connected route, while configuring the gateway creates the default route. Local and remote delivery are two outcomes of the same lookup.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dRRQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04a65802-2ecb-4e05-8d50-c450eea4361f_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dRRQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04a65802-2ecb-4e05-8d50-c450eea4361f_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!dRRQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04a65802-2ecb-4e05-8d50-c450eea4361f_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!dRRQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04a65802-2ecb-4e05-8d50-c450eea4361f_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!dRRQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04a65802-2ecb-4e05-8d50-c450eea4361f_1672x941.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!dRRQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04a65802-2ecb-4e05-8d50-c450eea4361f_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/04a65802-2ecb-4e05-8d50-c450eea4361f_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2955647,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/213862386?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04a65802-2ecb-4e05-8d50-c450eea4361f_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!dRRQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04a65802-2ecb-4e05-8d50-c450eea4361f_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!dRRQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04a65802-2ecb-4e05-8d50-c450eea4361f_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!dRRQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04a65802-2ecb-4e05-8d50-c450eea4361f_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!dRRQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04a65802-2ecb-4e05-8d50-c450eea4361f_1672x941.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 4. The route lookup happens first. It selects either the destination itself or the gateway as the next hop, and only then does ARP resolve that selected next hop on Ethernet.</em></p><p>This ordering prevents two common confusions. ARP does not decide whether a destination is local, and it does not choose a route. It answers a local address-resolution question after routing has already chosen the next hop.</p><h2>Where does the valley end?</h2><p>Our tower used a rule such as <code>V1.*</code> to recognize its valley. IPv4 represents the same idea with a network prefix.</p><p>An IPv4 address contains 32 bits, which we usually write as four decimal octets. In <code>192.168.1.23/24</code>, the <code>/24</code> says that the first 24 bits belong to the network portion and the remaining 8 belong to the host portion.</p><p>For this address, the network is <code>192.168.1.0/24</code>. Addresses such as <code>192.168.1.5</code>, <code>192.168.1.50</code> and <code>192.168.1.200</code> belong to that network, while <code>192.168.2.5</code> does not.</p><p>The traditional subnet mask <code>255.255.255.0</code> expresses the same boundary. In binary it contains 24 ones followed by 8 zeroes. The ones mark the network portion, while the zeroes leave room for host addresses.</p><p>The boundary does not have to respect the dots in the decimal notation, because the dots exist for us and the bits exist for the machine. Consider <code>192.168.1.10/26</code>. The first 24 bits and the first 2 bits of the final octet belong to the network, leaving 6 host bits.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Dgl9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c80a44-3b68-464e-8f4b-5b8901f96055_1600x900.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Dgl9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c80a44-3b68-464e-8f4b-5b8901f96055_1600x900.png 424w, https://substackcdn.com/image/fetch/$s_!Dgl9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c80a44-3b68-464e-8f4b-5b8901f96055_1600x900.png 848w, https://substackcdn.com/image/fetch/$s_!Dgl9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c80a44-3b68-464e-8f4b-5b8901f96055_1600x900.png 1272w, https://substackcdn.com/image/fetch/$s_!Dgl9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c80a44-3b68-464e-8f4b-5b8901f96055_1600x900.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!Dgl9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c80a44-3b68-464e-8f4b-5b8901f96055_1600x900.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f7c80a44-3b68-464e-8f4b-5b8901f96055_1600x900.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1119051,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/213862386?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c80a44-3b68-464e-8f4b-5b8901f96055_1600x900.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Dgl9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c80a44-3b68-464e-8f4b-5b8901f96055_1600x900.png 424w, https://substackcdn.com/image/fetch/$s_!Dgl9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c80a44-3b68-464e-8f4b-5b8901f96055_1600x900.png 848w, https://substackcdn.com/image/fetch/$s_!Dgl9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c80a44-3b68-464e-8f4b-5b8901f96055_1600x900.png 1272w, https://substackcdn.com/image/fetch/$s_!Dgl9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff7c80a44-3b68-464e-8f4b-5b8901f96055_1600x900.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 5. Each final octet contains exactly eight bit positions. A </em><code>/24</code><em> leaves positions 1 through 8 for hosts, while a </em><code>/26</code><em> uses positions 1 and 2 for the network and leaves positions 3 through 8, exactly six bits, for hosts.</em></p><p>Those four <code>/26</code> networks begin at:</p><pre><code><code>192.168.1.0/26
192.168.1.64/26
192.168.1.128/26
192.168.1.192/26

</code></code></pre><p>This is why <code>192.168.1.10</code> and <code>192.168.1.50</code> belong to the first <code>/26</code>, while <code>192.168.1.70</code> belongs to the second. The decimal addresses look almost like neighbors, but the prefix has placed a real border between them.</p><p>The prefix is not an intermediate technique unrelated to our story. It is the exact mathematical form of the question our first tower had to answer:</p><blockquote><p>Does the destination belong to my local network, or must the selected route lead through a gateway?</p></blockquote><h2>Who gave the host its map?</h2><p>So far our computer somehow knew its IP address, its prefix, its default gateway and usually a DNS server. On a normal home or office network, nobody sits down every morning and manually configures every laptop, phone, printer and coffee machine that has somehow acquired WiFi.</p><p>Most of the time, DHCP does the paperwork.</p><p>A new host already has its local Ethernet identity, but it does not yet know its IPv4 address, its network boundary or its default gateway. It cannot send a normal IP request to a server whose address it does not know from an address it does not have, so it begins with a local broadcast:</p><blockquote><p>I am here. Can somebody tell me who I am supposed to be?</p></blockquote><p>The basic exchange is usually remembered as DORA: Discover, Offer, Request and Acknowledgement. The server may eventually give the client:</p><pre><code><code>IP address:      192.168.1.23
Prefix:          /24
Default gateway: 192.168.1.1
DNS server:      192.168.1.1
Lease:           24 hours

</code></code></pre><p>DHCP did not route anything. It simply handed the host the small piece of the map it needs before routing can begin.</p><p>The lease means that the address is borrowed rather than carved into stone. Before the lease expires, the client normally tries to renew it, and the server may allow the same address to remain or assign another one.</p><p>The first DHCP discovery is a local broadcast, and routers normally do not forward local broadcasts. When the DHCP server lives in another network, a DHCP relay listens locally and carries the request toward the remote server. This lets one server configure many networks without joining their broadcast domains together.</p><p>If DHCP is absent, nothing fundamental breaks. We can configure the IP address, prefix, gateway and DNS server manually, provided that the values are correct and the chosen address does not conflict with another host.</p><p>Small networks often place DHCP, routing, NAT, firewalling, DNS forwarding and WiFi inside the same plastic box near the wall. Calling that entire creature a router is convenient but slightly misleading. Router is one role performed by the device, just as a castle can be a home, a fortress, a court, a prison and a very expensive heating problem at the same time.</p><h2>Following one real packet</h2><p>Host A lives at <code>192.168.1.23/24</code>, and somewhere beyond several networks Host Z lives at <code>10.20.0.42/16</code>. Host A&#8217;s route lookup selects <code>192.168.1.1</code> as the gateway, and ARP gives it the gateway interface&#8217;s MAC address.</p><p>The word <em>interface</em> matters here. A router connects at least two networks, so it does not have one universal IP address or one universal MAC address. Each Ethernet interface belongs to a particular local network and has its own MAC address, while it will usually have an IP address in that network as well.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Jmd8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdafd6728-b9ce-45d8-ad98-507cb7da588d_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Jmd8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdafd6728-b9ce-45d8-ad98-507cb7da588d_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!Jmd8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdafd6728-b9ce-45d8-ad98-507cb7da588d_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!Jmd8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdafd6728-b9ce-45d8-ad98-507cb7da588d_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!Jmd8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdafd6728-b9ce-45d8-ad98-507cb7da588d_1672x941.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!Jmd8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdafd6728-b9ce-45d8-ad98-507cb7da588d_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dafd6728-b9ce-45d8-ad98-507cb7da588d_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2852013,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/213862386?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdafd6728-b9ce-45d8-ad98-507cb7da588d_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Jmd8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdafd6728-b9ce-45d8-ad98-507cb7da588d_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!Jmd8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdafd6728-b9ce-45d8-ad98-507cb7da588d_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!Jmd8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdafd6728-b9ce-45d8-ad98-507cb7da588d_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!Jmd8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdafd6728-b9ce-45d8-ad98-507cb7da588d_1672x941.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 6. A router&#8217;s interfaces belong to different local networks. The incoming frame ends at Interface A, while a new local frame leaves through Interface B with that interface&#8217;s identity.</em></p><p>Hosts on <code>192.168.1.0/24</code> use <code>192.168.1.1</code> as their gateway because that address belongs to the router interface standing inside their own network. The interface on the other side belongs to another network and has different local neighbors.</p><p>Host A creates the first frame:</p><pre><code><code>Ethernet destination: MAC of 192.168.1.1
IPv4 destination:     10.20.0.42

</code></code></pre><p>The router removes the Ethernet frame, reads the IPv4 destination, performs its own route lookup and chooses the next hop. If the outgoing link is also Ethernet, the router resolves that next hop&#8217;s MAC address and creates a completely new frame. The next router repeats the same process.</p><p>Eventually a router finds that <code>10.20.0.0/16</code> is directly connected. On the final Ethernet network, it uses ARP to learn Host Z&#8217;s MAC address and creates the last local frame.</p><p>The IPv4 source and destination normally remain the same in this simple routed topology. NAT can deliberately rewrite addresses, but NAT is another official with another stamp and is not required to explain routing.</p><p>The packet is not completely untouched, however. Every router decreases the IPv4 Time to Live, usually called TTL, by at least one. Because TTL is part of the IPv4 header, the router also updates the IPv4 header checksum.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!L_ZY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd2733a9-260c-4b6b-9048-d7473451cb12_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!L_ZY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd2733a9-260c-4b6b-9048-d7473451cb12_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!L_ZY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd2733a9-260c-4b6b-9048-d7473451cb12_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!L_ZY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd2733a9-260c-4b6b-9048-d7473451cb12_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!L_ZY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd2733a9-260c-4b6b-9048-d7473451cb12_1672x941.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!L_ZY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd2733a9-260c-4b6b-9048-d7473451cb12_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bd2733a9-260c-4b6b-9048-d7473451cb12_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2211619,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/213862386?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd2733a9-260c-4b6b-9048-d7473451cb12_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!L_ZY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd2733a9-260c-4b6b-9048-d7473451cb12_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!L_ZY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd2733a9-260c-4b6b-9048-d7473451cb12_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!L_ZY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd2733a9-260c-4b6b-9048-d7473451cb12_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!L_ZY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbd2733a9-260c-4b6b-9048-d7473451cb12_1672x941.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 7. The IPv4 source and destination stay end to end, each local frame is rebuilt for one link, and TTL decreases as routers forward the packet.</em></p><p>TTL exists because routing information can be wrong. If two routers keep sending a packet back and forth, the packet must not wander between them until the end of history. When TTL reaches zero, the router discards it and normally sends an ICMP Time Exceeded message back toward the source.</p><p>Ethernet is not mandatory on every link. Another link technology may use different framing and may have no MAC addresses or ARP at all. What survives is the larger mechanism: the router removes the old link-layer envelope, keeps the IP destination, chooses the next route and creates whatever local delivery the outgoing link requires.</p><p>Layer 3 does not bypass Layer 2. It uses one local link, then another one, then another one. A global network is made from local networks that repeatedly agree to pass the packet on.</p><h2>Routers do not know the whole journey</h2><p>A router does not normally calculate the complete road from Host A to Host Z. It needs to answer only one question:</p><blockquote><p>Where should I send this packet next?</p></blockquote><p>This is why routing tables usually describe networks rather than every individual host. One rule can say that the whole <code>10.20.0.0/16</code> network is reachable through Router B.</p><p>Sometimes several routes match the same destination:</p><pre><code><code>10.0.0.0/8       via Router A
10.20.0.0/16     via Router B
10.20.5.0/24     via Router C
default          via Router D

</code></code></pre><p>The address <code>10.20.5.17</code> matches every line, including the default, but the <code>/24</code> route wins because it has the longest matching prefix. A longer prefix describes a smaller and more specific group of addresses. The default route has a prefix length of zero, so it is the vaguest possible instruction: if nobody knows better, send the packet this way.</p><p>For a small network, somebody can configure these routes by hand. In a much larger system, routers can exchange routes through protocols such as OSPF, IS-IS and BGP. Those protocols deserve their own story, but forwarding remains the same after the table has been built: read the destination IP, choose the most specific matching route, select the next hop, and perform one local delivery.</p><h2>What actually happens when we type <code>ping</code></h2><p>When we run:</p><pre><code><code>ping 8.8.8.8

</code></code></pre><p>the operating system performs the route lookup, selects the next hop, resolves the necessary local address if the outgoing link requires it, and sends an IPv4 packet containing an ICMP Echo Request.</p><p>If the remote host chooses to answer, it sends an ICMP Echo Reply back toward us. A successful reply means that the forward route worked, the return route worked, the necessary local deliveries succeeded, and the policies along the way allowed ICMP.</p><p>A failed <code>ping</code> therefore does not prove that the destination is dead. It proves only that the complete conversation did not return, which is a much less satisfying answer and a much more honest one.</p><h2>The mental model to keep</h2><p>We began with a local network that knew only local tower names. The second valley made those names ambiguous, so we added a wider address that named both the valley and the tower. Once a destination could be remote, we needed a boundary that distinguished our local world from everything beyond it. A remote packet needed a gateway, and the gateway needed a routing table that selected the next useful step.</p><p>Every new idea appeared because the growing system made the previous model insufficient.</p><p>The result can be carried in one sentence:</p><blockquote><p>Routing keeps an end-to-end IP destination inside the packet while rebuilding the local delivery around it for every link.</p></blockquote><p>A MAC address answers who should receive this frame here. An IP address answers where the packet is ultimately going. A prefix describes which addresses belong to a network. A route chooses the next hop, and ARP maps that next-hop IP address to a local Ethernet address when the current link needs one.</p><p>None of this replaced the network from Part 1. We built above it and then reused it at every hop.</p><p>Put those answers together and our valleys become a network of networks, which is rather inconveniently the same direction in which our rulers were taking their empire anyway.</p><h2>One machine is still a black box</h2><p>There is one character in this story that we have treated with suspicious casualness: the computer itself.</p><p>Throughout both parts I have written that the computer checks a route, stores a neighbor, owns a MAC address and sends a frame, but what inside the machine actually does those things? Where does a network interface begin and the operating system end? What changes when one computer has several interfaces, and what happens when some of those interfaces are not physical at all?</p><p>Linux can create virtual interfaces, connect them with virtual Ethernet pairs, place them in bridges, and split the network into namespaces that behave like separate hosts. One physical machine can contain several isolated valleys and the roads between them.</p><p>Which means that, instead of invading another kingdom for the next experiment, we can build almost the entire empire inside one Linux machine.</p><p>That is where we go next.</p><p>Routing explains how a packet finds its next hop. To explore how applications protect data carried over that network, continue with <a href="https://www.softwareinthegrid.com/p/rebuilding-tls-from-scratch-my-complete">Rebuilding TLS From Scratch</a>. That completed series builds an authenticated, encrypted channel above TCP, one missing property at a time.</p><div><hr></div><p>Subscribe to Software in the Grid for the next step: rebuilding these networks inside Linux with interfaces, bridges, virtual links, and namespaces.</p><h2>Next part:</h2><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;168fbbf8-bfa7-4db2-b14d-896f037018d0&quot;,&quot;caption&quot;:&quot;Previous part:&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Inside the Linux Networking Stack: From NIC to App&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer in the energy sector. I publish Software in the Grid, exploring how software works inside modern power infrastructure.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-10-03T17:58:46.849Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!xaga!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55e49167-4d3a-482a-ae8d-af5c40454628_1672x941.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/inside-the-linux-networking-stack&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:218666073,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:1,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><h2><strong>Series Hub:</strong></h2><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;990c8251-ce55-43e9-b182-303f4b4b5da9&quot;,&quot;caption&quot;:&quot;I have worked with networked software for years, but for most of that time the network was something I used rather than something I really understood. I could open a socket, call an API, connect to an IP address, and continue with the part of the system I was responsible for.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;lg&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Networking in the Power Grid for Software Developers&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer exploring how complex systems are built. I take them apart, rebuild them from first principles, and trace the layers connecting software, networks, infrastructure, devices, and the physical world.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-08-27T21:18:02.367Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!sXgD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2f83a8-82b3-42d5-817b-5266707341bb_1672x941.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/networking-in-the-power-grid-for&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:213058272,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!JM5w!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f89608f-4575-4fe4-9df4-7d6a25e088b2_1254x1254.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div>]]></content:encoded></item><item><title><![CDATA[Networking Machinery for Software Engineers
Part 1: Rebuilding a Local Network with Medieval Signal Towers]]></title><description><![CDATA[How a ridiculous thought experiment leads to Ethernet frames, MAC addresses, switches, broadcast, and ARP.]]></description><link>https://www.softwareinthegrid.com/p/networking-machinery-for-software</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/networking-machinery-for-software</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Fri, 28 Aug 2026 09:48:20 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Xg26!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81428888-7e1b-4174-8ad1-092e46214718_1672x941.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Xg26!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81428888-7e1b-4174-8ad1-092e46214718_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Xg26!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81428888-7e1b-4174-8ad1-092e46214718_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!Xg26!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81428888-7e1b-4174-8ad1-092e46214718_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!Xg26!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81428888-7e1b-4174-8ad1-092e46214718_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!Xg26!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81428888-7e1b-4174-8ad1-092e46214718_1672x941.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Xg26!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81428888-7e1b-4174-8ad1-092e46214718_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/81428888-7e1b-4174-8ad1-092e46214718_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1901889,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/213120887?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81428888-7e1b-4174-8ad1-092e46214718_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Xg26!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81428888-7e1b-4174-8ad1-092e46214718_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!Xg26!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81428888-7e1b-4174-8ad1-092e46214718_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!Xg26!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81428888-7e1b-4174-8ad1-092e46214718_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!Xg26!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81428888-7e1b-4174-8ad1-092e46214718_1672x941.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Recently I started working on a networking series for software developers who enter the electrical-grid world and suddenly discover that the grid speaks in packets, interfaces, switches, routes, protocols and a suspicious number of acronyms.</p><p>Before going anywhere near IEC 61850, utility WANs or substation networks, I wanted to understand the ordinary networking machinery itself. Not only what a switch or ARP does, but why these things had to appear in the first place.</p><p>I could start with the OSI model. I have seen that diagram enough times in my life. The problem is that a finished diagram is very good at telling us where something belongs and surprisingly bad at showing why it exists.</p><p>So I had a more ridiculous idea.</p><p>Imagine that I am somewhere in medieval Europe. No copper cable, no fiber, no radio and definitely no Ethernet. I have stone towers on hills, and the only useful property I can rely on is visibility. If one tower can see another, I can make light visible or hide it.</p><p>Could I start from that and slowly rebuild a network?</p><p>This is not a historical reconstruction. I am not claiming that medieval Europe was one good standards committee away from IEEE 802.3. The towers are only a constraint. I want to begin with the smallest possible communication system, push it until it becomes uncomfortable, fix the new problem, and then compare the thing we invented with the machinery inside a real network.</p><p>That approach is much closer to how I like to understand systems. The finished technology often hides the reasons for its own shape. Broken and incomplete versions expose them.</p><p>In this post we will discuss the local part of the network. We will begin with physical signalling between two towers, then add more participants and see why frames, MAC addresses, switching, flooding, broadcast and ARP appear. Near the end we will come back to Linux and look at the same machinery on a real machine.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:&quot;button-wrapper&quot;}" data-component-name="ButtonCreateButton"><a class="button primary button-wrapper" href="https://www.softwareinthegrid.com/subscribe?"><span>Subscribe now</span></a></p><h2>Two towers and one bit</h2><p>I want to begin before packets, addresses and protocols exist at all.</p><p>Two towers stand on neighboring hills. Tower A can see Tower B directly.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9xb0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04b2efcb-70e6-4c61-a47b-863cdd855705_1280x720.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9xb0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04b2efcb-70e6-4c61-a47b-863cdd855705_1280x720.svg 424w, https://substackcdn.com/image/fetch/$s_!9xb0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04b2efcb-70e6-4c61-a47b-863cdd855705_1280x720.svg 848w, https://substackcdn.com/image/fetch/$s_!9xb0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04b2efcb-70e6-4c61-a47b-863cdd855705_1280x720.svg 1272w, https://substackcdn.com/image/fetch/$s_!9xb0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04b2efcb-70e6-4c61-a47b-863cdd855705_1280x720.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!9xb0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04b2efcb-70e6-4c61-a47b-863cdd855705_1280x720.svg" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/04b2efcb-70e6-4c61-a47b-863cdd855705_1280x720.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:87732,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/213120887?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04b2efcb-70e6-4c61-a47b-863cdd855705_1280x720.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!9xb0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04b2efcb-70e6-4c61-a47b-863cdd855705_1280x720.svg 424w, https://substackcdn.com/image/fetch/$s_!9xb0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04b2efcb-70e6-4c61-a47b-863cdd855705_1280x720.svg 848w, https://substackcdn.com/image/fetch/$s_!9xb0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04b2efcb-70e6-4c61-a47b-863cdd855705_1280x720.svg 1272w, https://substackcdn.com/image/fetch/$s_!9xb0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F04b2efcb-70e6-4c61-a47b-863cdd855705_1280x720.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Diagram 1. Our entire network consists of two towers with direct visibility.</em></p><p>Tower A wants to send one piece of information to Tower B. The bridge is closed, for example.</p><p>But even that sentence is already too advanced for our network. We do not yet have a way to move a single bit between the towers.</p><p>The simplest thing I can invent is a lantern with a shutter. During a fixed interval the light is either visible or hidden.</p><pre><code><code>light visible = 1
light hidden  = 0

</code></code></pre><p>So a guard can produce something like:</p><pre><code><code>1 0 1 1 0 0 1 0

</code></code></pre><p>And the other tower can observe it.</p><p>This looks almost stupidly primitive, but it already contains the first real networking problem. An abstract <code>1</code> inside one system has to become something physical, travel through a medium, and be recovered by the other system.</p><p>In our case the medium is light through air. In Ethernet it may be an electrical or optical signal. Wireless uses radio. Real physical layers do not literally push abstract bits through a cable one after another. They deal with symbols, encoding, timing, synchronization, noise, attenuation, clock recovery and many other details that become a rabbit hole very quickly.</p><p>Even the lantern version immediately asks awkward questions. How long does one interval last? How does Tower B know where the sequence begins? What happens in fog? If the light stays visible for three intervals, how does the receiver know that it saw <code>111</code> rather than one long <code>1</code>?</p><p>I am going to stop before our medieval guards have to invent signal processing.</p><p>The useful part for this article is that we have reconstructed the job of Layer 1: make information physical enough that it can cross one link and be recovered at the other side.</p><p>That works beautifully while our entire civilization consists of two towers.</p><p>Unfortunately, I want a network.</p><h2>Adding the rest of the valley</h2><p>So I add more towers.</p><p>Some can see each other directly. Some need a relay point between them. For the moment, imagine one local communication region where a relay tower has direct light paths toward several participants.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QjZS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febc4c9fa-29c7-4359-a71d-1b16f5ec5ab8_1280x720.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QjZS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febc4c9fa-29c7-4359-a71d-1b16f5ec5ab8_1280x720.svg 424w, https://substackcdn.com/image/fetch/$s_!QjZS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febc4c9fa-29c7-4359-a71d-1b16f5ec5ab8_1280x720.svg 848w, https://substackcdn.com/image/fetch/$s_!QjZS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febc4c9fa-29c7-4359-a71d-1b16f5ec5ab8_1280x720.svg 1272w, https://substackcdn.com/image/fetch/$s_!QjZS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febc4c9fa-29c7-4359-a71d-1b16f5ec5ab8_1280x720.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!QjZS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febc4c9fa-29c7-4359-a71d-1b16f5ec5ab8_1280x720.svg" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ebc4c9fa-29c7-4359-a71d-1b16f5ec5ab8_1280x720.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:133776,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/213120887?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febc4c9fa-29c7-4359-a71d-1b16f5ec5ab8_1280x720.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!QjZS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febc4c9fa-29c7-4359-a71d-1b16f5ec5ab8_1280x720.svg 424w, https://substackcdn.com/image/fetch/$s_!QjZS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febc4c9fa-29c7-4359-a71d-1b16f5ec5ab8_1280x720.svg 848w, https://substackcdn.com/image/fetch/$s_!QjZS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febc4c9fa-29c7-4359-a71d-1b16f5ec5ab8_1280x720.svg 1272w, https://substackcdn.com/image/fetch/$s_!QjZS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febc4c9fa-29c7-4359-a71d-1b16f5ec5ab8_1280x720.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Diagram 2. Several towers now share one local communication system through a relay point.</em></p><p>The light can move bits across each individual path, but the moment several towers share the system, a stream like this becomes annoyingly ambiguous:</p><pre><code><code>10110010...

</code></code></pre><p>Who is it for? Where does one message end and the next one begin? If the relay receives it, which path should it use? And if I later want to carry different kinds of data, how does the receiver know what is inside?</p><p>This is where the simple Layer 1 picture starts to break. The physical signal still matters, but I need structure above it.</p><h2>Give the towers local addresses</h2><p>I will start with the most obvious missing piece and give every tower a local identifier.</p><pre><code><code>Tower A = 0A
Tower B = 0B
Tower C = 0C
Tower D = 0D

</code></code></pre><p>There is nothing magical about these values. My tiny kingdom does not need a 48-bit address space yet.</p><p>Now instead of sending naked bits, Tower A can send a structure:</p><pre><code><code>TO:   0C
FROM: 0A
TYPE: MESSAGE
DATA: THE BRIDGE IS CLOSED

</code></code></pre><p>The relay no longer has to guess what the bits mean. There is a destination, a source, a description of what the payload contains, and the payload itself.</p><p>That structure is already suspiciously close to an Ethernet frame.</p><p>Our tower frame Ethernet equivalent.</p><p>What it is doing: </p><p><code>TO</code> Destination MAC address Identifies the local recipient of the frame </p><p><code>FROM</code> Source MAC address Identifies the local sender of the frame </p><p><code>TYPE</code> EtherType Tells the receiver what kind of payload is carried </p><p><code>DATA</code> Payload Carries the higher-level data</p><p>A real Ethernet frame has more machinery around this, and the signal on the wire has additional synchronization and encoding details. Our invented text header is obviously not its real wire format. Those details solve different problems, so I will leave them outside this model for now.</p><p>The important thing is that <code>0A</code>, <code>0B</code> and the rest are local link-layer identities. They play the role of MAC addresses. They do not tell us how to reach a tower somewhere on the other side of Europe. They let this local network move a frame toward the right participant.</p><p>This is roughly where Layer 2 enters the picture. We have stopped dealing only with signals and started dealing with frames and local delivery.</p><h2>The relay starts remembering</h2><p>The first version of my relay can be extremely lazy. Every time it receives a transmission, it can repeat the signal toward every other light path. At the frame level, the result is that every frame becomes visible everywhere.</p><p>This is roughly the world of an old Ethernet hub. A real hub operates at Layer 1 and repeats signals rather than parsing Ethernet frames, which is one place where the tower analogy should not be pushed too literally.</p><p>But the relay is sitting in a very useful position. When a frame arrives from the western path and says:</p><pre><code><code>FROM: 0A

</code></code></pre><p>it has learned something for free: whatever <code>0A</code> is, the western path is how I just heard from it.</p><p>So the relay can remember that fact.</p><p>After some traffic its memory may look like this:</p><pre><code><code>0A &#8594; western path
0B &#8594; northern path
0C &#8594; eastern path
0D &#8594; southern path

</code></code></pre><p>Now a frame addressed to <code>0C</code> does not have to be repeated everywhere. The relay can send it only toward the eastern path.</p><p>This is the part where our relay has quietly become an Ethernet switch.</p><p>A switch builds a forwarding table by looking at the source MAC address of frames arriving on its ports. The source address is evidence. If a frame from <code>0C</code> arrived through port 3, then <code>0C</code> is currently reachable through port 3. Real switches also age these entries because networks change, cables move and machines disappear.</p><p>The destination MAC is used for the next decision. If the switch already knows where that destination lives, it forwards the frame through the corresponding port.</p><h3>The destination that has never spoken</h3><p>This was the first place where I caught myself giving the relay knowledge it had never earned.</p><p>Suppose its table contains only:</p><pre><code><code>0A &#8594; western path
0B &#8594; northern path

</code></code></pre><p>Then a frame arrives from the west:</p><pre><code><code>FROM: 0A
TO:   0C

</code></code></pre><p>The relay can refresh <code>0A &#8594; western path</code>, because it has just observed that fact. But the destination field tells it absolutely nothing about where <code>0C</code> is located. <code>TO: 0C</code> only describes what the sender wants.</p><p>So the relay has one honest option: try all the other paths.</p><p>It retransmits the frame everywhere except back through the path it arrived on. Every participant may see it, but only <code>0C</code> should accept a unicast frame addressed to <code>0C</code>.</p><p>Ethernet calls this unknown unicast flooding.</p><p>If Tower C later sends anything:</p><pre><code><code>FROM: 0C
TO:   0A

</code></code></pre><p>then the relay finally gets real evidence. The frame came from the east, so it can learn:</p><pre><code><code>0C &#8594; eastern path

</code></code></pre><p>Future frames for <code>0C</code> can go directly there.</p><p>There is a subtle point here that I want to keep separate from ARP. Unknown unicast flooding means the sender already put a destination MAC address into the Ethernet frame, but the switch does not know which port leads to that MAC. ARP solves a different problem: the sending host may not know the destination MAC address at all.</p><p>In a normal fresh IPv4 conversation, ARP often causes the destination host to reply before the first IP unicast frame is sent. That reply also gives the switch a chance to learn the destination MAC. So you may not actually observe unknown unicast flooding every time you contact a new local IP address.</p><p>The behavior still matters. Imagine that Tower A already knows <code>0C</code>, perhaps from an existing neighbour-cache entry, while the switch&#8217;s own forwarding entry for <code>0C</code> has expired. Then A can send a perfectly valid unicast frame to <code>0C</code>, and the switch may still have to flood it.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!EWRA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3ce0b6e-5f30-4336-a153-4105ec54446d_1280x720.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!EWRA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3ce0b6e-5f30-4336-a153-4105ec54446d_1280x720.svg 424w, https://substackcdn.com/image/fetch/$s_!EWRA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3ce0b6e-5f30-4336-a153-4105ec54446d_1280x720.svg 848w, https://substackcdn.com/image/fetch/$s_!EWRA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3ce0b6e-5f30-4336-a153-4105ec54446d_1280x720.svg 1272w, https://substackcdn.com/image/fetch/$s_!EWRA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3ce0b6e-5f30-4336-a153-4105ec54446d_1280x720.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!EWRA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3ce0b6e-5f30-4336-a153-4105ec54446d_1280x720.svg" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e3ce0b6e-5f30-4336-a153-4105ec54446d_1280x720.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:97248,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/213120887?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3ce0b6e-5f30-4336-a153-4105ec54446d_1280x720.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!EWRA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3ce0b6e-5f30-4336-a153-4105ec54446d_1280x720.svg 424w, https://substackcdn.com/image/fetch/$s_!EWRA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3ce0b6e-5f30-4336-a153-4105ec54446d_1280x720.svg 848w, https://substackcdn.com/image/fetch/$s_!EWRA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3ce0b6e-5f30-4336-a153-4105ec54446d_1280x720.svg 1272w, https://substackcdn.com/image/fetch/$s_!EWRA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3ce0b6e-5f30-4336-a153-4105ec54446d_1280x720.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Diagram 3. The relay tower has become a Layer 2 switch by learning where local addresses are reachable.</em></p><p>The switch now has a useful memory, but Tower A can still be stuck for a completely different reason.</p><h2>I know the IP address. I still cannot send the frame</h2><p>Suppose an application on Tower A wants to send data to:</p><pre><code><code>192.168.1.20

</code></code></pre><p>Let us say that this address belongs to Tower C.</p><p>For the moment I will also grant Tower A one piece of knowledge: it knows that <code>192.168.1.20</code> is on the same local network. How the host makes that decision belongs to IP addressing, subnet masks and routing tables, which is exactly the problem I want to pick up in the next part.</p><p>Tower A can create an IP packet for <code>192.168.1.20</code>, but our local medium still does not forward an ordinary Ethernet frame by looking at that IP address. The Ethernet frame needs a destination MAC address.</p><p>And Tower A does not know it.</p><p>This is different from the problem we just had inside the switch.</p><p><strong>How does the switch learn which MAC address is on which port?</strong></p><p>It learns from incoming frames: each frame&#8217;s <strong>source MAC address</strong> is associated with the port it arrived on.</p><p>If the destination MAC address is not yet in its forwarding table, the switch floods the frame to the other forwarding ports in the same VLAN.</p><p><strong>How does the sending host learn the MAC address for an IPv4 next hop?</strong></p><p>It uses <strong>ARP</strong>. If the mapping is not already cached, the host broadcasts an ARP request on the local network. The device with the requested IPv4 address replies with its MAC address.</p><p>The next hop is the destination host for local traffic, or a router for traffic leaving the subnet.</p><p>I like this distinction because both failures can sound like &#8220;I do not know where C is,&#8221; while they live in different machines and are solved by different mechanisms.</p><p>ARP, the Address Resolution Protocol, exists to solve the second one for IPv4.</p><h2>A local shout</h2><p>There is a bootstrapping problem, though. If Tower A does not know Tower C&#8217;s MAC address, it cannot send Tower C a normal unicast Ethernet frame asking for it.</p><p>So I need one more local address in the tower world:</p><pre><code><code>EVERYONE

</code></code></pre><p>A frame sent to <code>EVERYONE</code> is copied toward every participant in this local communication region.</p><p>Ethernet already has exactly such a destination:</p><pre><code><code>ff:ff:ff:ff:ff:ff

</code></code></pre><p>That is the Ethernet broadcast MAC address.</p><p>Tower A can now send something equivalent to:</p><pre><code><code>Who has 192.168.1.20?
Tell 192.168.1.10.

</code></code></pre><p>The Ethernet destination is the broadcast address, so the switch floods the frame through the local broadcast domain. The switch does not need to understand the IP address in the question. In the ordinary forwarding model it is still doing a Layer 2 job: it sees a broadcast destination MAC and forwards accordingly.</p><p>Inside that Ethernet frame is an ARP message. ARP is not an IP packet, and the switch does not use ARP to decide where ordinary unicast Ethernet frames should go. ARP is a separate protocol carried directly inside Ethernet, identified by EtherType <code>0x0806</code>.</p><p>Every IPv4 host in the local broadcast domain may receive the request. Most of them inspect it, notice that <code>192.168.1.20</code> is not theirs, and move on with their lives.</p><p>Tower C recognizes its own IP address and replies with its MAC address:</p><pre><code><code>192.168.1.20 is at 02:00:00:00:00:0c

</code></code></pre><p>The reply can be sent as a unicast Ethernet frame back to Tower A because the ARP request already contained A&#8217;s addresses.</p><p>That reply does two useful things in two different places. Tower A can store:</p><pre><code><code>192.168.1.20 &#8594; 02:00:00:00:00:0c

</code></code></pre><p>in its neighbour cache, while the switch sees a frame arriving from Tower C and can learn <code>02:00:00:00:00:0c &#8594; eastern port</code> from the source MAC address.</p><p>Nobody had to teach the switch about <code>192.168.1.20</code>. It still does not need that information for normal Layer 2 forwarding.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Vn4O!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F383b81cb-d78c-4b76-8529-cbd937041a79_1280x720.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Vn4O!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F383b81cb-d78c-4b76-8529-cbd937041a79_1280x720.svg 424w, https://substackcdn.com/image/fetch/$s_!Vn4O!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F383b81cb-d78c-4b76-8529-cbd937041a79_1280x720.svg 848w, https://substackcdn.com/image/fetch/$s_!Vn4O!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F383b81cb-d78c-4b76-8529-cbd937041a79_1280x720.svg 1272w, https://substackcdn.com/image/fetch/$s_!Vn4O!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F383b81cb-d78c-4b76-8529-cbd937041a79_1280x720.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!Vn4O!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F383b81cb-d78c-4b76-8529-cbd937041a79_1280x720.svg" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/383b81cb-d78c-4b76-8529-cbd937041a79_1280x720.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:182380,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/213120887?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F383b81cb-d78c-4b76-8529-cbd937041a79_1280x720.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!Vn4O!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F383b81cb-d78c-4b76-8529-cbd937041a79_1280x720.svg 424w, https://substackcdn.com/image/fetch/$s_!Vn4O!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F383b81cb-d78c-4b76-8529-cbd937041a79_1280x720.svg 848w, https://substackcdn.com/image/fetch/$s_!Vn4O!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F383b81cb-d78c-4b76-8529-cbd937041a79_1280x720.svg 1272w, https://substackcdn.com/image/fetch/$s_!Vn4O!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F383b81cb-d78c-4b76-8529-cbd937041a79_1280x720.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Diagram 4. Broadcast lets ARP discover the local MAC address associated with an IPv4 address.</em></p><p>This is the part of the experiment I find especially satisfying because we now have two small pieces of memory that look similar on paper but belong to completely different parts of the system.</p><h2>Two different maps of the same local network</h2><p>Tower A may remember:</p><pre><code><code>192.168.1.20 &#8594; 02:00:00:00:00:0c

</code></code></pre><p>That is host knowledge. On Linux it lives in the neighbour table. For IPv4, ARP is the mechanism that normally creates and refreshes this mapping.</p><p>The switch may remember:</p><pre><code><code>02:00:00:00:00:0c &#8594; eastern port

</code></code></pre><p>That is switch knowledge. It was learned from the source MAC address of a frame that arrived through the eastern port.</p><p>The two tables answer different questions:</p><p><strong>Host: IPv4 address &#8594; MAC address</strong></p><p>The host uses its ARP cache to find the MAC address of the next hop. For a destination on the local subnet, that is the destination host. For a remote destination, it is a router.</p><p>This tells the host <strong>which destination MAC address to put in the Ethernet frame</strong>.</p><p><strong>Switch: MAC address &#8594; port</strong></p><p>The switch uses its forwarding table to look up the frame&#8217;s destination MAC address.</p><p>This tells the switch <strong>which port to forward the frame through</strong>. If the destination is unknown, it floods the frame to the other ports in the same VLAN.</p><p>This also makes the MAC and IP distinction less mystical.</p><p>A MAC address is useful for delivery on the current Layer 2 network. An IP address is the logical address of the packet&#8217;s destination in the larger Layer 3 system.</p><p>When A and C are sitting in the same valley, both addresses appear to identify the same machine, so having two of them can feel redundant. The redundancy is mostly an illusion created by the small example. Once the packet has to cross a router, the reason for both becomes much clearer.</p><p>For a local destination, A may build something conceptually like this:</p><pre><code><code>Ethernet:
  dst MAC = 02:00:00:00:00:0c
  src MAC = 02:00:00:00:00:0a
  type    = IPv4

IPv4 packet inside:
  dst IP  = 192.168.1.20
  src IP  = 192.168.1.10

</code></code></pre><p>The switch cares about the Ethernet destination MAC when forwarding the frame. Tower C eventually receives the frame, sees that the payload is IPv4, and passes the enclosed IP packet upward.</p><p>The complete first exchange is therefore not one magic lookup. It is several small mechanisms cooperating:</p><pre><code><code>Application wants to send to 192.168.1.20
            &#8595;
Host decides 192.168.1.20 is local
            &#8595;
Neighbour cache has no MAC for 192.168.1.20
            &#8595;
Host sends an ARP request in an Ethernet broadcast frame
            &#8595;
Switch learns A's source MAC and floods the broadcast
            &#8595;
C recognizes its IP address and sends an ARP reply
            &#8595;
Switch learns C's source MAC from the reply
            &#8595;
A stores 192.168.1.20 &#8594; C's MAC in its neighbour cache
            &#8595;
A puts the IP packet into a unicast Ethernet frame for C's MAC
            &#8595;
Switch uses C's MAC to select the correct port
            &#8595;
C receives the frame and extracts the IP packet

</code></code></pre><p>This is a simplified path, but it is finally a simplification I can reason with. Each table has an owner. Each address has a purpose. The switch never needs to resolve <code>192.168.1.20</code>, and ARP never tells the switch which destination port to use.</p><h2>Back on a real Linux machine</h2><p>After spending enough time with imaginary towers, I wanted to see whether the same structure is visible without the analogy.</p><p>Linux exposes the host-side neighbour table with:</p><pre><code><code>ip neigh

</code></code></pre><p>For an IPv4 neighbour, an entry can look like this:</p><pre><code><code>192.168.1.20 dev eth0 lladdr 02:00:00:00:00:0c REACHABLE

</code></code></pre><p>There it is: the same <code>IPv4 address &#8594; MAC address</code> mapping that Tower A had to learn. The Linux neighbour table is more general than ARP and also contains IPv6 neighbour information, but for IPv4 on Ethernet, ARP is the mechanism we care about here.</p><p>The exchange itself is even nicer because we can watch it happen:</p><pre><code><code>sudo tcpdump -i eth0 -n -e arp

</code></code></pre><p>If <code>eth0</code> is not your actual interface name, which is very likely on a modern Linux machine because apparently <code>eth0</code> was too easy, replace it with the real interface.</p><p>With no cached neighbour entry, contacting <code>192.168.1.20</code> should first produce an ARP request sent to the Ethernet broadcast address. Then the owner of that IP replies with its MAC address. After the mapping exists, the host can send normal unicast Ethernet frames.</p><p>If the neighbour entry already exists, the absence of ARP traffic is not evidence that the mechanism disappeared. Linux is simply using what it already knows.</p><blockquote><p>&#128270; <strong>Try it yourself:</strong> run <code>ip neigh</code>, start <code>sudo tcpdump -i &lt;interface&gt; -n -e arp</code>, and then ping another machine on the same local network. If a cached entry prevents the ARP exchange from appearing, remove only that entry with <code>sudo ip neigh del &lt;IP&gt; dev &lt;interface&gt;</code> and repeat the experiment. Use a machine and network you control.</p></blockquote><p>I will stop the Linux part here. Later in Act I I want to open one host properly and look at interfaces, bridges, network namespaces, virtual Ethernet devices and the rest of the machinery Linux piles underneath an innocent socket. Here I only wanted to verify that our medieval invention leaves fingerprints on a real machine.</p><h2>Then I add another valley</h2><p>So far everybody belongs to one local communication region. Broadcast can reach the whole group, and one Layer 2 system is enough.</p><p>Then I put another valley behind the mountains.</p><p>It has its own towers, its own local relay, its own broadcasts and its own local MAC addresses. Tower A cannot simply shout an ARP request across the mountains and expect all of Europe to participate.</p><p>Still, Tower A needs to send a message there.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MGcI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb9c3341-23c6-4b73-8265-d1666a070d38_1280x720.svg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MGcI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb9c3341-23c6-4b73-8265-d1666a070d38_1280x720.svg 424w, https://substackcdn.com/image/fetch/$s_!MGcI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb9c3341-23c6-4b73-8265-d1666a070d38_1280x720.svg 848w, https://substackcdn.com/image/fetch/$s_!MGcI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb9c3341-23c6-4b73-8265-d1666a070d38_1280x720.svg 1272w, https://substackcdn.com/image/fetch/$s_!MGcI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb9c3341-23c6-4b73-8265-d1666a070d38_1280x720.svg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!MGcI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb9c3341-23c6-4b73-8265-d1666a070d38_1280x720.svg" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/eb9c3341-23c6-4b73-8265-d1666a070d38_1280x720.svg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:115640,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/svg+xml&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.softwareinthegrid.com/i/213120887?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb9c3341-23c6-4b73-8265-d1666a070d38_1280x720.svg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!MGcI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb9c3341-23c6-4b73-8265-d1666a070d38_1280x720.svg 424w, https://substackcdn.com/image/fetch/$s_!MGcI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb9c3341-23c6-4b73-8265-d1666a070d38_1280x720.svg 848w, https://substackcdn.com/image/fetch/$s_!MGcI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb9c3341-23c6-4b73-8265-d1666a070d38_1280x720.svg 1272w, https://substackcdn.com/image/fetch/$s_!MGcI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb9c3341-23c6-4b73-8265-d1666a070d38_1280x720.svg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Diagram 5. The local-network model stops being sufficient when the destination belongs to another network.</em></p><p>This is where my local-network model finally runs out of road.</p><p>I could try to connect both valleys into one gigantic Layer 2 domain and let broadcasts spread farther and farther. Then I could keep adding valleys until one ARP request lights half the continent. Apart from being a rather beautiful medieval spectacle, it would also turn every local broadcast into everybody else&#8217;s problem.</p><p>The cleaner solution is to let each valley remain a local network and introduce a machine that knows how to move packets between networks.</p><p>That machine is a router.</p><p>And here the two-address idea starts paying rent.</p><p>If Tower A wants to send an IP packet to a host in the remote valley, the packet can keep the remote host as its IP destination. But the Ethernet frame used in A&#8217;s local valley is not addressed to that distant machine. It is addressed to the local router, the next machine that can move the packet closer to where it belongs.</p><p>Conceptually:</p><pre><code><code>IP destination:       remote host in another valley
Ethernet destination: local router

</code></code></pre><p>The router receives the local frame, removes that Layer 2 envelope, examines the IP packet, chooses the next route, and places the packet into a new Layer 2 frame appropriate for the next link.</p><p>This is the point where the medieval analogy also needs a new piece. A relay inside one valley was enough while everybody shared one local addressing and broadcast system. Communication between valleys requires a gateway that understands something larger than local tower addresses.</p><p>That larger system is what I want to rebuild in Part 2: IP addresses, subnet masks, the decision that a destination is local or remote, default gateways, routing tables and routers.</p><p>The towers got us surprisingly far, but the mountains finally forced us into Layer 3.</p><p>Continue with <a href="https://www.softwareinthegrid.com/p/networking-machinery-for-software-f6b">Part 2: Extending the Empire and Rebuilding a Global Network</a>, where a second valley forces us to introduce IP addresses, prefixes, gateways, and routing.</p><p>Local delivery is one part of the story. If your next question is how applications protect the data they send, <a href="https://www.softwareinthegrid.com/p/rebuilding-tls-from-scratch-my-complete">Rebuilding TLS From Scratch</a> follows a TCP connection from encryption alone to integrity, key exchange, and authentication.</p><p>Subscribe to Software in the Grid to follow this network from local Ethernet delivery through IP routing and into Linux, then onward to the power grid.</p><h2>Next Part:</h2><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;0e34dc08-ff68-4d90-969b-159d042d9b47&quot;,&quot;caption&quot;:&quot;Previous Article:&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Networking Machinery for Software Engineers Part 2: Extending The Empire and Rebuilding a Global Network&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer in the energy sector. I publish Software in the Grid, exploring how software works inside modern power infrastructure.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-09-02T16:02:36.253Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!JAas!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d96a595-7108-43f7-92b7-4c57c97c5f2a_1672x941.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/networking-machinery-for-software-f6b&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:213862386,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div><hr></div><h2><strong>Series Hub</strong></h2><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;87c3ae4d-7e1f-4f1b-b7e8-8b5292d5328a&quot;,&quot;caption&quot;:&quot;I have worked with networked software for years, but for most of that time the network was something I used rather than something I really understood. I could open a socket, call an API, connect to an IP address, and continue with the part of the system I was responsible for.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;md&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Networking in the Power Grid for Software Developers&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer exploring how complex systems are built. I take them apart, rebuild them from first principles, and trace the layers connecting software, networks, infrastructure, devices, and the physical world.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-08-27T21:18:02.367Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!sXgD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2f83a8-82b3-42d5-817b-5266707341bb_1672x941.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/networking-in-the-power-grid-for&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:213058272,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!JM5w!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2f89608f-4575-4fe4-9df4-7d6a25e088b2_1254x1254.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><h2>References and further reading</h2><ul><li><p><a href="https://datatracker.ietf.org/doc/html/rfc826">RFC 826: An Ethernet Address Resolution Protocol</a></p></li><li><p><a href="https://www.ieee802.org/3/">IEEE 802.3 Ethernet Working Group</a></p></li><li><p><a href="https://man7.org/linux/man-pages/man8/ip-neighbour.8.html">Linux ip-neighbour manual</a></p></li><li><p><a href="https://docs.kernel.org/networking/tuntap.html">Linux kernel TUN/TAP documentation</a>, useful later when we rebuild networking machinery inside one Linux host</p></li><li><p><a href="https://www.softwareinthegrid.com/p/a-developers-map-of-the-european">A Developer&#8217;s Map of the European Power Grid</a>, the wider series context for software developers entering the energy domain</p></li></ul>]]></content:encoded></item><item><title><![CDATA[Networking Machinery for Software Engineers]]></title><description><![CDATA[Building the networking foundation needed to understand substations, SCADA, industrial protocols, and software in the power grid.]]></description><link>https://www.softwareinthegrid.com/p/networking-in-the-power-grid-for</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/networking-in-the-power-grid-for</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Thu, 27 Aug 2026 21:18:02 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!sXgD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2f83a8-82b3-42d5-817b-5266707341bb_1672x941.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sXgD!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2f83a8-82b3-42d5-817b-5266707341bb_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sXgD!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2f83a8-82b3-42d5-817b-5266707341bb_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!sXgD!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2f83a8-82b3-42d5-817b-5266707341bb_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!sXgD!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2f83a8-82b3-42d5-817b-5266707341bb_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!sXgD!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2f83a8-82b3-42d5-817b-5266707341bb_1672x941.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sXgD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2f83a8-82b3-42d5-817b-5266707341bb_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ea2f83a8-82b3-42d5-817b-5266707341bb_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2435372,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/213058272?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2f83a8-82b3-42d5-817b-5266707341bb_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!sXgD!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2f83a8-82b3-42d5-817b-5266707341bb_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!sXgD!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2f83a8-82b3-42d5-817b-5266707341bb_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!sXgD!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2f83a8-82b3-42d5-817b-5266707341bb_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!sXgD!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fea2f83a8-82b3-42d5-817b-5266707341bb_1672x941.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>I have worked with networked software for years, but for most of that time the network was something I used rather than something I really understood. I could open a socket, call an API, connect to an IP address, and continue with the part of the system I was responsible for.</p><p>When I started working closer to the power grid, this became uncomfortable. Network details were no longer hidden somewhere below the application. Ethernet frames, multicast, VLANs, gateways, industrial protocols, and utility networks appeared directly in requirements and discussions.</p><p>The difficult part was not learning what each term meant. I could read a definition of ARP or a description of a routing table. The problem was seeing how all these mechanisms formed one system, and then seeing how that system was used by substations, protection devices, control centers, and remote engineering tools.</p><p>This series is my attempt to build that connected picture. I want to begin with ordinary network machinery, reconstruct enough of it in Linux to make it tangible, and in next series follow it into the power grid.</p><p>My goal is to create a solid deep understanding of the network that could be used as a foundation to further grid related topics.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.softwareinthegrid.com/subscribe?"><span>Subscribe now</span></a></p><h2>Networking machinery for software engineers</h2><p>In this series I want to fill the gaps in my own networking foundation. We start with the smallest useful network: two machines, a physical link, and a switch. From there we can see how Ethernet frames move, how hosts learn MAC addresses, and why ARP exists.</p><p>The first part begins at Layer 1, or L1. Copper and fiber carry electrical or optical signals, while Ethernet gives those signals a frame structure and an addressing model at Layer 2. I do not plan to turn this into an electronics course, but the physical layer matters because every packet eventually depends on a real medium, a negotiated link, and hardware that can fail.</p><p>Next, we break the local-network assumption by placing the destination somewhere else. This introduces gateways and routing for a concrete reason. </p><p>Only after those ideas are visible from the outside do we open a Linux host and find the interfaces, neighbor table, routes, techniques and objects that implements them.</p><p>Linux comes last for a reason. Once the external network is clear, a single computer can reproduce it. Namespaces become hosts, <code>veth</code> pairs become links, a bridge becomes a switch, and a forwarding namespace becomes a router. That gives us a laboratory for the rest of the series.</p><div><hr></div><h3>Part 1: How Local Networks Work</h3><p><strong>Layer 1, Ethernet, MAC addresses, switches, and ARP</strong></p><p>We will connect two hosts on one local network and follow a message from the physical link upward. The main question is deceptively simple: what has to happen before one machine can send an Ethernet frame to another?</p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;c581391f-70fa-4b5c-aead-abc5d49a6737&quot;,&quot;caption&quot;:&quot;Recently I started working on a networking series for software developers who enter the electrical-grid world and suddenly discover that the grid speaks in packets, interfaces, switches, routes, protocols and a suspicious number of acronyms.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Networking Machinery for Software Engineers\nPart 1: Rebuilding a Local Network with Medieval Signal Towers&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer exploring how complex systems are built. I take them apart, rebuild them from first principles, and trace the layers connecting software, networks, infrastructure, devices, and the physical world.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-08-28T09:48:20.438Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!Xg26!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F81428888-7e1b-4174-8ad1-092e46214718_1672x941.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/networking-machinery-for-software&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:213120887,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div><hr></div><h3>Part 2: How Packets Travel Between Networks</h3><p><strong>IP addresses, subnet masks, gateways, routing tables, and routers</strong></p><p>The destination now moves outside the local network. We will follow the packet through the host&#8217;s routing decision, the default gateway, and the router that connects the two sides.</p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;b741031e-46e4-4481-958b-80a05487559b&quot;,&quot;caption&quot;:&quot;Previous Article:&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Networking Machinery for Software Engineers Part 2: Extending The Empire and Rebuilding a Global Network&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer exploring how complex systems are built. I take them apart, rebuild them from first principles, and trace the layers connecting software, networks, infrastructure, devices, and the physical world.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-09-02T16:02:36.253Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!JAas!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0d96a595-7108-43f7-92b7-4c57c97c5f2a_1672x941.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/networking-machinery-for-software-f6b&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:213862386,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div><hr></div><h3>Part 3: Inside the Linux Networking Stack</h3><h4>Understanding how Linux receives and processes network traffic</h4><p>In this post we will discuss the Linux networking stack by following one machine as its networking state evolves. We will see how Kernel implement all machinery that we discussed in the previous articles. </p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;4bac16a3-2dda-45bb-b2b5-bdb7145c0abd&quot;,&quot;caption&quot;:&quot;Previous part:&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Networking Machinery for Software Engineers Part 3: Inside the Linux Networking Stack&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer in the energy sector. I publish Software in the Grid, exploring how software works inside modern power infrastructure.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-10-03T17:58:46.849Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!xaga!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55e49167-4d3a-482a-ae8d-af5c40454628_1672x941.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/inside-the-linux-networking-stack&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:218666073,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:1,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div><hr></div><h3>Part 4: Rebuilding a Network Inside One Linux Machine</h3><p><strong>Namespaces, </strong><code>veth</code><strong>, bridges, routing and packet inspection</strong></p><p>Namespaces become hosts, <code>veth</code> pairs become links, a bridge becomes a switch, and a forwarding namespace becomes a router. </p><p>The objective is to reproduce the concepts from the previous articles inside one machine and create a laboratory where we can inspect every interface, route, neighbour entry and packet.</p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;37b3b589-815d-4193-b0a6-5bc03375e7ea&quot;,&quot;caption&quot;:&quot;Previous Article:&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Networking Machinery for Software Engineers Part 4: Rebuilding a Network Inside One Linux Machine&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer in the energy sector. I publish Software in the Grid, exploring how software works inside modern power infrastructure.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-10-17T20:33:10.640Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!7DWE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76d0fb2a-9816-4860-b7bb-2d139b51347a_1672x941.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/networking-machinery-for-software-323&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:220904040,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div><hr></div><h2>What this series should make possible</h2><p>My target is fairly modest: I want the network below an application to become something I can inspect and reason about.</p><p>When I see an unfamiliar architecture, I want to identify the local-network boundaries, understand why a packet follows a particular gateway, recognise where multicast is being used, and know which Linux tools can confirm my assumptions. </p><p>That level of understanding will not make me a protection engineer or a utility network architect. It should, however, make the conversations with those specialists much more useful and make network-related failures less mysterious.</p><h2>Follow the series</h2><p>I will use this page as the index for the whole project. As each article is published, I will replace its status with a direct link and update the plan if the investigation takes a different direction.</p><p>I am learning this subject in public. If you work with industrial networks, IEC 61850, utility communications, or Linux networking and notice that I have missed something, I would be glad to hear from you.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">You can subscribe to receive the next part.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item><item><title><![CDATA[Where Software Lives in the Power Grid]]></title><description><![CDATA[This article maps the software ecosystem of the power grid and gives software engineers a mental model for understanding where different systems fit and how they work together.]]></description><link>https://www.softwareinthegrid.com/p/where-software-lives-in-the-power</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/where-software-lives-in-the-power</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Tue, 04 Aug 2026 12:00:12 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!VcpN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d167517-6038-47fa-9548-a22e9beba2c7_1536x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!VcpN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d167517-6038-47fa-9548-a22e9beba2c7_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!VcpN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d167517-6038-47fa-9548-a22e9beba2c7_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!VcpN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d167517-6038-47fa-9548-a22e9beba2c7_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!VcpN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d167517-6038-47fa-9548-a22e9beba2c7_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!VcpN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d167517-6038-47fa-9548-a22e9beba2c7_1536x1024.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!VcpN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d167517-6038-47fa-9548-a22e9beba2c7_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6d167517-6038-47fa-9548-a22e9beba2c7_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2677087,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/209770599?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d167517-6038-47fa-9548-a22e9beba2c7_1536x1024.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!VcpN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d167517-6038-47fa-9548-a22e9beba2c7_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!VcpN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d167517-6038-47fa-9548-a22e9beba2c7_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!VcpN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d167517-6038-47fa-9548-a22e9beba2c7_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!VcpN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d167517-6038-47fa-9548-a22e9beba2c7_1536x1024.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Previous part:</em></p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;5dbd4aef-0513-436d-9709-5517d9a6d2a9&quot;,&quot;caption&quot;:&quot;Previous part:&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;How Europe&#8217;s Power System Is Organised&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer exploring how complex systems are built. I take them apart, rebuild them from first principles, and trace the layers connecting software, networks, infrastructure, devices, and the physical world.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-08-01T19:35:39.907Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!EXqg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ceb4d81-13de-47cf-9bab-d2f435ac5657_1672x941.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/how-europes-power-system-is-organised&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:209412144,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:3,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:false,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><blockquote><p><em><span>&#8220;The metasphere remains. But it is more wilderness than ever now. Black forests of unknown time and space. Sounds in the night. Lions. And tigers. And bears.&#8221;</span></em> &#8213; Dan Simmons, <em><span>Hyperion</span></em></p></blockquote><p></p><p>Where does software live in the grid?</p><p>It lives between, within and above.</p><p>For most of <a href="https://www.softwareinthegrid.com/p/a-developers-map-of-the-european">this series</a>, I was looking at the physical world. Generators produce electricity, transformers change voltage, transmission lines connect regions, and substations switch and protect all of it. These things have weight, occupy space and can be found on a map.</p><p>But during my research I slowly realised that there is another world hiding inside this one.</p><p>Software lives inside protection relays and control-room servers. It lives between devices, companies and countries. It stretches above cables and transformers as measurements, alarms, schedules, forecasts, bids and models. Almost every hollow space that is not fulfilled by the physical world hides another piece of software.</p><p>And it does not only observe the industry. It moves it. Software opens breakers, reconstructs the state of the grid, predicts tomorrow&#8217;s demand, accepts bids, calculates prices, activates reserves and later calculates who owes money to whom because reality did not follow the plan.</p><p>For me, it looks like a huge augmented reality built on top of the grid. At some point it becomes difficult to decide which reality is primary. Electricity still follows physics, but more and more of what happens around it is decided, coordinated and recorded in software.</p><p>It felt like discovering another continent.</p><p>I do not want to pretend that I can produce its Google Map. What I can draw is closer to the maps of Herodotus, collected from documents, conversations, tools I met at work and stories from people who travelled further than I did. It will contain blank places and probably a few sea monsters, but it should still be enough to understand where we are.</p><p>And AI, for better or worse, has been my Virgil during this journey.</p><p>In this post we will discuss three large software worlds: the software that operates the physical grid, the software that operates the electricity market, and the software that connects financial plans with physical reality.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dJzO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e519c4-bc8b-4e35-8c29-a8e22620fe9e_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dJzO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e519c4-bc8b-4e35-8c29-a8e22620fe9e_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!dJzO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e519c4-bc8b-4e35-8c29-a8e22620fe9e_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!dJzO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e519c4-bc8b-4e35-8c29-a8e22620fe9e_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!dJzO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e519c4-bc8b-4e35-8c29-a8e22620fe9e_1536x1024.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!dJzO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e519c4-bc8b-4e35-8c29-a8e22620fe9e_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/12e519c4-bc8b-4e35-8c29-a8e22620fe9e_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2532589,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/209770599?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e519c4-bc8b-4e35-8c29-a8e22620fe9e_1536x1024.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dJzO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e519c4-bc8b-4e35-8c29-a8e22620fe9e_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!dJzO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e519c4-bc8b-4e35-8c29-a8e22620fe9e_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!dJzO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e519c4-bc8b-4e35-8c29-a8e22620fe9e_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!dJzO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e519c4-bc8b-4e35-8c29-a8e22620fe9e_1536x1024.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 1. Three software worlds of the grid. Their borders are not clean, but their main purposes are different.</em></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.softwareinthegrid.com/subscribe?"><span>Subscribe now</span></a></p><h2>Software that operates the physical grid</h2><p>This is the software closest to copper, steel and electromagnetic fields.</p><p>A breaker does not know that it is called <code>Q0</code>. A current transformer does not produce a neat object with a timestamp and a quality flag. The physical world gives us voltage, current, heat, motion and consequences. Software turns them into information that people and other systems can use.</p><p>The first computers we meet are <strong>Intelligent Electronic Devices</strong>, usually shortened to IEDs. This family includes protection relays, bay controllers, merging units and meters.</p><p>A <strong>protection relay</strong> watches electrical quantities and reacts when they indicate a fault. It may detect overcurrent, an abnormal frequency or a fault inside a transformer and send a trip command before a remote operator could even understand what happened.</p><p>A <strong>bay controller</strong> supervises breakers, disconnectors and earthing switches around one part of a substation. A <strong>merging unit</strong> digitises current and voltage measurements. A <strong>meter</strong> measures energy or power for operational and commercial use.</p><p>Above these devices sits the <strong>substation automation system</strong>. Its visible part is often a local HMI with a single-line diagram, measurements, alarms and controls. Behind it are gateways, Remote Terminal Units (RTU), event recorders, engineering tools and configuration files. The substation is already a distributed software system, only with unusually expensive outputs.</p><p>Communication inside a modern substation is often organised around <strong><a href="https://webstore.iec.ch/en/publication/105222">IEC 61850</a></strong>.</p><p>At first, it is tempting to think of IEC 61850 as just another network protocol, similar to HTTP or Modbus. But it is much broader than that. It is a common language for describing the devices, measurements, commands and protection functions inside a power-system automation system.</p><p>For example, different vendors may build protection relays in very different ways, but IEC 61850 gives them a shared model for concepts such as circuit breakers, voltage measurements, alarms and trip signals. This makes it easier for devices and engineering tools from different manufacturers to understand each other.</p><p>IEC 61850 also defines several ways in which these devices communicate. <strong>MMS</strong> is commonly used when one system needs to read data from another device, receive reports or send a control command. <strong>GOOSE</strong> is used for very fast messages between devices, for example when one protection relay must immediately tell another device to trip a breaker. <strong>Sampled Values</strong> are used to send digitised current and voltage measurements over the station network.</p><p>The standard also includes <strong>SCL</strong>, or Substation Configuration Language. SCL files describe which devices exist in the substation, what data they provide, how they are connected and how they communicate. In other words, IEC 61850 defines not only how messages travel, but also what those messages mean and how the whole system is engineered.</p><p>Communication between a substation and a remote control centre often uses another standard called <strong><a href="https://webstore.iec.ch/en/publication/25035">IEC 60870-5-104</a></strong>, usually shortened to <strong>IEC 104</strong>.</p><p>Its role is easier to imagine. A gateway or Remote Terminal Unit inside the substation gathers selected information from local devices and sends it to the control centre. This can include voltage and power measurements, breaker positions, alarms and events. The control centre can then send commands back, for example to open or close a breaker.</p><p>A simple mental model is this: IEC 61850 is often used to organise communication inside the substation, while IEC 104 is often used to connect the substation with the control centre.</p><p>There are many other protocols, including DNP3, Modbus and OPC UA. There are also decades of legacy equipment and vendor-specific behaviour, because standards can reduce chaos but apparently cannot eliminate human creativity.</p><p>At the control centre, <strong>SCADA</strong> collects telemetry, displays the current state, processes alarms and lets authorised operators issue commands. It is the operational window into the grid.</p><p>For transmission operators, SCADA is often surrounded by an <strong>Energy Management System</strong>, or EMS. The EMS runs applications such as state estimation, power-flow calculation and contingency analysis. State estimation combines measurements with a network model and calculates the most plausible state of the system. Contingency analysis asks what would happen if a line, transformer or generator disappeared.</p><p>Distribution operators use similar families of software, often called <strong>DMS</strong> or <strong>ADMS</strong>, to supervise distribution networks, manage outages, estimate states and increasingly coordinate distributed generation, batteries and flexible loads.</p><p>Around all of this sit historians, alarm systems, disturbance recorders, outage tools, switching-management systems and dispatcher training simulators. Each solves a different problem, but together they perform one purpose: they let humans observe, understand and control a physical system that is far too large and fast to operate directly.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JnSa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4862113-5ca8-4215-8b39-22f2567e4781_1774x887.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JnSa!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4862113-5ca8-4215-8b39-22f2567e4781_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!JnSa!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4862113-5ca8-4215-8b39-22f2567e4781_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!JnSa!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4862113-5ca8-4215-8b39-22f2567e4781_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!JnSa!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4862113-5ca8-4215-8b39-22f2567e4781_1774x887.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!JnSa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4862113-5ca8-4215-8b39-22f2567e4781_1774x887.png" width="1456" height="728" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e4862113-5ca8-4215-8b39-22f2567e4781_1774x887.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:728,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2069100,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/209770599?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4862113-5ca8-4215-8b39-22f2567e4781_1774x887.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!JnSa!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4862113-5ca8-4215-8b39-22f2567e4781_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!JnSa!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4862113-5ca8-4215-8b39-22f2567e4781_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!JnSa!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4862113-5ca8-4215-8b39-22f2567e4781_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!JnSa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4862113-5ca8-4215-8b39-22f2567e4781_1774x887.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 2. A simplified path from physical equipment to the operator. Measurements travel to the right, while decisions and commands travel back.</em></p><h2>Software that operates the electricity market</h2><p>The market lives in a different world.</p><p>It does not normally open breakers or read raw current samples. It works with products, bids, schedules, contracts, positions and money. Still, it cannot completely escape physics, because the product it trades must be generated, transported and consumed at a specific time.</p><p>The process usually starts with <strong>forecasting and analytics</strong>. Generators forecast their available production. Suppliers and balance responsible parties forecast consumption. Traders forecast prices, weather and the behaviour of everybody else who is also forecasting prices, weather and the behaviour of traders. There is a pleasing circularity to the whole exercise.</p><p>These forecasts enter <strong>trading and bidding systems</strong>. Market participants prepare orders for forward, day-ahead, intraday and balancing markets. The software checks limits, builds bidding strategies, submits orders and records the results.</p><p>At the exchange side, market systems collect bids and offers. In the European day-ahead and intraday markets, market coupling allocates cross-zonal capacity together with energy orders. The <a href="https://www.acer.europa.eu/electricity/market-rules/capacity-allocation-and-congestion-management">Capacity Allocation and Congestion Management rules</a> define the framework for this process. The algorithm does not simply find a buyer for every seller. It tries to maximise economic surplus while respecting the capacity available between bidding zones.</p><p>Once the market clears, the result becomes a schedule. Generators know how much they should produce, suppliers know what they bought, and balance responsible parties have a position that they must later defend against reality.</p><p>Large participants commonly use <strong>Energy Trading and Risk Management systems</strong>, or ETRM. These systems keep track of trades, contracts, portfolios, exposure, nominations, collateral and settlement. They are the commercial memory of the company.</p><p>After delivery, <strong>metering and settlement systems</strong> compare contracted quantities, schedules and measured energy. They calculate invoices, fees and later the cost of imbalances. The market therefore does not end when the price is published. It ends much later, when the final numbers agree enough that money can move.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!M-bP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c1b5e5b-4bfd-4fa7-bb90-5f925ff12627_1774x887.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!M-bP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c1b5e5b-4bfd-4fa7-bb90-5f925ff12627_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!M-bP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c1b5e5b-4bfd-4fa7-bb90-5f925ff12627_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!M-bP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c1b5e5b-4bfd-4fa7-bb90-5f925ff12627_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!M-bP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c1b5e5b-4bfd-4fa7-bb90-5f925ff12627_1774x887.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!M-bP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c1b5e5b-4bfd-4fa7-bb90-5f925ff12627_1774x887.png" width="1456" height="728" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3c1b5e5b-4bfd-4fa7-bb90-5f925ff12627_1774x887.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:728,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1996274,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/209770599?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c1b5e5b-4bfd-4fa7-bb90-5f925ff12627_1774x887.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!M-bP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c1b5e5b-4bfd-4fa7-bb90-5f925ff12627_1774x887.png 424w, https://substackcdn.com/image/fetch/$s_!M-bP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c1b5e5b-4bfd-4fa7-bb90-5f925ff12627_1774x887.png 848w, https://substackcdn.com/image/fetch/$s_!M-bP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c1b5e5b-4bfd-4fa7-bb90-5f925ff12627_1774x887.png 1272w, https://substackcdn.com/image/fetch/$s_!M-bP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c1b5e5b-4bfd-4fa7-bb90-5f925ff12627_1774x887.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 3. The commercial loop. A forecast becomes a bid, the bid becomes a schedule, and physical delivery eventually returns as money and new data.</em></p><h2>Software that connects both worlds</h2><p>The third area is where the article becomes especially interesting for me.</p><p>A market participant can create a good schedule. A control centre can observe the real grid. Neither is enough alone. Somebody must continuously compare the planned world with the physical one and decide what to do when they differ.</p><p>This is one of the main software responsibilities of a Transmission System Operator.</p><p>A TSO receives schedules, forecasts and availability information from market participants. At the same time, SCADA and EMS show what the system is actually doing. The TSO compares the two realities and checks whether the grid can safely carry the planned flows.</p><p>This area contains <strong>load and generation forecasting</strong>, <strong>scheduling systems</strong>, <strong>network models</strong>, <strong>capacity-calculation tools</strong>, <strong>congestion-management tools</strong> and <strong>operational-security analysis</strong>. European TSOs also exchange their individual grid models and combine them into a Common Grid Model through shared infrastructure such as the Operational Planning Data Environment. It is software used not merely by one company, but to construct a common view of an interconnected continent.</p><p>When expected flows violate limits, TSOs may use remedial actions such as changing generation, modifying topology, redispatching power or countertrading. When production and consumption diverge in real time, balancing software procures and activates reserves.</p><p>Some control happens almost automatically. Frequency Containment Reserves respond quickly to frequency deviations. Automatic and manual Frequency Restoration Reserves bring the system back toward its target. European platforms such as <a href="https://www.entsoe.eu/network_codes/eb/picasso/">PICASSO</a> for aFRR and <a href="https://www.entsoe.eu/network_codes/eb/mari/">MARI</a> for mFRR coordinate the exchange of balancing energy between TSOs.</p><p>Afterwards, imbalance-calculation and settlement systems compare the final measured position of each balance responsible party with its schedule. The physical deviation becomes a financial result.</p><p>This is the point where the two worlds finally meet. A forecast becomes a bid, a bid becomes a schedule, a schedule becomes a power flow, a power flow becomes a frequency deviation, and the deviation eventually becomes an invoice.</p><p>The grid and the market are not separate systems. They are two models of the same reality, connected by a large amount of software and by the stubborn requirement that, in every moment, production and consumption still have to match.</p><h2>Regulation is part of the architecture</h2><p>In most software projects, requirements begin with a customer, a product manager or somebody who has discovered a new button they urgently need.</p><p>In the grid, a requirement may have started years earlier in an EU regulation.</p><p>The chain roughly looks like this:</p><p><code>EU legislation &#8594; Network Codes and Guidelines &#8594; ACER and national regulators &#8594; national laws, tariffs and approved methodologies &#8594; company processes and technical requirements &#8594; software behaviour, interfaces and audit trails</code></p><p>For system operation, the <a href="https://eur-lex.europa.eu/eli/reg/2017/1485/oj/eng">System Operation Guideline, Regulation (EU) 2017/1485</a>, defines rules around operational security, coordination, data exchange and planning between TSOs, DSOs and significant grid users.</p><p>For balancing, the <a href="https://eur-lex.europa.eu/eli/reg/2017/2195">Electricity Balancing Guideline, Regulation (EU) 2017/2195</a>, establishes common principles for procuring, activating and settling reserves.</p><p>For day-ahead and intraday markets, the CACM framework defines how capacity calculation and market coupling should work across Europe.</p><p>Technical standards sit beside these legal layers. IEC 61850 shapes data models and communication inside utility automation. IEC 104 defines a common telecontrol path. Other standards define cybersecurity, grid-model exchange, metering, testing and many other details that developers eventually meet as requirements.</p><p>There is still room for architecture, design and creativity, but not every behaviour is free to invent. A configuration field may exist because a standard requires it. An audit trail may exist because an operator must later prove who issued a command. A market interface may have a strange deadline because an approved methodology defines a gate-closure time.</p><p>This was one of the most important discoveries for me. Regulation does not sit somewhere outside the software. It slowly flows down through organisations until it becomes a database field, a validation rule, a protocol message or a test case.</p><h2>A map, not an encyclopedia</h2><p>My goal was not to create the full catalogue of all software, protocols and standards used in the grid. That catalogue would be enormous and, more importantly, almost unreadable.</p><p>I wanted to draw a mental map that gives you an impression and a raw feeling of what exists, why it exists and where your own software takes its place.</p><p>The map has three large regions.</p><p>Operation and control software turns physical processes into measurements, alarms, models and commands.</p><p>Market software turns forecasts and electricity into bids, schedules, contracts and prices.</p><p>Coordination software stands between them and compares the planned world with the real one until they agree, or at least disagree within limits that the grid can survive.</p><p>Regulation and standards cover all three. They define many of the roads, borders and languages through which these systems communicate.</p><p>This is still not Google Maps. It is closer to Herodotus, with incomplete coastlines and unknown territory beyond the edge. But now, when I meet a new protocol, algorithm or application at work, I at least understand on which part of the continent I have landed.</p><p>In the future I want to visit some of these places properly. I would like to rebuild substation communication, follow a signal from a relay to a control centre, reconstruct a market-clearing algorithm, and understand how one planned megawatt becomes an imbalance and finally money.</p><p>The next topics will probably be defined by the problems I face in my current position and by questions from people who read this series. That feels like the most honest way to continue the journey.</p><p>The next investigation has begun in <a href="https://www.softwareinthegrid.com/p/networking-in-the-power-grid-for">Networking in the Power Grid for Software Developers</a>. Start with <a href="https://www.softwareinthegrid.com/p/networking-machinery-for-software">Part 1: Rebuilding a Local Network with Medieval Signal Towers</a> to reconstruct Ethernet, switching, and ARP before following the network toward substations and control centres.</p><p>And may the Force be with you.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Subscribe to follow the connections between grid software and the physical system, starting with the networks that carry measurements and commands.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p><em>All parts of the series:</em></p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;b8ec3c38-ff02-4ecb-b288-2cfd1ea575bb&quot;,&quot;caption&quot;:&quot;I have spent a lot of time learning technical systems by rebuilding them from first principles.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;A Developer&#8217;s Map of the European Power Grid&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer exploring how complex systems are built. I take them apart, rebuild them from first principles, and trace the layers connecting software, networks, infrastructure, devices, and the physical world.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-05-12T15:14:05.930Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!r2v5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b47f174-07bd-435f-9c8c-363edb0adbfd_1491x1055.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/a-developers-map-of-the-european&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:197363882,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div>]]></content:encoded></item><item><title><![CDATA[How Europe’s Power System Is Organised]]></title><description><![CDATA[The EU electricity sector is not one company moving electricity from power plants to consumers. It is a regulated system of different actors whose responsibilities overlap without becoming identical.]]></description><link>https://www.softwareinthegrid.com/p/how-europes-power-system-is-organised</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/how-europes-power-system-is-organised</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Sat, 01 Aug 2026 19:35:39 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!EXqg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ceb4d81-13de-47cf-9bab-d2f435ac5657_1672x941.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!EXqg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ceb4d81-13de-47cf-9bab-d2f435ac5657_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!EXqg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ceb4d81-13de-47cf-9bab-d2f435ac5657_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!EXqg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ceb4d81-13de-47cf-9bab-d2f435ac5657_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!EXqg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ceb4d81-13de-47cf-9bab-d2f435ac5657_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!EXqg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ceb4d81-13de-47cf-9bab-d2f435ac5657_1672x941.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!EXqg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ceb4d81-13de-47cf-9bab-d2f435ac5657_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9ceb4d81-13de-47cf-9bab-d2f435ac5657_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2534044,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/209412144?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ceb4d81-13de-47cf-9bab-d2f435ac5657_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!EXqg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ceb4d81-13de-47cf-9bab-d2f435ac5657_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!EXqg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ceb4d81-13de-47cf-9bab-d2f435ac5657_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!EXqg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ceb4d81-13de-47cf-9bab-d2f435ac5657_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!EXqg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ceb4d81-13de-47cf-9bab-d2f435ac5657_1672x941.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-tqxFUX" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-tqxFUX" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Previous part:</em></p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;26bb46c6-4d8a-47e3-b924-a19f040fd8d5&quot;,&quot;caption&quot;:&quot;Previous part:&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;How the European Grid Stays Stable&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer exploring how complex systems are built. I take them apart, rebuild them from first principles, and trace the layers connecting software, networks, infrastructure, devices, and the physical world.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-07-20T07:02:23.698Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!z1Qz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90a438ee-e618-41a8-9933-cc1dfcf1dcb2_1672x941.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/how-the-european-grid-stays-stable&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:207691626,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:1,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:false,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><p>I was new to the electricity sector as a software engineer. I came into the industry from web development.</p><p>The web was a pretty straightforward world. I usually knew for whom and why we developed a solution. Even when the software was highly technical, it was still clear who used it and who paid for it.</p><p>When I came into energy, everything was different.</p><p>Customers, users, regulators, and all possible three-letter abbreviations that meant companies, agencies, markets, services, and roles. It was hard to understand who actually bought the software. Who used it. Who paid for it. Who paid if something went wrong. Who defined how it should work. Who checked that it worked as it should.</p><p>And many... no. <strong>A LOT</strong> of other &#8220;who&#8221; and &#8220;why&#8221; questions.</p><p>Not knowing these answers might be acceptable in another industry. In energy, the structure of the sector shapes the architecture of the software. It defines requirements and explains why those requirements exist. A feature that looks strange from a purely technical perspective may be necessary because the customer must fulfil a legal, operational, market, security, or reporting obligation.</p><p>The person using the software may not be the person buying it. The company buying it may not be the organisation that defined the requirement. The asset owner may not be the system operator. The party that loses money when something fails may not be the party that approved the budget.</p><p>I am writing this article for colleagues who entered energy from other fields and are still trying to understand how the whole system fits together. By the end, you should have a clear mental model showing who owns the assets, who operates the power system, who buys and sells electricity, where the money comes from, and who defines the rules.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.softwareinthegrid.com/subscribe?"><span>Subscribe now</span></a></p><h2>Regulation created the structure</h2><p>Laws, regulations, network codes, national rules, licences, and agreements define the main actors of the electricity sector and the way they interact. Therefore, regulation is not a separate layer added on top of an already existing market. It is one of the main forces that created the current structure.</p><p>The common EU framework is primarily established by the <a href="https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32019L0944">Electricity Directive, Directive (EU) 2019/944</a>, and the <a href="https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32019R0943">Electricity Regulation, Regulation (EU) 2019/943</a>. Together, they define common principles for generation, transmission, distribution, storage, supply, consumer participation, system operation, and electricity markets.</p><p>These documents are not implementation manuals for software engineers. They define something more fundamental: the environment in which energy companies, grid operators, markets, and eventually our software must work.</p><h3>Why electricity is regulated so heavily</h3><p>Electricity is a commercial product, but the power system is also critical infrastructure.</p><p>Electricity cannot be handled like a normal product that is manufactured, placed in a warehouse, and delivered later. Production and consumption must remain balanced continuously, while thousands of producers and millions of consumers use the same interconnected physical system.</p><p>The network itself also behaves differently from an ordinary competitive business. Building several competing transmission grids between the same regions would be enormously expensive and technically unnecessary. The same is generally true for local distribution networks. It would make little sense for several companies to dig up the same street and install parallel cables so that every household could choose its preferred physical grid.</p><p>Transmission and distribution networks are therefore treated as regulated monopolies. Competition is introduced where it is practical, particularly in generation, trading, and supply, while access to the physical networks is regulated.</p><p>This gives us the first part of the mental model:</p><blockquote><p><strong>Generation, trading, and supply can be competitive. Transmission and distribution are regulated network activities.</strong></p></blockquote><p>Because users cannot realistically choose another physical network, system operators cannot freely set any price or access condition they want. Their tariffs, investments, service obligations, and treatment of network users are supervised by regulators.</p><h3>Why one company does not simply do everything</h3><p>Historically, electricity systems were often organised around vertically integrated utilities. One company could generate electricity, own and operate the network, and sell electricity to consumers.</p><p>From a technical perspective, that structure looks convenient. One organisation owns the chain and coordinates it internally.</p><p>From a market perspective, it creates a conflict of interest.</p><p>Imagine a company that owns the transmission network and also owns power plants. Competing generators need access to the same network. The network owner could favour its own generation business by delaying connections, restricting access, using commercially sensitive information, or applying different conditions to competitors.</p><p>The EU response was <strong>unbundling</strong>, which separates network operation from potentially conflicting interests in generation and supply. The European Commission describes unbundling as one of the main pillars of the internal energy market because network operators must act independently and provide non-discriminatory access to infrastructure. The <a href="https://energy.ec.europa.eu/topics/markets-and-consumers/governance-internal-energy-market_en">Commission&#8217;s overview of internal energy market governance</a> explains the three main transmission unbundling models:</p><ul><li><p><strong>Ownership unbundling</strong>, where network ownership and operation are separated from generation and supply interests.</p></li><li><p><strong>Independent system operator</strong>, or ISO, where the integrated company may retain formal ownership of the network, but an independent organisation operates, maintains, and develops it.</p></li><li><p><strong>Independent transmission operator</strong>, or ITO, where the network remains inside an integrated group but is operated through an independent subsidiary under detailed rules.</p></li></ul><p>Distribution unbundling is less absolute. A distribution system operator that belongs to a vertically integrated group must generally be independent in its legal form, organisation, and decision-making, but EU law does not automatically require separate ownership of its assets. The directive also allows Member States to exempt some smaller integrated undertakings from parts of these requirements. The details are set out in <a href="https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32019L0944">Article 35 of the Electricity Directive</a>.</p><p>The accurate conclusion is therefore not that a company can never participate in more than one part of the sector. The conclusion is that network operation must be sufficiently independent from competitive interests so that access remains fair.</p><p>Once this principle is introduced, the sector separates into several roles:</p><ul><li><p>generators produce electricity;</p></li><li><p>transmission system operators operate high-voltage transmission systems;</p></li><li><p>distribution system operators operate regional and local networks;</p></li><li><p>suppliers sell electricity contracts to consumers;</p></li><li><p>traders buy and sell electricity and related products;</p></li><li><p>market operators organise trading;</p></li><li><p>regulators supervise network and market activities.</p></li></ul><p>These roles are not merely names invented by companies. They are part of the regulated design of the sector.</p><h3>Who creates and enforces the rules</h3><p>The regulatory chain begins at EU level, but not every rule comes from the same organisation.</p><p>The European Commission proposes legislation and develops energy policy. The European Parliament and the Council adopt EU legislation. Regulations apply directly, while directives define results that Member States must implement through national law.</p><p>The main legislation is supported by more detailed network codes and guidelines. These rules cover grid connection, system operation, emergency procedures, capacity allocation, congestion management, forward markets, day-ahead and intraday trading, and electricity balancing. ACER provides a useful <a href="https://www.acer.europa.eu/electricity/market-rules">overview of the binding European electricity market rules</a>.</p><p>At national level, independent regulatory authorities supervise the market and regulated network businesses. Their responsibilities vary between countries, but they commonly include approving or reviewing network tariff methodologies, certifying system operators, supervising unbundling, monitoring competition, protecting consumers, and enforcing national and EU rules. In Austria, this role is performed by <a href="https://www.e-control.at/">E-Control</a>.</p><p>At European level, the <a href="https://www.acer.europa.eu/the-agency/about-acer">European Union Agency for the Cooperation of Energy Regulators, or ACER</a>, coordinates national regulators and acts where cooperation across borders is required. ACER contributes to common methodologies, monitors markets, and takes certain decisions when national regulators cannot reach agreement.</p><p>ENTSO-E and the DSO Entity have different roles. <a href="https://www.entsoe.eu/">ENTSO-E</a> coordinates transmission system operators and contributes technical expertise, common methodologies, planning, data publication, and operational cooperation. The <a href="https://eudsoentity.eu/">DSO Entity</a> performs a corresponding European coordination role for distribution system operators. Neither organisation is an independent public regulator.</p><p>Technical standards add another layer. Standards from organisations such as IEC, CENELEC, ETSI, and ISO may define communication protocols, security controls, equipment behaviour, interoperability, testing, and lifecycle requirements. A standard is not automatically a law, but it may become mandatory through regulation, a grid code, a licence, a contract, or a procurement specification.</p><p>The simplified chain looks like this:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hpa5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e5ab4-fd4d-445d-bb17-3a71985eb0c1_1024x1536.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hpa5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e5ab4-fd4d-445d-bb17-3a71985eb0c1_1024x1536.png 424w, https://substackcdn.com/image/fetch/$s_!hpa5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e5ab4-fd4d-445d-bb17-3a71985eb0c1_1024x1536.png 848w, https://substackcdn.com/image/fetch/$s_!hpa5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e5ab4-fd4d-445d-bb17-3a71985eb0c1_1024x1536.png 1272w, https://substackcdn.com/image/fetch/$s_!hpa5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e5ab4-fd4d-445d-bb17-3a71985eb0c1_1024x1536.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!hpa5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e5ab4-fd4d-445d-bb17-3a71985eb0c1_1024x1536.png" width="1024" height="1536" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d61e5ab4-fd4d-445d-bb17-3a71985eb0c1_1024x1536.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1536,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1767034,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/209412144?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e5ab4-fd4d-445d-bb17-3a71985eb0c1_1024x1536.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hpa5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e5ab4-fd4d-445d-bb17-3a71985eb0c1_1024x1536.png 424w, https://substackcdn.com/image/fetch/$s_!hpa5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e5ab4-fd4d-445d-bb17-3a71985eb0c1_1024x1536.png 848w, https://substackcdn.com/image/fetch/$s_!hpa5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e5ab4-fd4d-445d-bb17-3a71985eb0c1_1024x1536.png 1272w, https://substackcdn.com/image/fetch/$s_!hpa5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd61e5ab4-fd4d-445d-bb17-3a71985eb0c1_1024x1536.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-tqxFUX" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-tqxFUX" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 1: A software requirement can travel a long way before it reaches a development team.</em></p><p>This explains why a small validation rule in Jira may originate from an EU regulation, be interpreted by a national regulator, translated into a process by a system operator, and finally become a requirement for a software vendor.</p><h2>Who owns the assets of the power system?</h2><p>There is no single European company that owns everything between a power plant and a wall socket. The power system consists of assets owned by generators, transmission companies, distribution companies, governments, municipalities, investment funds, industrial companies, cooperatives, and private households.</p><p>It helps to separate the physical system into four groups.</p><h3>Generation assets</h3><p>Generation assets convert another form of energy into electrical energy. They include nuclear, gas, coal, hydro, wind, solar, biomass, and other power plants.</p><p>Their ownership can be private, public, municipal, cooperative, or mixed. A large utility may own dozens of plants. An industrial company may own generation for its factory. A household may own rooftop solar panels.</p><p>Generation is generally a competitive activity. A generator earns revenue by selling energy and, depending on the technology and market, may also sell balancing capacity, balancing energy, ancillary services, certificates, or other products.</p><h3>Transmission assets</h3><p>The transmission grid transports large amounts of power over long distances at high voltage. It connects large generators, large consumers, distribution networks, and neighbouring transmission systems.</p><p>Transmission assets include lines, cables, substations, transformers, switchgear, protection systems, communication networks, and control centres. They are normally owned or controlled by certified transmission system operators (TSO), although the ownership structure differs by country and by unbundling model.</p><p>A TSO can be publicly owned, privately owned, publicly listed, or held through a mixed structure. The ownership model does not change the fundamental point: the company performs a regulated system function and must satisfy independence, access, operational, and certification requirements.</p><p>The <a href="https://www.entsoe.eu/data/map/">ENTSO-E transmission system map</a> gives a useful view of the major transmission infrastructure operated by European TSOs.</p><h3>Distribution assets</h3><p>Distribution networks connect most consumers and smaller generators to the power system. They contain regional substations, medium and low-voltage lines and cables, local transformers, switching equipment, meters, communication systems, and an increasing number of distributed resources.</p><p>Distribution system operators can be large national or regional companies, municipal utilities, private companies, public companies, or members of larger utility groups. Because distribution is a regulated monopoly, consumers usually cannot choose their DSO. Their physical location determines which network connects them.</p><p>They can, however, normally choose a supplier.</p><p>This distinction is fundamental:</p><blockquote><p><strong>The supplier manages the customer&#8217;s commercial electricity contract. The DSO operates the local network to which the customer is physically connected.</strong></p></blockquote><p>Changing supplier does not cause another company to install a second cable to the building. The commercial relationship changes, while the physical connection normally remains with the same DSO.</p><h3>Customer and industrial assets</h3><p>Not every electrical asset belongs to a generator or grid operator.</p><p>Factories, railway systems, data centres, mines, hospitals, airports, and large commercial sites may own substations, transformers, internal networks, generators, batteries, protection systems, and communication infrastructure. Households may own solar panels, batteries, heat pumps, and electric vehicle chargers.</p><p>This creates an important boundary between the public network and the customer installation. The grid operator defines connection conditions, but the customer owns and operates equipment on its side of the boundary. Protection, metering, remote control, data exchange, maintenance, and fault responsibilities must be clearly assigned.</p><p>Knowing who owns an asset is therefore only the beginning. We still need to ask who operates it, who controls it in real time, who defines its requirements, and who carries the consequences when it fails.</p><h2>Who operates the power system?</h2><p>Ownership answers who possesses the assets. Operation answers who is responsible for making the system work.</p><p>The word <em>operator</em> appears everywhere in the sector. A power plant has operators. A substation may be remotely operated from a control centre. A distribution network has a system operator. A transmission network has another system operator. A market also has an operator.</p><p>We therefore need to ask what exactly is being operated.</p><h3>Transmission system operators</h3><p>A transmission system operator, or TSO, is responsible for operating the transmission system and maintaining system security within its area of responsibility.</p><p>A TSO monitors the high-voltage network, coordinates outages, manages congestion, procures balancing services, plans network development, exchanges operational data with neighbouring TSOs, and prepares for emergencies and restoration. It is also responsible for maintaining the balance of the power system within the operational framework defined by European and national rules.</p><p>The unusual part is that a TSO is responsible for the behaviour of a system made mostly from assets owned by other organisations. It does not own every generator, industrial load, battery, wind farm, or distribution network connected to the system.</p><p>It operates through measurements, forecasts, schedules, market mechanisms, reserve procurement, control signals, grid topology, operating agreements, and emergency procedures.</p><h3>Distribution system operators</h3><p>A distribution system operator, or DSO, operates, maintains, and develops a regional or local distribution network.</p><p>A DSO connects consumers and distributed generators, manages planned and unplanned outages, restores supply after local faults, maintains voltage within permitted limits, provides connection information, and exchanges data with suppliers, generators, aggregators, consumers, and TSOs.</p><p>Historically, distribution systems were often treated as passive networks through which electricity flowed from the transmission grid toward consumers. That model is becoming less accurate as distribution networks contain more solar generation, batteries, electric vehicles, heat pumps, flexible industrial demand, and local energy communities.</p><p>A DSO therefore needs increasingly good observability, forecasting, automation, and coordination with the TSO.</p><h3>Synchronous areas and operational responsibility</h3><p>The European power system is physically interconnected, but operational responsibility still needs clear boundaries.</p><p>A <strong>synchronous area</strong> is a group of AC systems operating at the same nominal frequency and connected strongly enough that a significant imbalance affects frequency across the whole area. Europe contains several synchronous areas, with Continental Europe being the largest.</p><p>Inside a synchronous area, balancing and frequency-control responsibilities are divided into defined operational structures. The formal terminology includes load-frequency control blocks, load-frequency control areas, monitoring areas, and scheduling areas. These concepts are defined in the <a href="https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32017R1485">System Operation Guideline, Regulation (EU) 2017/1485</a>.</p><p>For an introductory mental model, the important point is simpler:</p><blockquote><p><strong>The interconnected system is divided into defined operational areas so that schedules, measurements, deviations, reserves, and responsibility can be assigned to specific TSOs or coordinated groups of TSOs.</strong></p></blockquote><p>This is why we should not treat a country, TSO territory, synchronous area, control area, and bidding zone as synonyms. Sometimes their borders align. Often they solve different problems and therefore do not.</p><h3>ENTSO-E and regional coordination</h3><p>National transmission systems cannot be operated in isolation because power flows, outages, market schedules, and security problems cross borders.</p><p><a href="https://www.entsoe.eu/about/inside-entsoe/members/">ENTSO-E brings together 40 member TSOs from 36 countries</a> to support coordinated operation, market integration, planning, common methodologies, data publication, and technical cooperation.</p><p>ENTSO-E is not a European super-TSO. It does not replace national TSOs and does not directly operate every substation. A TSO operates its transmission system. ENTSO-E coordinates the TSOs and fulfils tasks assigned to it by European legislation.</p><p>Regional coordination centres provide another layer of cooperation. They support TSOs with regional security analysis, capacity calculation, outage coordination, adequacy forecasting, and common grid models. The individual TSO remains responsible for its own system, while the regional centre provides calculations and a wider view that no national operator can produce alone. ENTSO-E describes these tasks in its <a href="https://www.entsoe.eu/regions/">overview of European power regions and regional coordination</a>.</p><h2><strong>Who buys, sells, and pays?</strong></h2><p>When I started researching how the electricity market works, I expected it to be the most straightforward topic in this whole series.</p><p>The result was the opposite, and it was much more exciting than I expected.</p><p>The market opened another dimension of the power system for me. Its structure is almost as complex as the physical layer. The physical and commercial layers intersect and depend on each other, but they mostly exist as two parallel worlds with their own actors, rules, states, and processes.</p><p>In the physical world, we have generators, consumers, transmission lines, voltage, frequency, and power flows.</p><p>In the commercial world, we have contracts, bids, schedules, market positions, prices, and financial settlement.</p><p>Understanding the difference between these worlds is the foundation for understanding the electricity market.</p><h3><strong>The market is not the physical grid</strong></h3><p>My first question was simple: how does an electricity producer sell electricity and deliver it to a buyer?</p><p>The confusing answer is that it does not deliver its own electricity directly to that buyer.</p><p>Electrons in the network do not carry labels. We cannot take a particular group of electrons produced by Power Plant A and route it through selected transmission lines to Factory B. The physical power flow is determined by the grid topology, electrical impedances, voltages, and phase angles, not by the commercial contract.</p><p>A generator injects power into the interconnected system. A consumer withdraws power from the same system. Commercially, they may have bought and sold electricity between them, but physically there is no dedicated connection carrying only the electricity from that seller to that buyer.</p><p>This creates two parallel views of the same delivery period.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!V-p-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e54f3fa-0f93-4dd2-9456-3cd99ca25f1d_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!V-p-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e54f3fa-0f93-4dd2-9456-3cd99ca25f1d_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!V-p-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e54f3fa-0f93-4dd2-9456-3cd99ca25f1d_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!V-p-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e54f3fa-0f93-4dd2-9456-3cd99ca25f1d_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!V-p-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e54f3fa-0f93-4dd2-9456-3cd99ca25f1d_1536x1024.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!V-p-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e54f3fa-0f93-4dd2-9456-3cd99ca25f1d_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5e54f3fa-0f93-4dd2-9456-3cd99ca25f1d_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1601919,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/209412144?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e54f3fa-0f93-4dd2-9456-3cd99ca25f1d_1536x1024.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!V-p-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e54f3fa-0f93-4dd2-9456-3cd99ca25f1d_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!V-p-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e54f3fa-0f93-4dd2-9456-3cd99ca25f1d_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!V-p-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e54f3fa-0f93-4dd2-9456-3cd99ca25f1d_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!V-p-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5e54f3fa-0f93-4dd2-9456-3cd99ca25f1d_1536x1024.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-tqxFUX" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-tqxFUX" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The market does not route electricity. It coordinates what participants promise to inject or withdraw and assigns financial responsibility when their actual behaviour differs from those promises.</p><h3><strong>Contracts create the commercial plan</strong></h3><p>A seller and a buyer agree on an amount of electrical energy for a particular delivery period and usually for a particular market area.</p><p>One participant promises to provide a commercial quantity. Another participant takes the corresponding commercial position.</p><p>Across the market, thousands of such trades create the expected commercial balance between production and consumption. Depending on the market and national rules, these positions are translated into schedules, nominations, and other information used by market participants and system operators.</p><p>However, the sum of all commercial positions does not guarantee that the physical grid will operate securely.</p><p>A market result may be commercially balanced while still creating too much power flow through a particular transmission corridor. A generator may fail after selling its expected production. Consumers may use more or less electricity than forecast. Wind and solar production may differ from predictions.</p><p>The TSO therefore uses market schedules together with forecasts, measurements, network models, equipment availability, and security analysis. Commercial planning tells the TSO what participants expect to do. Physical operation determines whether the system can actually support it.</p><h3><strong>Electricity is traded across different timeframes</strong></h3><p>Electricity is not traded through one single market.</p><p>Participants make decisions at different times because their information and risks change as delivery approaches. A supplier can estimate next year&#8217;s consumption, but tomorrow&#8217;s forecast will be more accurate. A wind producer knows more about expected generation a few hours before delivery than several months earlier.</p><p>The European wholesale market is therefore divided into several timeframes. ACER describes forward, day-ahead, intraday, and balancing as the main connected market stages. [^https://www.acer.europa.eu/electricity/market-rules/market-rules-different-electricity-market-timeframes]</p><h4><strong>Long-term and forward trading</strong></h4><p>Long-term contracts are made months or years before delivery.</p><p>They include bilateral contracts, power purchase agreements, forwards, futures, and other hedging instruments. Their main purpose is often not to predict every future megawatt-hour precisely, but to reduce exposure to future price changes.</p><p>A supplier may want predictable purchasing costs. A generator may need stable revenues to support an investment. A factory may want to protect itself from extreme electricity prices.</p><h4><strong>Day-ahead market</strong></h4><p>In the day-ahead market, participants buy and sell electricity for delivery during the following day.</p><p>They submit bids and offers for defined delivery periods. Market coupling combines these orders across bidding zones while accounting for the available cross-zonal transmission capacity.</p><p>The day-ahead result becomes an important commercial baseline, but it is still based on forecasts.</p><h4><strong>Intraday market</strong></h4><p>After the day-ahead market closes, reality continues to develop.</p><p>Weather forecasts change. A generator becomes unavailable. Consumption expectations move. A battery operator changes its planned position.</p><p>The intraday market allows participants to adjust their positions closer to physical delivery. This helps them reduce the difference between what they previously traded and what they now expect to produce or consume. European intraday trading continues close to real time, subject to the applicable gate-closure rules. [^https://www.acer.europa.eu/news/acer-greenlights-30-minute-intraday-electricity-gate-closure-time-across-eu-borders]</p><h4><strong>Balancing market</strong></h4><p>Even after intraday trading, actual production and consumption will not exactly match the commercial positions.</p><p>The TSO must correct the remaining physical imbalance in real time. It does this by activating balancing resources that can increase or decrease their generation or consumption.</p><p>The balancing market is therefore different from the earlier markets. Forward, day-ahead, and intraday trading allow participants to build and correct their own commercial positions. Balancing allows TSOs to procure and activate the physical flexibility needed to maintain system frequency and avoid a wider failure when the final result still does not match. [<a href="https://www.acer.europa.eu/electricity/market-rules/market-rules-different-electricity-market-timeframes">https://www.acer.europa.eu/electricity/market-rules/market-rules-different-electricity-market-timeframes</a>]</p><h3><strong>Not every producer and consumer trades directly</strong></h3><p>It would be extremely difficult for every household, small generator, factory, and battery to buy and sell every delivery period independently.</p><p>The electricity market therefore contains actors that may not produce or consume electricity themselves but organise the commercial side of the system.</p><p>They aggregate customers, forecast consumption, access wholesale markets, manage schedules, trade changing positions, issue invoices, and carry financial responsibility.</p><h3><strong>Supplier</strong></h3><p>A supplier is the company that manages the commercial electricity relationship with the end customer.</p><p>For most households, this is the company that offers the tariff, signs the electricity contract, purchases energy for its customer portfolio, and sends the bill.</p><p>The supplier estimates how much electricity its customers will use and purchases corresponding quantities through contracts and markets. It also manages market access, forecasting, billing, customer service, and the financial consequences of differences between expected and actual consumption.</p><p>The supplier should not be confused with the DSO.</p><p><strong>The supplier manages the customer&#8217;s commercial electricity contract. The DSO operates the local network to which the customer is physically connected.</strong></p><p>Changing supplier normally changes who sells electricity to the customer. It does not change the physical cable or the local network operator.</p><h3><strong>What happens when the plan is wrong?</strong></h3><p>The grid must remain physically balanced, but no forecast is perfect.</p><p>A generator may produce less than planned because of a technical failure. A wind farm may produce more than forecast. Consumers may use more electricity than expected during a cold evening or less than expected during a holiday.</p><p>Suppose a supplier expects its customers to consume 50 MWh during one settlement period and purchases 50 MWh.</p><p>The customers actually consume 52 MWh.</p><p>Physically, the grid does not stop supplying them after the contracted 50 MWh has been consumed. The power system continues operating, and the TSO maintains the overall balance using the available physical response and balancing actions.</p><p>Commercially, however, somebody must be responsible for the missing 2 MWh and for the costs created by the deviation.</p><p>This is where the balance responsible party enters the picture.</p><h3><strong>Balance responsible party</strong></h3><p>A <strong>balance responsible party</strong>, or BRP, is a market role that accepts financial responsibility for the imbalance of a portfolio.</p><p>A BRP may manage a portfolio containing generators, suppliers, consumers, traders, storage systems, or aggregators. A company can become a BRP itself, or it can contract another BRP to carry its balance responsibility.</p><p>EU electricity-market rules require market participants either to be BRPs or to contractually delegate their balance responsibility to one, apart from limited exceptions. Each BRP is financially responsible for its imbalance and must strive to remain balanced or help the system remain balanced. [<a href="https://eur-lex.europa.eu/eli/reg/2019/943/oj/eng">https://eur-lex.europa.eu/eli/reg/2019/943/oj/eng</a>]</p><p>The BRP can be understood as the commercial boundary around a portfolio.</p><p>Inside that boundary, there may be many injections and withdrawals:</p><ul><li><p>power plants producing electricity;</p></li><li><p>suppliers serving consumers;</p></li><li><p>factories consuming electricity;</p></li><li><p>batteries charging and discharging;</p></li><li><p>traders buying and selling market positions.</p></li></ul><p>The BRP tries to make the portfolio&#8217;s total commercial position match its expected physical behaviour.</p><h3><strong>What does a BRP actually do?</strong></h3><p>A BRP does not simply wait until an imbalance happens and then pay the bill.</p><p>It actively manages the portfolio before delivery.</p><p>Its work can include:</p><ul><li><p>forecasting production and consumption;</p></li><li><p>collecting plans and availability information from portfolio members;</p></li><li><p>purchasing or selling electricity in long-term and day-ahead markets;</p></li><li><p>updating positions through intraday trading as forecasts change;</p></li><li><p>submitting schedules and position information required by market rules;</p></li><li><p>monitoring expected production and consumption;</p></li><li><p>reacting to plant failures or forecast changes;</p></li><li><p>receiving allocated metering data after delivery;</p></li><li><p>calculating or checking the portfolio&#8217;s imbalance;</p></li><li><p>settling the remaining imbalance with the connecting TSO.</p></li></ul><p>Before the applicable intraday gate closure, a BRP can change schedules and use the intraday market to reduce an expected shortage or surplus. After delivery, the TSO calculates the difference between the BRP&#8217;s final position and its allocated physical volume for each imbalance settlement period. That difference is settled using the applicable imbalance price. The precise procedures vary between countries and balancing arrangements. [<a href="https://eur-lex.europa.eu/eli/reg/2017/2195/oj/eng">https://eur-lex.europa.eu/eli/reg/2017/2195/oj/eng</a>]</p><p>Returning to our example, the supplier&#8217;s customers consumed 52 MWh while only 50 MWh had been purchased.</p><p>If the supplier belongs to a BRP portfolio, the shortage becomes part of the BRP&#8217;s total position. Other generators or consumers inside the same portfolio may partly offset it. If the portfolio still has a net shortage of 2 MWh, the remaining imbalance is settled between the BRP and the TSO.</p><p>The BRP therefore resembles an insurance provider only in a limited sense: it accepts responsibility for a risk that individual participants may not want to manage alone.</p><p>However, unlike normal insurance, it does not simply absorb the cost. It forecasts, trades, aggregates opposite deviations, charges its portfolio members, and manages the remaining financial exposure. Calling it a portfolio manager with balance responsibility is more accurate than calling it insurance.</p><p>For another practical explanation, the <a href="https://www.next-kraftwerke.be/knowledge-hub/balancing-responsible-party-brp">Next Kraftwerke overview of the BRP role</a> provides a useful industry perspective.</p><h3><strong>BRP and BSP are not the same thing</strong></h3><p>The abbreviations are similar, but the roles solve different problems.</p><p>A <strong>BRP</strong> carries financial responsibility for the difference between the commercial position and the allocated physical behaviour of its portfolio.</p><p>A <strong>balancing service provider</strong>, or BSP, provides physical flexibility that the TSO can activate. A BSP may operate a power plant, battery, industrial load, aggregated portfolio, or another controllable resource capable of changing its injection or withdrawal.</p><p>One company may perform both roles, but they remain separate responsibilities.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ihFi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F338c33b8-8c9e-4905-8d0b-2860aa4eeeff_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ihFi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F338c33b8-8c9e-4905-8d0b-2860aa4eeeff_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!ihFi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F338c33b8-8c9e-4905-8d0b-2860aa4eeeff_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!ihFi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F338c33b8-8c9e-4905-8d0b-2860aa4eeeff_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!ihFi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F338c33b8-8c9e-4905-8d0b-2860aa4eeeff_1536x1024.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!ihFi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F338c33b8-8c9e-4905-8d0b-2860aa4eeeff_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/338c33b8-8c9e-4905-8d0b-2860aa4eeeff_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1390401,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/209412144?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F338c33b8-8c9e-4905-8d0b-2860aa4eeeff_1536x1024.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ihFi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F338c33b8-8c9e-4905-8d0b-2860aa4eeeff_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!ihFi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F338c33b8-8c9e-4905-8d0b-2860aa4eeeff_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!ihFi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F338c33b8-8c9e-4905-8d0b-2860aa4eeeff_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!ihFi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F338c33b8-8c9e-4905-8d0b-2860aa4eeeff_1536x1024.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-tqxFUX" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-tqxFUX" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 2: The BRP manages the commercial deviation, while the BSP provides the physical response activated by the TSO.</em></p><p>Suppose a power plant unexpectedly disconnects.</p><p>Its BRP becomes exposed to the resulting commercial shortage. The BRP may have reduced that exposure through intraday trading before gate closure, or other assets in its portfolio may offset part of it.</p><p>At the same time, the TSO sees the physical power-system imbalance and activates balancing resources from BSPs.</p><p>The TSO solves the immediate physical problem.</p><p>The imbalance-settlement process assigns the commercial consequences.</p><p>This is where the two parallel worlds intersect.</p><p>The physical system cannot wait for contracts to be corrected. The TSO must keep it stable immediately. The commercial system then determines whose position differed from reality and who pays or receives money as a result.</p><p>That is the central purpose of the electricity market: not to route individual electrons from seller to buyer, but to coordinate planned injections and withdrawals, create prices, support efficient use of the network, and assign financial responsibility around one shared physical machine.</p><h2>Putting the layers together</h2><p>Consider a wind farm connected to a regional network and a factory consuming electricity elsewhere.</p><p>The <strong>physical flow</strong> begins with the wind farm injecting power into the interconnected system. The factory withdraws power through its local distribution network. The electricity reaching the factory is not a private stream routed from that particular wind farm.</p><p>The <strong>commercial flow</strong> is represented by contracts and market positions. The wind farm may sell through a trader or aggregator. A supplier buys electricity and sells a contract to the factory. A NEMO may operate the day-ahead or intraday market where part of the position is traded.</p><p>The <strong>operational flow</strong> is managed by system operators. The DSO operates the networks to which the wind farm and factory are connected. The TSO monitors the wider system, manages congestion, and procures balancing services. If wind production differs from the schedule, the physical system still has to remain balanced.</p><p>The <strong>financial-responsibility flow</strong> is assigned through balance responsibility. The relevant BRP carries the imbalance caused by the difference between scheduled and actual production or consumption. A BSP may provide balancing energy when activated by the TSO.</p><p>The <strong>regulatory flow</strong> begins with EU and national rules, continues through ACER and the national regulator, and becomes licences, tariffs, methodologies, grid codes, company processes, and technical requirements.</p><p>No single company owns or controls the complete process. The European electricity sector works through coordinated responsibility distributed among specialised actors.</p><h2>What this means for software engineers</h2><p>Once we understand the structure, many technical requirements stop looking arbitrary.</p><p>Suppose a team receives a requirement to record every control action with the user identity, timestamp, previous value, new value, source system, and reason for the change. From a narrow product perspective, this can look excessive.</p><p>However, the requirement may exist because several organisations share responsibility, an incident must be reconstructed, a regulator may require evidence, a control action can have safety consequences, or incorrect data can create financial liability.</p><p>The feature is not merely audit logging. It is the software representation of responsibility.</p><p>The same pattern appears in requirements for redundancy, strict time synchronisation, role-based access, configuration approval, long retention periods, traceable calculations, formal testing, standardised protocols, controlled updates, and operation during partial failures.</p><p>Some of these requirements come from physics. Some come from regulation. Most come from the interaction between technical reality and institutional responsibility.</p><p>When you begin work on an energy software system, ask eight questions:</p><ol><li><p><strong>Who owns the relevant asset?</strong></p></li><li><p><strong>Who operates the asset or process?</strong></p></li><li><p><strong>Who buys the software?</strong></p></li><li><p><strong>Who uses the software every day?</strong></p></li><li><p><strong>Who defined the requirement?</strong></p></li><li><p><strong>Who receives or relies on the data?</strong></p></li><li><p><strong>Who carries the operational and financial risk?</strong></p></li><li><p><strong>Who checks that the system complies with the rules?</strong></p></li></ol><p>The answers reveal the architecture around the architecture.</p><p>They explain why the system needs particular interfaces, security boundaries, access models, audit records, approval flows, availability targets, deployment procedures, and lifecycle guarantees.</p><h2>Conclusion</h2><p>When I entered the electricity sector, I tried to understand it as a simple chain. Someone produced electricity. Someone transported it. Someone sold it. Someone consumed it.</p><p>That picture was not completely wrong, but it was too small to be useful.</p><p>The sector is deliberately divided into specialised roles. Ownership, operation, commercial responsibility, and regulation are separate layers. A company may own an asset without operating the wider system. It may operate critical infrastructure while being privately owned. It may buy software whose requirements were defined by a regulator, a network code, or another operator.</p><p>Once these layers are separated, the collection of strange abbreviations starts to form a system.</p><p>More importantly, we can answer the questions that matter when building software:</p><p>Who is our customer? Who is our user? Who defined the requirement? Who pays for the system? Who carries the risk? And who will be responsible when something goes wrong?</p><p>These questions do not replace technical analysis. They tell us which technical problems actually matter.</p><p><em>Next part:</em></p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;a88cdca1-feb0-4eb2-b56c-a7108f326066&quot;,&quot;caption&quot;:&quot;Previous part:&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Where Software Lives in the Power Grid&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer exploring how complex systems are built. I take them apart, rebuild them from first principles, and trace the layers connecting software, networks, infrastructure, devices, and the physical world.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-08-04T12:00:12.967Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!VcpN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6d167517-6038-47fa-9548-a22e9beba2c7_1536x1024.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/where-software-lives-in-the-power&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:209770599,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:2,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><p><em>All articles of the series:</em></p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;61698f62-61eb-4bb1-845b-c96d191d814f&quot;,&quot;caption&quot;:&quot;I have spent a lot of time learning technical systems by rebuilding them from first principles.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;A Developer&#8217;s Map of the European Power Grid&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer exploring how complex systems are built. I take them apart, rebuild them from first principles, and trace the layers connecting software, networks, infrastructure, devices, and the physical world.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-05-12T15:14:05.930Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!r2v5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b47f174-07bd-435f-9c8c-363edb0adbfd_1491x1055.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/a-developers-map-of-the-european&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:197363882,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><h2>Primary sources</h2><ul><li><p><a href="https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32019L0944">Directive (EU) 2019/944 on common rules for the internal market for electricity</a></p></li><li><p><a href="https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32019R0943">Regulation (EU) 2019/943 on the internal market for electricity</a></p></li><li><p><a href="https://energy.ec.europa.eu/topics/markets-and-consumers/governance-internal-energy-market_en">European Commission: Governance of the internal energy market</a></p></li><li><p><a href="https://www.acer.europa.eu/electricity/market-rules">ACER: European electricity market rules</a></p></li><li><p><a href="https://www.acer.europa.eu/electricity/market-rules/market-rules-different-electricity-market-timeframes">ACER: Market rules for different electricity market timeframes</a></p></li><li><p><a href="https://www.acer.europa.eu/electricity/market-rules/electricity-balancing">ACER: Electricity balancing</a></p></li><li><p><a href="https://www.entsoe.eu/about/inside-entsoe/members/">ENTSO-E member companies</a></p></li><li><p><a href="https://www.entsoe.eu/regions/">ENTSO-E regional coordination</a></p></li><li><p><a href="https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32017R1485">Commission Regulation (EU) 2017/1485 establishing a guideline on electricity transmission system operation</a></p></li><li><p><a href="https://energy.ec.europa.eu/topics/markets-and-consumers/electricity-prices_en">European Commission: Electricity prices</a></p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">&#8216;Software in the Grid&#8216; is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[How the European Grid Stays Stable]]></title><description><![CDATA[Operations, monitoring, control and protection, Part 3 of A Developer&#8217;s Map of the European Power Grid]]></description><link>https://www.softwareinthegrid.com/p/how-the-european-grid-stays-stable</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/how-the-european-grid-stays-stable</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Mon, 20 Jul 2026 07:02:23 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!z1Qz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90a438ee-e618-41a8-9933-cc1dfcf1dcb2_1672x941.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!z1Qz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90a438ee-e618-41a8-9933-cc1dfcf1dcb2_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!z1Qz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90a438ee-e618-41a8-9933-cc1dfcf1dcb2_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!z1Qz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90a438ee-e618-41a8-9933-cc1dfcf1dcb2_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!z1Qz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90a438ee-e618-41a8-9933-cc1dfcf1dcb2_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!z1Qz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90a438ee-e618-41a8-9933-cc1dfcf1dcb2_1672x941.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!z1Qz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90a438ee-e618-41a8-9933-cc1dfcf1dcb2_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/90a438ee-e618-41a8-9933-cc1dfcf1dcb2_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2775367,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/207691626?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90a438ee-e618-41a8-9933-cc1dfcf1dcb2_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!z1Qz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90a438ee-e618-41a8-9933-cc1dfcf1dcb2_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!z1Qz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90a438ee-e618-41a8-9933-cc1dfcf1dcb2_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!z1Qz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90a438ee-e618-41a8-9933-cc1dfcf1dcb2_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!z1Qz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F90a438ee-e618-41a8-9933-cc1dfcf1dcb2_1672x941.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Previous part:</em></p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;e9dd4be6-cabb-4a4d-ac9c-946e7e810147&quot;,&quot;caption&quot;:&quot;Figure 1: The old picture says power flows through a pipe. The real grid is a synchronized graph that must stay balanced in real time.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;The Grid Is Not a Pipeline&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer exploring how complex systems are built. I take them apart, rebuild them from first principles, and trace the layers connecting software, networks, infrastructure, devices, and the physical world.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-05-29T15:42:22.475Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!h0bv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b765de-ab75-4122-88be-17cf19c0eed2_1536x1024.jpeg&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/the-grid-is-not-a-pipeline&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:199757049,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:1,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:false,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><p>Suppose you operate a web-service across three data centres. One region handles a large share of the traffic, and then it disappears.</p><p>Your monitoring detects failed health checks. The load balancer stops sending new requests to the failed region. Queues hold work that cannot be processed immediately. Clients retry some requests. Spare capacity in the remaining regions absorbs part of the load, autoscaling adds more instances, and operators receive alerts while the system settles into a degraded but usable state.</p><p>Software engineers know this story. We design distributed systems with observability, redundancy, failure detection, isolation, automated recovery and human escalation because components eventually fail.</p><p>Now replace the data centre with a 1,000 MW generator connected to the European power grid.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.softwareinthegrid.com/subscribe?"><span>Subscribe now</span></a></p><p>The comparison still helps, but the failure is harder. Electricity cannot wait inside a queue until another generator is ready. Consumers continue withdrawing power at the same moment that generation disappears. The electrical state begins changing before a monitoring system has delivered the first alarm, and power redistributes through transmission lines according to physical laws rather than routes selected by an application.</p><p>The grid also has shared physical state. Frequency reflects the balance between active power generation and consumption. Voltage differs across the network and depends strongly on local reactive power and power flows. Current, equipment temperatures, rotor angles and line loading continue changing while software is still collecting measurements.</p><p>In <a href="https://www.softwareinthegrid.com/p/electricity-is-not-water-a-better">Part 1, Electricity Is Not Water</a>, we built the physical model behind generators, transformers, AC and frequency. In <a href="https://www.softwareinthegrid.com/p/the-grid-is-not-a-pipeline">Part 2, The Grid Is Not a Pipeline</a>, we assembled the network as a graph of substations, lines, generators, storage and loads. Now the machine is running, and we can ask how it stays alive when its state never stops changing.</p><p>In this post you will learn how protection, monitoring, operation and control work together, what SCADA contributes to that chain, which physical variables operators care about, and what happens from the first instant after a large generator disconnects until the grid reaches a new secure state.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XFzL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66015bd2-ff02-4a94-85e2-0383303110d4_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XFzL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66015bd2-ff02-4a94-85e2-0383303110d4_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!XFzL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66015bd2-ff02-4a94-85e2-0383303110d4_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!XFzL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66015bd2-ff02-4a94-85e2-0383303110d4_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!XFzL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66015bd2-ff02-4a94-85e2-0383303110d4_1672x941.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!XFzL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66015bd2-ff02-4a94-85e2-0383303110d4_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/66015bd2-ff02-4a94-85e2-0383303110d4_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1268227,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/207691626?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66015bd2-ff02-4a94-85e2-0383303110d4_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XFzL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66015bd2-ff02-4a94-85e2-0383303110d4_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!XFzL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66015bd2-ff02-4a94-85e2-0383303110d4_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!XFzL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66015bd2-ff02-4a94-85e2-0383303110d4_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!XFzL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F66015bd2-ff02-4a94-85e2-0383303110d4_1672x941.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p><em>Figure 1: A software platform can queue and redirect work. A power-system disturbance begins changing the shared physical state immediately.</em></p><h2>A Distributed Physical System</h2><p>The grid behaves like a distributed system in the broad sense. It spans many locations, has no single machine that contains its complete state, depends on communication and coordination, and must continue operating when individual components become unavailable.</p><p>The difference is that its nodes are coupled by physics.</p><p>A web service can often tolerate short disagreement between replicas. Messages can arrive late, requests can wait, and a control plane can calculate a new routing decision before the data plane changes. The electrical grid has far less freedom. A breaker opening in one substation immediately changes the topology seen by the electrical system. Voltages and currents respond at electromagnetic speed, rotating machines accelerate or decelerate, and power flows settle into new paths throughout the connected network.</p><p>This makes grid stability a broader idea than keeping the lights on. The system must remain within several limits at the same time.</p><h3>Generation and load balance</h3><p>A <strong>load</strong> is anything withdrawing electrical power from the grid. It may be one motor, a railway, a steel plant, a house or the combined demand of an entire distribution network.</p><p>Generators&#8212;and storage systems when discharging&#8212;inject <strong>active power</strong>, measured in watts. Active power is the average rate at which electrical energy is transferred into net work or heat: it turns motors, warms heaters, moves pumps and powers computers.</p><p>Across a synchronous AC system, generation and other active-power injections must continuously match consumption and network losses. When consumption and losses require more active power than generators and other resources provide, energy is initially drawn from the rotating masses of connected machines and frequency falls. When injections exceed consumption and losses, those machines accelerate and frequency rises.</p><p>In Continental Europe the target is 50 Hz. Frequency is therefore both a controlled quantity and a system-wide symptom. It tells operators that the active-power balance has changed, although it does not by itself reveal where the cause is located.</p><h3>Voltage and reactive power</h3><p>Every connection point in the grid also has a <strong>voltage</strong>. Voltage can be thought of as the electrical potential that drives current and allows power to move, but operationally the key point is simpler: voltage must stay within an acceptable range at every important bus and connection point.</p><p>Frequency is broadly shared across a synchronous area. Voltage is local. A bus in western Austria, a substation near Vienna and an interconnector in Germany can all have different voltage magnitudes at the same moment.</p><p>AC equipment needs changing electric and magnetic fields. Part of the current repeatedly stores energy in those fields and returns it later in the AC cycle. The associated quantity is <strong>reactive power</strong>, measured in var. It does not produce net work over a complete cycle, but it still creates current, occupies network capacity and affects voltage.</p><p>When an area lacks reactive-power support, voltage tends to fall. When it has too much, voltage can rise. The relationship is not perfectly isolated, because active power, reactive power, current, voltage and network impedance affect each other. Still, the following first model is useful:</p><blockquote><p>Active power is closely connected to frequency, while reactive power is closely connected to voltage.</p></blockquote><h3>Power flow and transmission capacity</h3><p><strong>Power flow</strong> describes how active and reactive power move through the connected network. In software terms, the grid has a graph, but it has no router assigning each megawatt to a chosen path. Flows emerge from topology, line impedances, voltage magnitudes and phase angles.</p><p>If one transmission line opens, the power it carried does not wait for a new route. The electrical state changes and the flow redistributes over the lines that remain. A line far from the original event may receive much of the additional loading.</p><p>Each element has operational limits. A conductor can carry only so much current before heating becomes unacceptable. Transformers have thermal and equipment limits. Voltages must stay inside permitted ranges. The system also has stability limits that can become restrictive before a wire reaches its thermal rating.</p><p>This is what <strong>transmission capacity</strong> means operationally. It is not only a fixed number printed on a line specification. The usable capacity depends on the wider network state, including which elements are available, how power is injected and withdrawn, the weather, voltage conditions and what would happen if another component failed.</p><p>A grid can have enough total generation and still be unable to transport it safely to the loads that need it. This is why balancing generation and managing network congestion are related tasks, but they are not the same task.</p><h2>Protection, Operation and Control</h2><p>When I first tried to understand grid operations, these words blurred together. A relay trips a breaker, an operator opens another breaker, an automatic controller changes generator output, and SCADA displays all three events. It is easy to treat everything as one large control system.</p><p>The distinction becomes clearer when we ask what each area is trying to achieve.</p><h3>Protection detects and isolates danger</h3><p>A <strong>fault</strong> is an unintended electrical condition such as a short circuit, an insulation failure or an accidental connection between conductors and ground. Faults can create currents and voltages far outside normal operating values, damage expensive equipment and destabilise the surrounding network.</p><p>Protection systems exist to detect these conditions and isolate the affected equipment quickly.</p><p>A <strong>protection relay</strong> receives electrical measurements from instrument transformers or sensors. It applies configured logic to determine whether the measured condition indicates a fault or another dangerous state. Depending on the protected asset, the relay may compare currents entering and leaving a transformer, estimate the apparent distance to a fault on a line, watch for excessive current, or use measurements exchanged with a relay at the other end of the line.</p><p>When the relay decides that the equipment must be disconnected, it sends a trip signal to a <strong>circuit breaker</strong>. The breaker is the heavy electrical switch capable of interrupting normal load current and, within its rating, the much larger current produced by a fault.</p><p>The protected network is divided into <strong>protection zones</strong> around lines, transformers, busbars and generators. These zones usually overlap around breakers so that there is no unprotected gap. The design aims to remove the smallest practical part of the grid while still clearing the fault reliably. Backup protection covers cases where the primary relay, communication path or circuit breaker fails.</p><p>Protection is mainly local, automatic and fast. A line fault may need to be cleared within tens of milliseconds. The relay cannot wait for SCADA to send measurements to a control centre, for an operator to interpret an alarm and for a remote command to return. The trip path is designed to work without that sequence.</p><p>SCADA will report what happened. Operators will investigate and decide how to restore the network. Those steps matter, but they come after the immediate protection action.</p><h3>Operation builds and maintains a secure state</h3><p><strong>Operation</strong> is the continuous work of understanding the current grid, preparing it for expected conditions and responding when reality differs from the plan.</p><p>Dispatchers in control rooms track the network topology, planned outages, unavailable equipment, generator schedules, weather, load forecasts, active and reactive reserves, voltages and line loading. They coordinate switching, release equipment for maintenance, return it to service, communicate with generators and distribution operators, and exchange information with neighbouring transmission system operators.</p><p>Routine work occupies much of this domain. Taking a transformer out of service for maintenance changes the grid before any failure occurs. A dispatcher needs to know whether the remaining network can carry the expected power and whether it can still survive another credible outage.</p><p>This leads to <strong>contingency analysis</strong>, which repeatedly asks questions such as:</p><ul><li><p>What happens if this line trips?</p></li><li><p>What happens if the largest generator disconnects?</p></li><li><p>Will another transformer overload?</p></li><li><p>Will a bus voltage leave its permitted range?</p></li><li><p>Which remedial actions would still be available?</p></li></ul><p>The common <strong>N-1</strong> idea means that the system should normally tolerate the loss of one relevant component without leaving acceptable operating limits after the allowed corrective actions. The exact application is more detailed than that sentence, but the mental model is valuable: operators manage the present while continuously testing possible next states.</p><p>EU system-operation rules require TSOs to monitor active and reactive flows, voltages, frequency, reserves, generation and load in real time, and to perform recurring contingency analysis against operational security limits. They also require close-to-real-time analysis to use state estimation. The complete rules are in the <a href="https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX%3A32017R1485">EU System Operation Guideline</a>.</p><h3>Control changes the state</h3><p><strong>Control</strong> is the set of actions that move the grid toward a desired operating state.</p><p>Some controls are built into equipment. A generator governor responds to frequency. An automatic voltage regulator changes excitation. A transformer tap changer adjusts its ratio. A capacitor controller switches a bank when voltage crosses a threshold.</p><p>Other controls are centralised. Automatic generation control sends changing active-power setpoints to participating resources. A control-room application can request a breaker operation. A dispatcher can instruct a power plant to change active or reactive output, order redispatch, or coordinate a topology change with another operator.</p><p>Operation and control therefore describe different parts of the same process. Operation provides the context, objectives and decisions. Control applies physical actions, either automatically or through commands initiated by operators. A protection relay also causes a physical action, but its purpose and logic are different: it removes danger immediately rather than optimising the wider operating state.</p><p>A useful software comparison is this:</p><ul><li><p>Protection resembles local safety logic with authority to shut down a dangerous component.</p></li><li><p>Monitoring provides observability.</p></li><li><p>Operation resembles the work of site reliability engineers who assess the complete service and choose a recovery strategy.</p></li><li><p>Control contains the automated loops and commands that change the running system.</p></li></ul><p>The comparison helps organise the responsibilities, although the grid remains coupled by physical laws throughout the whole process.</p><h2>How the Grid Becomes Visible</h2><p>A control room may have wall-sized diagrams and dozens of screens, but the operator still does not see the electrical system directly. The displayed grid is constructed from measurements, communication, equipment statuses and models.</p><p>The chain begins in the field.</p><h3>Measurements begin at the equipment</h3><p>Sensors and instrument transformers measure current and voltage. From these signals, devices calculate active power, reactive power, frequency and other electrical quantities. Breakers and disconnectors provide position indications. Transformers report tap positions, protection devices report trips, and equipment monitoring systems may provide temperatures, pressures and internal alarms.</p><p>A measurement always has context. A value needs a timestamp, a source, a unit and a quality indication. A current value from the wrong bay, a breaker state received late, or a voltage measurement marked good when its input circuit has failed can create a convincing but incorrect picture.</p><h3>Substation devices collect and process data</h3><p>Inside a substation, intelligent electronic devices, bay controllers, remote terminal units and substation automation systems collect measurements and statuses. Some values are processed locally. Some are stored as events. Some are forwarded to a remote control centre.</p><p>These devices may also receive commands. A control centre can request a breaker operation, change a setpoint or switch voltage-control equipment, subject to interlocks and operational procedures.</p><p>Protection lives close to this layer, but it should not be confused with telemetry. A protection relay can share measurements and event reports with the automation system while keeping its trip logic local and independent from the normal SCADA path.</p><h3>Communication networks transport telemetry and commands</h3><p>Substations and power plants are connected to control centres through operational communication networks. Depending on the system and its age, these links may use fibre, microwave, radio, leased communication services or other channels, often with redundant paths.</p><p>Protocols such as IEC 60870-5-104, IEC 61850, DNP3 and vendor-specific interfaces carry measurements, events, statuses and commands across different parts of the chain. The protocol tells us how information is represented and transported. It does not guarantee that the physical measurement is correct or that the model on the receiving side matches the real substation.</p><h3>SCADA provides the supervisory interface</h3><p><strong>SCADA</strong> stands for Supervisory Control and Data Acquisition. In a grid control centre, it collects telemetry from many remote sites, presents measurements and equipment states, manages alarms and events, stores trends, and provides authorised operators with remote-control functions.</p><p>The word <em>supervisory</em> matters. SCADA gives a central view and allows high-level control of dispersed assets. It does not replace local protection, and it does not independently understand every physical consequence of an action.</p><p>A SCADA screen may show a one-line diagram in which a breaker appears open, a line is coloured according to its loading and an alarm list reports a generator trip. Behind that screen sits a long chain of measurement circuits, field devices, communication links, protocol gateways, databases, application logic and configuration.</p><p>NIST&#8217;s <a href="https://csrc.nist.gov/pubs/sp/800/82/r3/final">Guide to Operational Technology Security</a> describes the same broad SCADA structure: field devices and RTUs or PLCs communicate through wide-area networks with control servers, operator interfaces, engineering workstations and historians in a control centre.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fqzI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c01cec7-ba2a-41a6-a3ad-e346edec2f4a_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fqzI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c01cec7-ba2a-41a6-a3ad-e346edec2f4a_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!fqzI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c01cec7-ba2a-41a6-a3ad-e346edec2f4a_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!fqzI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c01cec7-ba2a-41a6-a3ad-e346edec2f4a_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!fqzI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c01cec7-ba2a-41a6-a3ad-e346edec2f4a_1672x941.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!fqzI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c01cec7-ba2a-41a6-a3ad-e346edec2f4a_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6c01cec7-ba2a-41a6-a3ad-e346edec2f4a_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1216351,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/207691626?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c01cec7-ba2a-41a6-a3ad-e346edec2f4a_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fqzI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c01cec7-ba2a-41a6-a3ad-e346edec2f4a_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!fqzI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c01cec7-ba2a-41a6-a3ad-e346edec2f4a_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!fqzI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c01cec7-ba2a-41a6-a3ad-e346edec2f4a_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!fqzI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c01cec7-ba2a-41a6-a3ad-e346edec2f4a_1672x941.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p><em>Figure 2: Monitoring information travels toward the control centre, while protection can trip equipment locally without waiting for a remote decision.</em></p><h3>Why the screen can be wrong</h3><p>SCADA is often described as real time, but that does not mean every point reflects physical reality at the same instant.</p><p>Measurements are sampled and transmitted at different rates. Communication links can fail. A value can become stale. A breaker indication can disagree with the actual contact position. A substation may be in a temporary configuration that the central model does not yet represent. Sensors have errors, and some values are calculated rather than directly measured.</p><p>This creates an <strong>observability</strong> problem. Operators need enough trustworthy information to determine the state of the network, even when individual measurements are missing or inconsistent.</p><h3>State estimation reconstructs a coherent picture</h3><p><strong>State estimation</strong> combines telemetry with the electrical network model and the current topology. It checks whether measurements agree with each other, identifies likely bad data and estimates the bus voltages and phase angles that best explain the available information.</p><p>The resulting state is still an estimate. Its value comes from making the overall picture more coherent than a raw collection of telemetry points.</p><p>This estimated state becomes an input to other Energy Management System applications. Power-flow analysis calculates how power is moving through the network. Contingency analysis simulates possible outages. Security assessment identifies violations of operational limits. Forecasting tools compare the present with expected demand and generation.</p><p><strong>Automatic generation control</strong>, usually implemented within the European load-frequency control process, uses frequency and control-area interchange information to calculate the area imbalance and adjust participating resources. It does not replace the dispatcher. It performs a continuous control loop inside objectives and limits established by grid operation.</p><p>SCADA is therefore a central part of the picture, but it is only one layer. The control room needs telemetry, models, specialised applications, automatic controllers, procedures and experienced operators. Treating the SCADA screen as the grid itself would be like treating a monitoring dashboard as the production system.</p><h2>What the Grid Must Control</h2><p>Once the operator has a usable picture of the network, the next question is what can be changed.</p><p>There is no single control knob for stability. Different mechanisms influence different parts of the operating state, and changing one variable often affects several others.</p><h3>Frequency control and reserves</h3><p>When active-power generation and consumption stop matching, frequency begins to move. The response is organised in layers because no resource is simultaneously instantaneous, unlimited, cheap and available everywhere.</p><p>The first physical response comes from stored energy in rotating machines and, increasingly, fast controls in batteries and inverter-based resources. This slows the frequency movement but does not remove the underlying imbalance.</p><p>The first organised reserve layer in Continental Europe is <strong>Frequency Containment Reserve</strong>, or <strong>FCR</strong>. Participating generators, storage systems and loads monitor frequency locally and change active power automatically. A falling frequency causes upward response, which means more generation or less consumption. A rising frequency causes downward response.</p><p>FCR is shared across the synchronous area. Resources respond to the common frequency deviation regardless of which control area caused it. Its immediate purpose is containment: stop the deviation from growing and stabilise frequency.</p><p>A <strong>reserve</strong> is available upward or downward power held by a prequalified resource. The resource might be a hydro plant with headroom, a thermal unit operating below maximum output, a battery with charge available, a pumped-storage plant that can stop pumping, or an industrial load able to reduce consumption. Reserving capacity means keeping part of that flexibility unused during normal operation so it is available when needed.</p><p>Once the common response has contained the disturbance, the responsible control area must restore its own balance. <strong>Automatic Frequency Restoration Reserve</strong>, or <strong>aFRR</strong>, is activated by the load-frequency controller, often described more generally as automatic generation control. It adjusts selected resources so frequency and scheduled cross-border exchanges move back toward their targets.</p><p>If the imbalance is too large or lasts too long, <strong>manual Frequency Restoration Reserve</strong>, or <strong>mFRR</strong>, provides another layer. It replaces part of the automatic response and prevents aFRR from remaining occupied indefinitely.</p><p>As a concrete Austrian example, <a href="https://markt.apg.at/en/power-grid/balancing/">Austrian Power Grid&#8217;s balancing overview</a> describes FCR as an automatic response that must reach full activation within 30 seconds when the frequency deviation reaches 0.2 Hz. APG states that aFRR must activate within five minutes in the Austrian control area, while automatic and manual restoration reserves together must cover foreseeable balancing errors within 15 minutes. The exact products and rules belong to the European balancing framework and national implementation, but the sequence is the important part:</p><ol><li><p>Slow the frequency change.</p></li><li><p>Contain the deviation.</p></li><li><p>Restore the responsible control area.</p></li><li><p>Replace the used reserves and prepare for another event.</p></li></ol><h3>Voltage control and reactive power</h3><p>Frequency control works across the synchronous system. Voltage control is more local because voltage differs between buses and because transporting reactive power over long distances consumes current and network capacity.</p><p>Synchronous generators regulate voltage through their excitation systems. Increasing excitation allows a generator to supply more reactive power within its capability limits, while reducing excitation can make it absorb reactive power. Power-electronic converters can also provide controlled reactive current, although their capability depends on their design, current limits and active-power operating point.</p><p>Transformer <strong>tap changers</strong> adjust the turns ratio and therefore the voltage relationship between network levels. They are useful for maintaining a downstream voltage, but they do not create missing power. Under stressed conditions, repeatedly raising a distribution-side voltage can increase the demand seen by an already weak transmission system, which is why tap control may need to be coordinated or blocked during a voltage emergency.</p><p><strong>Capacitor banks</strong> supply reactive power and tend to support local voltage. <strong>Reactors</strong> absorb reactive power and help reduce excessive voltage, especially on lightly loaded high-voltage lines and cables. Devices such as STATCOMs and synchronous condensers provide dynamic reactive-power support when voltage needs to change quickly.</p><p>The EU System Operation Guideline treats voltage and reactive-power management as a direct operational responsibility. It lists </p><p>transformer tap changes, capacitor and reactor switching, power-electronic devices, generator reactive-power setpoints and coordinated actions with distribution operators among the available remedial actions.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!n_xL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F537a204d-6aca-4340-9ab5-aa035f8736da_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!n_xL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F537a204d-6aca-4340-9ab5-aa035f8736da_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!n_xL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F537a204d-6aca-4340-9ab5-aa035f8736da_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!n_xL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F537a204d-6aca-4340-9ab5-aa035f8736da_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!n_xL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F537a204d-6aca-4340-9ab5-aa035f8736da_1672x941.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!n_xL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F537a204d-6aca-4340-9ab5-aa035f8736da_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/537a204d-6aca-4340-9ab5-aa035f8736da_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1269634,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/207691626?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F537a204d-6aca-4340-9ab5-aa035f8736da_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!n_xL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F537a204d-6aca-4340-9ab5-aa035f8736da_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!n_xL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F537a204d-6aca-4340-9ab5-aa035f8736da_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!n_xL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F537a204d-6aca-4340-9ab5-aa035f8736da_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!n_xL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F537a204d-6aca-4340-9ab5-aa035f8736da_1672x941.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p><em>Figure 3: Operators manage several coupled problems at once. Active power strongly affects frequency, reactive power strongly affects voltage, and topology determines how both move through the network.</em></p><h3>Power-flow control and redispatch</h3><p>Operators cannot assign a route to each unit of power, but they can change the conditions that determine the flows.</p><p>Opening or closing selected breakers changes the topology. Transformer taps and phase-shifting transformers influence voltage and the distribution of active power. HVDC links can use controlled setpoints. Generation and consumption can be changed at specific locations.</p><p>One of the main tools is <strong>redispatch</strong>. A generator in one location increases output while another decreases output, keeping the total generation approximately balanced but changing where power enters the network.</p><p>Suppose a northern generator is increasing the loading of a constrained north-to-south corridor, while another plant closer to the southern load has spare capacity. Reducing the northern plant and increasing the southern plant can relieve the corridor without changing the total amount of generation.</p><p>Redispatch shows why a megawatt is not operationally identical in every location. The energy amount may be the same, but the effect on line loading, losses, voltage and contingency margins depends on where it is injected.</p><h2>Normal Operation Is Already Active Work</h2><p>A control room is not a fire brigade waiting for the next alarm. Normal operation requires continuous preparation because the safe state for the next hour may differ from the safe state now.</p><p>Demand follows daily and seasonal patterns but never matches a forecast exactly. Wind and solar output change with the weather. Generators start, stop and change output. International exchanges follow schedules while actual physical flows respond to the complete interconnected network. Equipment enters and leaves service for inspection, repair and construction.</p><p>Operators prepare switching programs before planned work. They confirm which breakers and disconnectors must change position, how the equipment will be isolated, what interlocks and safety procedures apply, and what the resulting topology means for the rest of the network.</p><p>An outage that is harmless during low demand may be unacceptable during a winter evening. Two individually reasonable maintenance plans may conflict because taking both assets out at once would remove the system&#8217;s ability to survive a further failure. This is why outage coordination extends across substations, companies and national borders.</p><p>The operator also watches <strong>operational limits</strong>. These include line and transformer loading, bus voltages, generator active and reactive capability, reserve availability, short-circuit levels and stability constraints. Some limits are immediate. Others permit a short overload while corrective action is prepared.</p><p>When analysis shows that one additional failure would violate a limit, the grid may enter an alert state even though all customers are still supplied and frequency is close to 50 Hz. The system is operating, but the safety margin has become too small.</p><p>The response might be preventive redispatch, returning an out-of-service line, changing topology, adjusting reactive-power resources, restricting a planned transfer or postponing maintenance. Good operation often looks uneventful because the risky state was corrected before a second event exposed it.</p><p>Coordination matters because the electrical system ignores organisational borders. A remedial action in one country can change flows in another. A distribution operator may control generators and reactive-power resources that affect the transmission grid. A power plant may own the machine, while the transmission operator is responsible for the wider system state. The <a href="https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX%3A32017R1485">EU System Operation Guideline</a> formalises much of this data exchange and operational coordination between TSOs, DSOs and significant grid users.</p><h2>A Large Generator Disconnects</h2><p>We now have enough vocabulary to follow the failure from the opening example.</p><p>Assume a large synchronous generator is supplying 1,000 MW of active power and a meaningful amount of reactive power. A problem inside the plant causes its protection system to trip the unit and open the generator circuit breaker.</p><p>The exact numbers in the following sequence depend on the system state, but the order of responsibilities is stable.</p><h3>The protection system disconnects the generator</h3><p>The first action belongs to plant or generator protection. A relay detects a condition that makes continued connection unsafe, then commands the relevant circuit breaker to open.</p><p>This action protects the generator and the nearby electrical system. It may happen before the transmission control room knows that anything is wrong.</p><p>The breaker changes the topology. Active-power injection falls by 1,000 MW. The generator&#8217;s reactive-power contribution disappears as well. From that instant, the network has a new physical state.</p><h3>Generation becomes lower than demand</h3><p>Consumers have not coordinated with the failed plant. Their motors, heaters, trains and computers continue drawing power.</p><p>Total active-power generation is now lower than total active-power demand. The missing 1,000 MW is not supplied by one designated replacement generator during the first instant. The difference is initially supplied mainly by kinetic energy stored in the rotating masses of connected machines, while fast converter-based resources may also begin responding.</p><p>The electrical torque on the remaining synchronous generators becomes slightly greater than the mechanical torque supplied by their turbines. Their rotors slow down together, and the system frequency begins to fall.</p><p>This response is physical. No operator has selected it, and no SCADA command has caused it.</p><h3>Local controls and FCR respond</h3><p>Generator governors and other frequency-sensitive controllers detect the frequency change locally. Resources providing FCR begin increasing active-power injection or reducing consumption.</p><p>A hydro unit may open its guide vanes. A thermal unit may increase turbine input within its available headroom. A battery may inject power quickly. A pumped-storage plant may reduce pumping load. A flexible industrial consumer may lower demand.</p><p>These resources are distributed across the synchronous area. They do not need to know which generator failed. Frequency provides the common signal.</p><p>The reserve response grows while frequency is still falling. Eventually the additional power matches the deficit closely enough to stop the decline. The lowest point reached is called the <strong>frequency nadir</strong>.</p><p>If the response is sufficient, frequency stabilises. It may remain below 50 Hz because containment has stopped the movement without yet restoring the original balance.</p><h3>Voltage and power flows change at the same time</h3><p>The failed generator may have supported the voltage near its connection point. Losing its reactive-power capability can cause local voltage to fall, even while the frequency event is visible across the whole synchronous area.</p><p>Nearby automatic voltage regulators respond within their limits. Capacitors, reactors, converter controls or transformer taps may also act, depending on the network and configured control modes.</p><p>At the same time, active power begins entering the affected region from other generators through the transmission network. Flows redistribute across many lines. A corridor that previously carried moderate power may become heavily loaded because the local generator is no longer serving nearby demand.</p><p>This is where the graph from Part 2 becomes operational. The missing injection changes conditions across the network, and the most stressed line may be far from the failed plant.</p><h3>Measurements and alarms reach the control centre</h3><p>The generator breaker status changes. Active and reactive output measurements drop. Frequency values move. Nearby line flows and bus voltages change. Plant systems and substations create time-stamped events and alarms.</p><p>IEDs and RTUs forward this information through the operational communication network. SCADA updates the one-line diagram and alarm list. The operator may see a generator trip alarm, changed line colours, a frequency deviation and several secondary alarms caused by the same event.</p><p>These messages arrive after the physical system has already responded. They are evidence of the new state, not the trigger for the initial system-wide reaction.</p><p>Alarm handling is also harder than reading one clear error message. One event can produce hundreds of signals, some arriving out of order because different devices and communication paths have different delays. Operators and software need to distinguish the initiating event from its consequences.</p><h3>State estimation and security analysis assess the new grid</h3><p>The control centre now needs to answer several questions:</p><ul><li><p>Was the generator the only element lost?</p></li><li><p>Are the received breaker states and measurements consistent?</p></li><li><p>Which lines and transformers are now more heavily loaded?</p></li><li><p>Has local voltage remained within its limits?</p></li><li><p>How much FCR and reactive-power capability is still available?</p></li><li><p>Can the grid survive the loss of another important component?</p></li></ul><p>State estimation combines the new telemetry and topology with the network model. Power-flow and contingency-analysis applications calculate the current loading and simulate further outages.</p><p>The result may show that the frequency event is contained while the network is still unsafe. Perhaps one transmission corridor is close to its thermal limit. Perhaps local voltage is low. Perhaps the largest remaining generator has become the next critical contingency.</p><p>This is why returning frequency toward 50 Hz is necessary but insufficient. The full operating state must be secure.</p><h3>aFRR and automatic generation control restore the area</h3><p>FCR support came from across the synchronous area. The control area where the imbalance occurred must now restore its own balance and release that shared support.</p><p>The load-frequency controller calculates the control error from frequency and scheduled interchange. Through automatic generation control, it sends changing setpoints to resources providing aFRR.</p><p>These resources gradually add active power until the control-area imbalance is corrected. As aFRR takes over, FCR returns toward its neutral position and becomes available for the next disturbance.</p><p>If the outage lasts or the required correction is too large, mFRR and other slower actions replace part of the automatic response.</p><h3>Operators create a new secure state</h3><p>The failed generator may remain unavailable for hours. Operators cannot treat the restored frequency as the end of the incident.</p><p>They may redispatch generation so replacement power comes from locations that do not overload the network. They may start another plant, change pumped-storage operation, adjust cross-border schedules, switch reactive-power equipment, request new voltage setpoints or change the network topology.</p><p>They also need to restore reserve margins. A battery that delivered immediate power may need to recharge. Hydro and thermal units providing aFRR need room to respond in both directions again. The system should be able to survive another credible failure rather than remain balanced only while nothing else goes wrong.</p><p>The final state may look different from the state before the trip. A different set of generators is running, power flows use different corridors, reserve allocations have changed and some equipment may remain disconnected.</p><p>Recovery therefore means reaching a secure operating state, not recreating the exact previous state.</p><h3>The same event on one timeline</h3><ul><li><p><strong>Milliseconds:</strong> Protection detects the plant condition and trips the breaker. <em>Local and automatic protection.</em></p></li><li><p><strong>First electrical instant:</strong> Power flows change and rotating machines release stored energy. <em>Physical response.</em></p></li><li><p><strong>First seconds:</strong> Frequency-sensitive controls and FCR increase power or reduce load. <em>Distributed automatic control.</em></p></li><li><p><strong>Seconds to minutes:</strong> Telemetry, events and alarms reach SCADA; state estimation reconstructs the network. <em>Monitoring and operational software.</em></p></li><li><p><strong>Minutes:</strong> aFRR and automatic generation control restore the control area. <em>Central automatic control.</em></p></li><li><p><strong>Minutes to tens of minutes:</strong> mFRR, redispatch, voltage actions and topology changes establish a secure state. <em>Automatic and operator-initiated control.</em></p></li><li><p><strong>Hours and beyond:</strong> Rescheduling, reserve replenishment, investigation and repair continue. <em>Operation and asset management.</em></p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uwE_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0f7465b-effe-45c5-8f83-41552963940e_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uwE_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0f7465b-effe-45c5-8f83-41552963940e_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!uwE_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0f7465b-effe-45c5-8f83-41552963940e_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!uwE_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0f7465b-effe-45c5-8f83-41552963940e_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!uwE_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0f7465b-effe-45c5-8f83-41552963940e_1672x941.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!uwE_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0f7465b-effe-45c5-8f83-41552963940e_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f0f7465b-effe-45c5-8f83-41552963940e_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1356976,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/207691626?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0f7465b-effe-45c5-8f83-41552963940e_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!uwE_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0f7465b-effe-45c5-8f83-41552963940e_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!uwE_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0f7465b-effe-45c5-8f83-41552963940e_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!uwE_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0f7465b-effe-45c5-8f83-41552963940e_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!uwE_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff0f7465b-effe-45c5-8f83-41552963940e_1672x941.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p><em>Figure 4: A generator loss is handled by several overlapping layers. Physics and local automation contain the first moments, while central controls and operators rebuild a secure system.</em></p><h2>If the Normal Response Is Not Enough</h2><p>The scenario above ends well because the protection system isolates the plant cleanly, reserves are sufficient and the network has enough remaining capacity.</p><p>A larger event, several simultaneous outages or a weak initial state can exhaust those layers.</p><p>If frequency continues falling, automatic under-frequency schemes can disconnect blocks of load. Removing consumers is damaging, but it can rebalance an island or synchronous area before generators also disconnect and the entire system collapses.</p><p>If voltage keeps falling, operators and automatic schemes may use all available reactive-power support, block transformer tap changers, reduce voltage targets or disconnect demand. If power flows remain outside safe limits, equipment may be switched, generation may be redispatched, transfers may be reduced and, in an emergency, selected loads may be disconnected.</p><p>These measures are defined in system defence plans. The European framework for emergency and restoration operation is set out in <a href="https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX%3A32017R2196">Regulation (EU) 2017/2196</a>.</p><p>Protection still has a difficult role. If an overloaded line trips, its flow redistributes over the remaining network. Another line may then exceed its limit and trip as well. Each relay may be correctly protecting its own asset while the sequence weakens the wider system.</p><p>This is the basic mechanism behind a cascading outage:</p><ol><li><p>One element disconnects.</p></li><li><p>Flows and voltages redistribute.</p></li><li><p>Another element exceeds its limits.</p></li><li><p>Protection disconnects it.</p></li><li><p>The remaining network receives even more stress.</p></li></ol><p>The grid may eventually split into electrical islands. Each island must immediately balance its own generation and load. An island with too little generation experiences falling frequency, while an island with too much generation experiences rising frequency.</p><p>Emergency controls attempt to stop the cascade, preserve stable islands and keep as much of the system supplied as possible.</p><h2>Different Disturbances Stress Different Layers</h2><p>The generator loss gives us a useful complete story, but it should not become a template for every event.</p><p>A <strong>transmission line fault</strong> begins with a short circuit or another abnormal electrical condition. Line protection detects the fault and opens breakers at one or both ends, often within a fraction of a second. Generation and demand may remain nearly balanced, so the initial frequency change can be small, while the main operational problem is redistributed power flow and reduced transmission margin.</p><p>A <strong>transformer outage</strong> can remove the connection between voltage levels or parts of a substation. The result may be a local supply problem, overloaded parallel transformers, changed short-circuit levels or a voltage issue rather than a large system-wide frequency event.</p><p>A sudden rise in <strong>reactive-power demand</strong>, perhaps from large motors or a heavily loaded region, can depress local voltage while total active-power generation still matches consumption. Frequency can remain close to 50 Hz while part of the network approaches voltage instability.</p><p>A <strong>regional separation</strong> creates the clearest example of the system&#8217;s coupled nature. Once tie lines open, the two sides no longer share one active-power balance. Each island follows its own imbalance and frequency trajectory.</p><p>Protection, monitoring, operation and control appear in every case, but their order and relative importance change with the physical disturbance.</p><h2>Where the Distributed-Systems Analogy Helps</h2><p>We can now return to the failed data centre.</p><p>Both systems need observability. Operators need trustworthy measurements, event histories, health information and models that explain what is connected and available.</p><p>Both need spare capacity. A service without compute headroom cannot absorb traffic from a failed region. A grid without active-power reserves, reactive capability or transmission margin cannot absorb an electrical outage safely.</p><p>Both use layered response. Local components handle some failures automatically, central systems coordinate wider recovery, and human operators intervene when the event crosses the assumptions built into automation.</p><p>Both can operate in a degraded state. A service may remain available with higher latency and reduced redundancy. A grid may restore frequency while running with tighter transmission margins and less reserve.</p><p>Both need to prepare for the next failure. Recovering the current workload is not enough if the platform has lost all remaining redundancy. Restoring generation-load balance is not enough if the grid can no longer survive another contingency.</p><p>These similarities make distributed systems a useful starting point for developers entering the energy industry.</p><h2>Where the Analogy Stops</h2><p>The limitations matter just as much.</p><p>Software work can often be queued. Electrical load continues interacting with the network at every instant.</p><p>Software traffic can be assigned to a region or route. AC power divides across the connected network according to impedance, voltage and phase angle.</p><p>Many software failures remain local until another component calls the failed service. An electrical disconnection changes the physical state of the wider network immediately.</p><p>A monitoring system in software may detect a problem before users notice it. In the grid, frequency, voltage and current may already be moving before the control centre receives the first event.</p><p>Software replicas can disagree temporarily while eventual consistency resolves the difference. The synchronous grid has shared physical variables that must remain inside narrow limits continuously.</p><p>Finally, grid control actions feed back into the same physical system being measured. Opening a breaker to remove an overload changes flows elsewhere. Raising a downstream voltage can increase demand on an upstream network. Increasing one generator can relieve frequency while worsening congestion.</p><p>This is why grid software cannot be designed only as ordinary enterprise software with stricter availability requirements. It participates in a control loop around a large physical machine.</p><h2>The Mental Model to Keep</h2><p>A developer does not need to become a protection engineer or a control-room dispatcher to understand where grid software fits. The following model is enough to organise the vocabulary:</p><ol><li><p><strong>Physics moves first.</strong> Changes in generation, load or topology immediately affect frequency, voltage, current and power flow.</p></li><li><p><strong>Protection removes immediate danger.</strong> Relays and circuit breakers isolate faults locally and quickly.</p></li><li><p><strong>Monitoring constructs visibility.</strong> Field measurements, substation devices, communications, SCADA and state estimation create an operational picture.</p></li><li><p><strong>Control changes the system.</strong> Governors, voltage regulators, reserves, automatic generation control, tap changers, reactive-power devices, redispatch and switching move the grid toward acceptable conditions.</p></li><li><p><strong>Operation chooses and coordinates the secure state.</strong> Dispatchers assess limits, contingencies, outages and available actions across organisational and national boundaries.</p></li></ol><p>None of these layers works alone. Protection can clear a fault but cannot replace lost generation. SCADA can show an overload but cannot decide which market and operational constraints matter. Reserves can restore active-power balance but cannot help if the replacement power has no safe transmission path. Operators cannot act effectively when measurements or models are wrong.</p><p>The European grid stays stable because these layers overlap across different timescales. Local physics and automation handle the first instant. Wide-area controls restore balance. Software helps operators understand the changing state. Human decisions rebuild enough margin for the next event.</p><p>In Part 1, we assembled the electromagnetic machine. In Part 2, we assembled the graph. Here, the graph became operational.</p><p>It is always changing, always measured and always being corrected. Stability is the result of that continuous work.</p><p><em>Next part:</em></p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;4300bce5-e9b2-4071-b8fd-288fc4d76996&quot;,&quot;caption&quot;:&quot;Previous part:&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;How Europe&#8217;s Power System Is Organised&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer exploring how complex systems are built. I take them apart, rebuild them from first principles, and trace the layers connecting software, networks, infrastructure, devices, and the physical world.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-08-01T19:35:39.907Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!EXqg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9ceb4d81-13de-47cf-9bab-d2f435ac5657_1672x941.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/how-europes-power-system-is-organised&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:209412144,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:3,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><p><em>All parts of the series:</em></p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;b78dc60c-b10a-4c26-aeea-153c17589160&quot;,&quot;caption&quot;:&quot;I have spent a lot of time learning technical systems by rebuilding them from first principles.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;A Developer&#8217;s Map of the European Power Grid&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer exploring how complex systems are built. I take them apart, rebuild them from first principles, and trace the layers connecting software, networks, infrastructure, devices, and the physical world.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-05-12T15:14:05.930Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!r2v5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b47f174-07bd-435f-9c8c-363edb0adbfd_1491x1055.png&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/a-developers-map-of-the-european&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:197363882,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:0,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><h2>References</h2><ul><li><p><a href="https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX%3A32017R1485">European Commission, Regulation (EU) 2017/1485 establishing a guideline on electricity transmission system operation</a></p></li><li><p><a href="https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX%3A32017R2196">European Commission, Regulation (EU) 2017/2196 establishing a network code on electricity emergency and restoration</a></p></li><li><p><a href="https://markt.apg.at/en/power-grid/balancing/">Austrian Power Grid, Balancing and frequency reserves</a></p></li><li><p><a href="https://csrc.nist.gov/pubs/sp/800/82/r3/final">NIST SP 800-82 Rev. 3, Guide to Operational Technology Security</a></p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">&#8216;Software in the Grid&#8217; is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item><item><title><![CDATA[Adding Homemade TLS to a Homemade Web Server]]></title><description><![CDATA[I combined my self-written web server and my self-written TLS project. The surprising part was how little the HTTP layer needed to know.]]></description><link>https://www.softwareinthegrid.com/p/adding-homemade-tls-to-a-homemade</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/adding-homemade-tls-to-a-homemade</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Sat, 04 Jul 2026 20:32:45 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!s2Hi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F272dd5c3-9c01-49fc-a311-175eec483b14_1672x941.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!s2Hi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F272dd5c3-9c01-49fc-a311-175eec483b14_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!s2Hi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F272dd5c3-9c01-49fc-a311-175eec483b14_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!s2Hi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F272dd5c3-9c01-49fc-a311-175eec483b14_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!s2Hi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F272dd5c3-9c01-49fc-a311-175eec483b14_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!s2Hi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F272dd5c3-9c01-49fc-a311-175eec483b14_1672x941.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!s2Hi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F272dd5c3-9c01-49fc-a311-175eec483b14_1672x941.png" width="1672" height="941" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/272dd5c3-9c01-49fc-a311-175eec483b14_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:&quot;normal&quot;,&quot;height&quot;:941,&quot;width&quot;:1672,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:0,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!s2Hi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F272dd5c3-9c01-49fc-a311-175eec483b14_1672x941.png 424w, https://substackcdn.com/image/fetch/$s_!s2Hi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F272dd5c3-9c01-49fc-a311-175eec483b14_1672x941.png 848w, https://substackcdn.com/image/fetch/$s_!s2Hi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F272dd5c3-9c01-49fc-a311-175eec483b14_1672x941.png 1272w, https://substackcdn.com/image/fetch/$s_!s2Hi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F272dd5c3-9c01-49fc-a311-175eec483b14_1672x941.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p><strong>Original series:</strong> <a href="https://dev.to/dmytro_huz/building-your-own-web-server-part-1-theory-and-foundations-3kgo">Building Your Own Web Server</a> + <a href="https://www.softwareinthegrid.com/p/rebuilding-tls-from-scratch-my-complete">Rebuilding TLS from Scratch</a></p><p>This article connects two earlier series. In the web-server series, I rebuilt the HTTP side from raw sockets up to routing and file serving. In the TLS series, I rebuilt the secure-channel side: key exchange, certificates, key derivation, and encrypted records.</p><p>This piece is where the two meet: what has to change when a web server stops receiving plaintext HTTP bytes and starts receiving encrypted TCP bytes?</p><p></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://dmytrohuz.substack.com/subscribe?utm_source=email&amp;r=&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://dmytrohuz.substack.com/subscribe?utm_source=email&amp;r="><span>Subscribe</span></a></p><div><hr></div><p>I expected adding TLS to my web server to change almost everything.</p><p>It did not.</p><p>The HTTP parser stayed boring. The router stayed boring. The file-serving code stayed boring.</p><p>The real change happened one layer below HTTP.</p><p>I had two separate learning projects before this:</p><ul><li><p>a small web server built from scratch: sockets, HTTP parsing, <code>location</code> matching, file serving, and eventually a single-threaded event-loop server;</p></li><li><p>a small TLS-like secure channel built from scratch: ephemeral key exchange, certificate chains, server authentication, HKDF, AES-GCM records, and the difference between identity keys and session keys.</p></li></ul><p>Putting them together led to one question:</p><blockquote><p>What changes in the web server when the bytes coming from TCP are encrypted?</p></blockquote><p>The useful answer is smaller than I expected:</p><pre><code>TCP socket
   &#8595;
TLS handshake / record layer
   &#8595; decrypted plaintext bytes
HTTP parser / router / file serving
   &#8595; plaintext HTTP response
TLS record protection
   &#8595; encrypted bytes
TCP socket
</code></pre><p>That is the whole architecture of the companion project.</p><p>This is not production HTTPS. It does not implement the real TLS 1.3 wire format, and browsers will not connect to it with <code>https://localhost:8443</code>.</p><p>It is a learning project. The goal is to make the integration boundary visible.</p><p>Once that boundary becomes clear, HTTPS feels much less magical.</p><div><hr></div><h2>The plain web server had one assumption</h2><p>Before TLS, the web server had a simple mental model.</p><p>A client connects over TCP. The server reads bytes from the socket. Those bytes are HTTP bytes. The server appends them to a per-connection buffer, tries to parse an HTTP request, matches the path, reads a file, and writes an HTTP response.</p><p>The flow looked like this:</p><pre><code>accept TCP connection
   &#8595;
read bytes from socket
   &#8595;
append bytes to HTTP input buffer
   &#8595;
parse HTTP request
   &#8595;
match URL against location config
   &#8595;
read file from root
   &#8595;
write HTTP response
</code></pre><p>The buffer is important because TCP is a stream.</p><p>One <code>recv()</code> call can give you half a request. Or exactly one request. Or multiple requests joined together. The parser cannot assume that one socket read equals one HTTP request.</p><p>In my server, the parser consumes complete HTTP messages from a buffer. If the request is incomplete, the server waits for more bytes. If there are extra bytes after a complete request, they stay in the buffer for the next parse.</p><p>For plain HTTP, socket bytes and HTTP bytes are the same thing:</p><pre><code>context.http_input.append(data)
self._handle_http_messages(context)
</code></pre><p>That line works only because the bytes from the socket are already plaintext HTTP.</p><p>TLS breaks that assumption.</p><div><hr></div><h2>After TLS, socket bytes are no longer HTTP bytes</h2><p>Once TLS is added, the TCP socket no longer carries a readable HTTP request.</p><p>The client still wants to send this:</p><pre><code>GET / HTTP/1.1
Host: localhost
Connection: close
</code></pre><p>But that request is not placed directly on the wire.</p><p>It is wrapped inside TLS records. After the handshake, those records are encrypted and authenticated. The bytes arriving at the server socket are now protocol bytes for the TLS layer, not text for the HTTP parser.</p><p>That is the shift:</p><pre><code>plain listener:
TCP bytes are HTTP bytes

TLS listener:
TCP bytes are TLS records
TLS records decrypt into HTTP bytes
</code></pre><p>If the HTTP parser starts caring about certificates, keys, record sequence numbers, or AES-GCM tags, the abstraction has leaked.</p><p>The HTTP parser should parse HTTP.</p><p>The TLS layer should turn unsafe network bytes into authenticated plaintext bytes.</p><div><hr></div><h2>The integration point belongs below HTTP</h2><p>Production servers use the same high-level boundary.</p><p>NGINX does not ask the HTTP parser to understand encrypted TLS records. A TLS implementation such as OpenSSL handles the connection security first. After that, the HTTP processing layer receives plaintext HTTP bytes.</p><p>My project copies that architecture in a smaller educational form:</p><pre><code>Production-ish mental model:
TCP &#8594; OpenSSL/TLS state &#8594; plaintext HTTP &#8594; NGINX HTTP processing

This project:
TCP &#8594; ToyTLSServerConnection &#8594; plaintext HTTP &#8594; HTTPParser / route matcher
</code></pre><p>The analogy is architectural, not protocol-compatible.</p><p>The project uses a small TLS-like protocol so the moving pieces are possible to read in one sitting. The handshake messages are simplified. The record framing is simplified. Many real TLS 1.3 details are missing on purpose.</p><p>But the boundary is the point:</p><pre><code>socket bytes in
   &#8595;
connection layer decides whether they are plain HTTP or TLS records
   &#8595;
HTTP layer receives plaintext HTTP bytes either way
</code></pre><p>That boundary lets the same HTTP code serve both ports.</p><div><hr></div><h2>The config makes the boundary visible</h2><p>The server uses an NGINX-style config because that was part of the original web-server project.</p><p>A single server block can listen on a plain port and on a TLS port:</p><pre><code>http {
    server {
        listen 8080;
        listen 8443 ssl;
        server_name localhost;

        ssl_certificate certs/server_cert.pem;
        ssl_certificate_key certs/server_key.pem;
        ssl_certificate_chain certs/intermediate_cert.pem;

        location / {
            root html;
        }
    }
}
</code></pre><p><code>listen 8080;</code> creates a normal HTTP listener.</p><p><code>listen 8443 ssl;</code> creates a listener that attaches TLS state to every accepted connection.</p><p>Both listeners still share the same routing and file-serving code. The difference is what happens between <code>recv()</code> and <code>HTTPParser.parse_message(...)</code>.</p><p>That is the part I wanted the project to expose.</p><div><hr></div><h2>The blocking TLS demo had to become a state machine</h2><p>The original TLS demo was linear and blocking.</p><p>That is perfect for teaching the handshake:</p><pre><code>receive ClientHello
send ServerHello
send ServerAuth
receive encrypted request
send encrypted response
</code></pre><p>But the web server I wanted to integrate with was not a one-client-at-a-time demo. It was a selectors-based server.</p><p>One event loop handles listening sockets and client sockets. A slow client should not freeze the whole process. That means the TLS implementation cannot sit inside a function waiting for the next record to arrive.</p><p>So the TLS code had to become buffer-oriented.</p><p>Instead of blocking on the socket, the TLS connection exposes three operations:</p><pre><code>tls.feed_wire_data(socket_bytes)
pending = tls.pop_pending_wire_data()
plaintext = tls.read_plaintext()
</code></pre><p><code>feed_wire_data(...)</code> accepts whatever bytes TCP happened to deliver.</p><p><code>pop_pending_wire_data()</code> returns handshake bytes or encrypted application data that need to be sent back to the client.</p><p><code>read_plaintext()</code> returns decrypted HTTP bytes after the TLS layer has enough complete records to process.</p><p>The web server does not need to know whether TCP split a TLS record into three reads or merged several records together. The TLS record buffer owns that problem.</p><p>That small interface is the bridge between the two projects.</p><div><hr></div><h2>Plain and TLS reads now differ by one layer</h2><p>Here is the core read path in the integrated server.</p><p>For plain HTTP, the socket bytes go directly into the HTTP input buffer:</p><pre><code># Plain path: socket bytes are already HTTP bytes.
context.http_input.append(data)
self._handle_http_messages(context)
</code></pre><p>For the TLS listener, the same socket bytes first pass through the TLS connection state:</p><pre><code># TLS path: socket bytes are handshake/application records, not HTTP.
context.tls.feed_wire_data(data)
self._queue_output(context, context.tls.pop_pending_wire_data())

plaintext = context.tls.read_plaintext()
if plaintext:
    context.http_input.append(plaintext)
    self._handle_http_messages(context)
</code></pre><p>The HTTP handler never receives encrypted bytes. It receives plaintext after the TLS layer has done its job.</p><p>After that, request handling is the same:</p><pre><code>request, consumed = HTTPParser.parse_message(context.http_input.data)
context.http_input.reduce_data(consumed)
response, should_close = build_http_response(request, context.server_block, self.base_dir)
self._send_application_bytes(context, response)
</code></pre><p>The response path mirrors the read path.</p><p>The HTTP layer builds a normal plaintext HTTP response. If the connection is plain HTTP, those bytes are written directly to the socket. If the connection is TLS, the server wraps the response in an encrypted application record first.</p><pre><code>if context.tls is not None:
    wire = context.tls.protect_application_data(plaintext_response)
else:
    wire = plaintext_response
</code></pre><p>This is the part I like most about the final design.</p><p>The web server still feels like a web server.</p><p>TLS becomes a connection concern, not an HTTP concern.</p><div><hr></div><h2>What the toy TLS layer does</h2><p>The TLS-like layer in this project is intentionally small, but it keeps the important shape of the original TLS series.</p><p>The handshake starts with ephemeral X25519 keys.</p><p>The client sends a <code>ClientHello</code> containing its ephemeral public key. The server generates its own ephemeral key for this connection and sends back a <code>ServerHello</code>.</p><p>Then the server sends authentication material:</p><ul><li><p>the server certificate,</p></li><li><p>intermediate certificates,</p></li><li><p>a signature over the two ephemeral public keys.</p></li></ul><p>That signature is the simplified version of <code>CertificateVerify</code>. It proves that the peer presenting the certificate also controls the matching private key for this specific key exchange.</p><p>After that, both sides compute the same X25519 shared secret and derive directional AES-GCM keys through HKDF.</p><p>Directional keys matter. The client-to-server key protects client records. The server-to-client key protects server records.</p><pre><code>client_write_key: records sent by the client
server_write_key: records sent by the server
</code></pre><p>Application data records also carry sequence numbers into the authenticated encryption. That lets the receiver detect tampering and sequence mismatches.</p><p>Again, this is not real TLS 1.3. The real protocol has much more structure: transcript binding, alerts, Finished messages, SNI, ALPN, session resumption, real record headers, and many other details.</p><p>For learning the web-server boundary, the smaller version is enough:</p><pre><code>handshake creates keys
records protect HTTP bytes
HTTP parser sees only decrypted bytes
</code></pre><div><hr></div><h2>The useful lesson was not only cryptography</h2><p>I started the project thinking the interesting part would be TLS.</p><p>The cryptographic pieces do matter. It is useful to understand why ephemeral keys exist, why certificates are about identity rather than encryption, and why authenticated encryption needs sequence numbers.</p><p>But the integration lesson was more general.</p><p>When you add a lower-level protocol to an existing system, the hard part is often choosing the seam.</p><p>If the seam is wrong, everything above it starts learning details it should not know.</p><p>If the seam is right, most of the application code stays boring.</p><p>In this case, the seam is between TCP and HTTP.</p><p>The HTTP parser should not know about X25519. The route matcher should not know about certificates. The file-serving code should not care whether the client used the plain port or the TLS port.</p><p>Those parts operate on HTTP.</p><p>The connection layer is responsible for turning the outside world into HTTP bytes.</p><p>That pattern shows up in a lot of infrastructure code:</p><ul><li><p>network bytes become parsed messages,</p></li><li><p>encrypted records become plaintext streams,</p></li><li><p>unreliable external systems become retried operations,</p></li><li><p>hardware signals become typed events,</p></li><li><p>logs become structured facts.</p></li></ul><p>A design question I keep coming back to is:</p><blockquote><p>What should the next layer be allowed to assume?</p></blockquote><p>For this project, the HTTP layer is allowed to assume one thing:</p><pre><code>I receive plaintext HTTP bytes.
</code></pre><p>Everything below that belongs to the connection layer.</p><div><hr></div><h2>Why build this if it is not real HTTPS?</h2><p>A fair objection is: if the project is not browser-compatible, why build it?</p><p>For me, browser-compatible TLS is too large if the goal is to understand the integration boundary.</p><p>If I used OpenSSL directly, the project would be more practical, but the interesting internals would disappear behind a library call.</p><p>If I tried to implement full TLS 1.3, the project would become mostly about protocol correctness. That is valuable, but it would bury the web-server lesson under too much detail.</p><p>The educational middle ground is a TLS-like secure channel with the same high-level shape:</p><pre><code>handshake
certificate verification
key derivation
encrypted records
application data
</code></pre><p>Then I can integrate that channel into the web server as if it were a real TLS stack.</p><p>The result is small enough to read, but realistic enough to expose the architecture.</p><p>That is the kind of learning project I like: simplified around one specific question.</p><p>Here the question is:</p><blockquote><p>What does a web server need from TLS?</p></blockquote><p>My answer after building it:</p><blockquote><p>A secure byte stream that produces plaintext HTTP for the existing HTTP layer.</p></blockquote><div><hr></div><h2>How to run the companion project</h2><p>The repository is here:</p><p><a href="https://github.com/DmytroHuzz/tls_web_server">https://github.com/DmytroHuzz/tls_web_server</a></p><p>The visual walkthrough is here:</p><p><a href="https://dmytrohuzz.github.io/tls_web_server/">https://dmytrohuzz.github.io/tls_web_server/</a></p><p>From a fresh clone:</p><pre><code>python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install -e ".[dev]"
</code></pre><p>Then run the one-command demo:</p><pre><code>python3 scripts/demo.py
</code></pre><p>It starts the server in a background thread, sends one plain HTTP request, then sends one HTTP request through the self-written TLS-like layer.</p><p>Both paths should return:</p><pre><code>HTTP/1.1 200 OK
</code></pre><p>There are also separate <code>server_side.py</code> and <code>client_side.py</code> files if you want to see the workflow from each side, closer to the style of the original projects.</p><p>The tests cover the integration points that are easy to get wrong:</p><ul><li><p>fragmented TLS handshake records,</p></li><li><p>fragmented encrypted application records,</p></li><li><p>wrong DNS name certificate rejection,</p></li><li><p>tampered encrypted record rejection,</p></li><li><p>sequence-number mismatch rejection,</p></li><li><p>HTTP requests split across multiple encrypted TLS records,</p></li><li><p>the same web server serving plain HTTP and HTTP-over-self-written-TLS.</p></li></ul><div><hr></div><h2>The mental model I keep now</h2><p>Before building this, I would have described HTTPS as &#8220;HTTP with encryption.&#8221;</p><p>That is fine as a user-level description, but it is not precise enough when writing the server.</p><p>The server-side model that helped me is this:</p><pre><code>TCP gives bytes.
TLS turns encrypted bytes into authenticated plaintext bytes.
HTTP parses the plaintext bytes.
</code></pre><p>That sounds simple, but it changes where the code belongs.</p><p>You do not sprinkle TLS checks through the HTTP parser.</p><p>You do not make the route matcher aware of certificates.</p><p>You do not duplicate the file server for secure and insecure connections.</p><p>You put a protocol layer below HTTP and keep the rest of the server honest.</p><p>That is what I wanted from this project.</p><p>Not a production HTTPS server. Not a replacement for OpenSSL.</p><p>Just a clearer picture of where HTTPS belongs.</p><p>If you want to follow the full path from encrypted TCP bytes to a parsed HTTP request and back again, I put the code and visual walkthrough here:</p><ul><li><p>Companion repo: <a href="https://github.com/DmytroHuzz/tls_web_server">https://github.com/DmytroHuzz/tls_web_server</a></p></li><li><p>Visual walkthrough: <a href="https://dmytrohuzz.github.io/tls_web_server/">https://dmytrohuzz.github.io/tls_web_server</a></p></li></ul><p></p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:null,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p></p>]]></content:encoded></item><item><title><![CDATA[The Grid Is Not a Pipeline]]></title><description><![CDATA[The European Power Grid for Software Developers, Part 2]]></description><link>https://www.softwareinthegrid.com/p/the-grid-is-not-a-pipeline</link><guid isPermaLink="false">https://www.softwareinthegrid.com/p/the-grid-is-not-a-pipeline</guid><dc:creator><![CDATA[Dmytro Huz]]></dc:creator><pubDate>Fri, 29 May 2026 15:42:22 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!h0bv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b765de-ab75-4122-88be-17cf19c0eed2_1536x1024.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!h0bv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b765de-ab75-4122-88be-17cf19c0eed2_1536x1024.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!h0bv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b765de-ab75-4122-88be-17cf19c0eed2_1536x1024.jpeg 424w, https://substackcdn.com/image/fetch/$s_!h0bv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b765de-ab75-4122-88be-17cf19c0eed2_1536x1024.jpeg 848w, https://substackcdn.com/image/fetch/$s_!h0bv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b765de-ab75-4122-88be-17cf19c0eed2_1536x1024.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!h0bv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b765de-ab75-4122-88be-17cf19c0eed2_1536x1024.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!h0bv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b765de-ab75-4122-88be-17cf19c0eed2_1536x1024.jpeg" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/65b765de-ab75-4122-88be-17cf19c0eed2_1536x1024.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:465371,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/199757049?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b765de-ab75-4122-88be-17cf19c0eed2_1536x1024.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!h0bv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b765de-ab75-4122-88be-17cf19c0eed2_1536x1024.jpeg 424w, https://substackcdn.com/image/fetch/$s_!h0bv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b765de-ab75-4122-88be-17cf19c0eed2_1536x1024.jpeg 848w, https://substackcdn.com/image/fetch/$s_!h0bv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b765de-ab75-4122-88be-17cf19c0eed2_1536x1024.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!h0bv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65b765de-ab75-4122-88be-17cf19c0eed2_1536x1024.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 1: The old picture says power flows through a pipe. The real grid is a synchronized graph that must stay balanced in real time.</em></p><p>In the first part, we killed one comfortable idea: electricity is not water.</p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;f0d52ce4-1147-4329-91ad-00490462f616&quot;,&quot;caption&quot;:&quot;Most requirements in critical industries come from the physical world, and the power grid is no exception. Electricity has rules that cannot be negotiated with. Distance, geography, weather, forests, cities, mountains, sea cables, and even animals shape how the grid must be built and operated.&quot;,&quot;cta&quot;:null,&quot;showBylines&quot;:true,&quot;showDescription&quot;:true,&quot;showImage&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;Electricity Is Not Water: A Better Mental Model for the Grid&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:392416265,&quot;name&quot;:&quot;Dmytro Huz&quot;,&quot;bio&quot;:&quot;Software engineer exploring how complex systems are built. I take them apart, rebuild them from first principles, and trace the layers connecting software, networks, infrastructure, devices, and the physical world.&quot;,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4a14e6b-5f68-4257-9ee7-e33b8864d56a_1024x1024.png&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2026-05-15T15:10:24.614Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!sq_V!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c80b9e9-5ddd-4f0c-a4cb-2cb485003afe_1536x1024.jpeg&quot;,&quot;cover_image_alt&quot;:null,&quot;cover_image_crop&quot;:null,&quot;canonical_url&quot;:&quot;https://www.softwareinthegrid.com/p/electricity-is-not-water-a-better&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:197871484,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:3,&quot;comment_count&quot;:0,&quot;publication_id&quot;:6272314,&quot;publication_name&quot;:&quot;Software in the Grid&quot;,&quot;publication_logo_url&quot;:&quot;https://substackcdn.com/image/fetch/$s_!M0GQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3976cb25-61bb-4530-b5dc-5535b4b51445_1254x1254.png&quot;,&quot;belowTheFold&quot;:false,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><p>Now we can kill the next one.</p><p>The power grid is often imagined as a large water system. Somewhere far away there is a power plant, like a pump. Long power lines carry electricity, like pipes. The wires reach a city, then a street, then a house, and when someone opens the &#8220;tap&#8221; by switching on a device, electricity flows from the power plant into the socket.</p><p>It is simple. It is visual. It feels intuitive.</p><p>And it is almost the worst possible picture if you want to understand the real grid.</p><p>The grid is not a pipe where energy sits inside wires waiting to be consumed by devices. A power plant does not fill transmission lines with electrons and send them to your laptop, fridge, or washing machine. The real grid is a synchronized electromagnetic system. It works in real time. It oscillates. It has a frequency. It connects generators, consumers, transformers, substations, transmission lines, distribution grids, storage systems, and control centers into one huge machine.</p><p>And this machine has one brutal rule: generation and consumption must stay balanced all the time.</p><p>Consumers constantly change their behavior. Someone starts an industrial motor. A train accelerates. A factory begins a shift. A city wakes up in the morning. A cloud moves over a solar park. Wind generation rises or drops. A power plant ramps up, ramps down, or disconnects. Nothing is static, and still the whole system must remain synchronized.</p><p>In continental Europe, this synchronization is visible through the 50 Hz grid frequency. APG describes grid frequency as the measure of balance between electricity supply and demand, and one of its core tasks is to keep the system close to 50 Hz continuously. Austrian Power Grid</p><p>So no, the grid is not a pipe.</p><p>It is closer to a living technical machine whose operating state changes all the time. It is measured, switched, protected, transformed, corrected, and balanced continuously. Not because engineers enjoy complexity, but because the system would not work otherwise.</p><p>In this post we will discuss a better model for understanding the grid. We will stop looking at the fake &#8220;power plant to socket&#8221; diagram and rebuild the picture from the center outward. We will start with the high-voltage transmission grid, then attach substations, generators, storage systems, distribution grids, and consumers around it. After that, we will inspect a real slice of the Austrian grid and see how these abstract ideas appear in real infrastructure.</p><p>Because once we stop seeing the grid as a pipe, we can finally start seeing it as a graph.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Subscribe to follow how physical infrastructure, control systems, and software work together in the power grid.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><h2>The old diagram is already misleading</h2><p>Most explanations of the grid start with a power plant.</p><p>The diagram usually looks like this:</p><p>Power plant. Transmission line. Substation. Distribution line. House. Socket.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1fsH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff910e9f3-3f52-4da1-bf49-d28d9934d974_1536x1024.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1fsH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff910e9f3-3f52-4da1-bf49-d28d9934d974_1536x1024.jpeg 424w, https://substackcdn.com/image/fetch/$s_!1fsH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff910e9f3-3f52-4da1-bf49-d28d9934d974_1536x1024.jpeg 848w, https://substackcdn.com/image/fetch/$s_!1fsH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff910e9f3-3f52-4da1-bf49-d28d9934d974_1536x1024.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!1fsH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff910e9f3-3f52-4da1-bf49-d28d9934d974_1536x1024.jpeg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!1fsH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff910e9f3-3f52-4da1-bf49-d28d9934d974_1536x1024.jpeg" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f910e9f3-3f52-4da1-bf49-d28d9934d974_1536x1024.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:328114,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/199757049?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff910e9f3-3f52-4da1-bf49-d28d9934d974_1536x1024.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!1fsH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff910e9f3-3f52-4da1-bf49-d28d9934d974_1536x1024.jpeg 424w, https://substackcdn.com/image/fetch/$s_!1fsH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff910e9f3-3f52-4da1-bf49-d28d9934d974_1536x1024.jpeg 848w, https://substackcdn.com/image/fetch/$s_!1fsH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff910e9f3-3f52-4da1-bf49-d28d9934d974_1536x1024.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!1fsH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff910e9f3-3f52-4da1-bf49-d28d9934d974_1536x1024.jpeg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 2: This picture is easy to understand, but it already teaches the wrong architecture.</em></p><p>At first sight, this seems reasonable because electricity is generated somewhere and consumed somewhere else. But the moment we draw the system this way, we accidentally teach the reader the wrong architecture.</p><p>We make it look like electricity has a source, a route, and a destination. We make it look like a delivery system. A factory produces a product, a road transports it, and a customer receives it.</p><p>But the electrical grid is not a delivery route.</p><p>A generator does not produce a private stream of electricity for one city. A house does not receive electrons that started their journey at one specific power plant. A transmission line is not a pipe with a fixed direction. The grid is a shared synchronized system. Generators inject power into this system. Consumers withdraw power from it. Storage can do both. Power flows change depending on the current physical state of the network.</p><p>That is why starting with a power plant is already dangerous. It keeps us inside the pipe model.</p><p>A better starting point is the network itself. Not the generator, not the socket, but the grid.</p><h2>The grid is a graph, not a chain</h2><p>For a software developer, the better mental model is not a pipe. It is a graph.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Bn4m!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3e1c50-ec18-4aca-92fc-5b45e8cbb445_1536x1024.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Bn4m!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3e1c50-ec18-4aca-92fc-5b45e8cbb445_1536x1024.jpeg 424w, https://substackcdn.com/image/fetch/$s_!Bn4m!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3e1c50-ec18-4aca-92fc-5b45e8cbb445_1536x1024.jpeg 848w, https://substackcdn.com/image/fetch/$s_!Bn4m!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3e1c50-ec18-4aca-92fc-5b45e8cbb445_1536x1024.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!Bn4m!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3e1c50-ec18-4aca-92fc-5b45e8cbb445_1536x1024.jpeg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!Bn4m!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3e1c50-ec18-4aca-92fc-5b45e8cbb445_1536x1024.jpeg" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1f3e1c50-ec18-4aca-92fc-5b45e8cbb445_1536x1024.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:457526,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/199757049?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3e1c50-ec18-4aca-92fc-5b45e8cbb445_1536x1024.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Bn4m!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3e1c50-ec18-4aca-92fc-5b45e8cbb445_1536x1024.jpeg 424w, https://substackcdn.com/image/fetch/$s_!Bn4m!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3e1c50-ec18-4aca-92fc-5b45e8cbb445_1536x1024.jpeg 848w, https://substackcdn.com/image/fetch/$s_!Bn4m!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3e1c50-ec18-4aca-92fc-5b45e8cbb445_1536x1024.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!Bn4m!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1f3e1c50-ec18-4aca-92fc-5b45e8cbb445_1536x1024.jpeg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 3: A better model: high-voltage lines form the backbone, substations are nodes, and generation, storage, distribution, and consumers attach to the graph.</em></p><p>Transmission lines are edges. Substations are nodes. Generators, storage systems, distribution grids, industrial consumers, cities, and interconnectors are attached to this graph at different points.</p><p>But we need to be careful here, because this analogy can also become stupid if we push it too far.</p><p>The grid is not the internet. Power does not move like packets. There is no router that says, &#8220;send this megawatt through line A and this other megawatt through line B.&#8221; Power flows according to physics. It depends on voltage, impedance, phase angle, topology, and the current state of the synchronized system.</p><p>Still, the graph model is extremely useful because it breaks the one-way chain illusion.</p><p>In a chain, you start at one end and walk to the other end. In a graph, you first ask what is connected to what. That is exactly how we should look at the grid.</p><p>The high-voltage network is the backbone. Substations connect parts of the backbone to each other and to lower voltage levels. Generators inject power at some nodes. Consumers withdraw power through other nodes. Storage systems can either withdraw or inject, depending on the operating mode. Interconnectors connect countries and control areas. Protection systems watch the graph and disconnect faulty parts when something goes wrong.</p><p>This is already a much better picture.</p><p>The grid is not a road from a power plant to your socket. It is a synchronized graph whose state must be kept inside safe limits.</p><h2>Why we start with the high-voltage grid</h2><p>If we start with a house, the grid looks like a local supply problem.</p><p>If we start with a power plant, the grid looks like a delivery problem.</p><p>But if we start with the high-voltage grid, the architecture becomes visible.</p><p>The high-voltage grid is the strong skeleton of the system. It connects regions, countries, large generation sites, large consumption areas, and lower-voltage networks. In Austria, APG manages the transmission grid at 110 kV, 220 kV, and 380 kV. These voltage levels are used to transport electricity efficiently over long distances and to connect large parts of the country into one operating system. Austrian Power Grid</p><p>This is where the pipe analogy starts to completely fall apart.</p><p>A high-voltage line is not just a long cable from one plant to one city. It is part of a larger network. Depending on generation, consumption, outages, maintenance, weather, and market schedules, power flows can change. A line can carry more or less power. A region can import or export. A storage plant can consume power in pumping mode and produce power in turbine mode. The same physical infrastructure participates in many different operating situations.</p><p>At the European scale, this becomes even more obvious. ENTSO-E (<strong>European Network of Transmission System Operators for Electricity</strong>) provides a transmission system map showing power plants, converters, substations, and high-voltage cables and lines operated by European transmission system operators. The map is useful for seeing the scale and density of the interconnected transmission network, but it should not be read as exact geography because ENTSO-E notes that network elements are not placed at their precise geographic positions. ENTSO-E Transmission System Map</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TrdG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5102640e-09dd-450e-b5f5-7315b9ce2722_912x1072.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TrdG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5102640e-09dd-450e-b5f5-7315b9ce2722_912x1072.png 424w, https://substackcdn.com/image/fetch/$s_!TrdG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5102640e-09dd-450e-b5f5-7315b9ce2722_912x1072.png 848w, https://substackcdn.com/image/fetch/$s_!TrdG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5102640e-09dd-450e-b5f5-7315b9ce2722_912x1072.png 1272w, https://substackcdn.com/image/fetch/$s_!TrdG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5102640e-09dd-450e-b5f5-7315b9ce2722_912x1072.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!TrdG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5102640e-09dd-450e-b5f5-7315b9ce2722_912x1072.png" width="912" height="1072" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5102640e-09dd-450e-b5f5-7315b9ce2722_912x1072.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1072,&quot;width&quot;:912,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:763357,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/199757049?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5102640e-09dd-450e-b5f5-7315b9ce2722_912x1072.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!TrdG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5102640e-09dd-450e-b5f5-7315b9ce2722_912x1072.png 424w, https://substackcdn.com/image/fetch/$s_!TrdG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5102640e-09dd-450e-b5f5-7315b9ce2722_912x1072.png 848w, https://substackcdn.com/image/fetch/$s_!TrdG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5102640e-09dd-450e-b5f5-7315b9ce2722_912x1072.png 1272w, https://substackcdn.com/image/fetch/$s_!TrdG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5102640e-09dd-450e-b5f5-7315b9ce2722_912x1072.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 4: Even as a schematic, the European transmission system looks less like a pipe and more like a continental graph. Source: ENTSO-E.</em></p><p>That map is overwhelming, and that is exactly the point.</p><p>The European grid is not a simple line from source to load. It is a continental machine. So instead of trying to understand the whole map at once, we can zoom into one country and then into one real grid node.</p><p>Austria is a good place to do this because the APG grid gives us a concrete high-voltage backbone, and the Austrian grid does not stop at the border. It is part of the wider European synchronous system.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9GdN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24b8c950-51e0-4f0d-b5f0-e0892070c0b4_936x624.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9GdN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24b8c950-51e0-4f0d-b5f0-e0892070c0b4_936x624.png 424w, https://substackcdn.com/image/fetch/$s_!9GdN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24b8c950-51e0-4f0d-b5f0-e0892070c0b4_936x624.png 848w, https://substackcdn.com/image/fetch/$s_!9GdN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24b8c950-51e0-4f0d-b5f0-e0892070c0b4_936x624.png 1272w, https://substackcdn.com/image/fetch/$s_!9GdN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24b8c950-51e0-4f0d-b5f0-e0892070c0b4_936x624.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!9GdN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24b8c950-51e0-4f0d-b5f0-e0892070c0b4_936x624.png" width="936" height="624" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/24b8c950-51e0-4f0d-b5f0-e0892070c0b4_936x624.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:624,&quot;width&quot;:936,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:100553,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/199757049?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24b8c950-51e0-4f0d-b5f0-e0892070c0b4_936x624.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!9GdN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24b8c950-51e0-4f0d-b5f0-e0892070c0b4_936x624.png 424w, https://substackcdn.com/image/fetch/$s_!9GdN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24b8c950-51e0-4f0d-b5f0-e0892070c0b4_936x624.png 848w, https://substackcdn.com/image/fetch/$s_!9GdN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24b8c950-51e0-4f0d-b5f0-e0892070c0b4_936x624.png 1272w, https://substackcdn.com/image/fetch/$s_!9GdN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F24b8c950-51e0-4f0d-b5f0-e0892070c0b4_936x624.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 5: Austria&#8217;s transmission grid gives us a real backbone to inspect, with 110 kV, 220 kV, and 380 kV layers connected through substations. Source: Austrian Power Grid.</em></p><h2>Substations are the nodes where the graph becomes real</h2><p>Once we think in graphs, substations become much more interesting.</p><p>A substation is not just &#8220;the place where voltage goes down.&#8221; That is the school version. It is not completely wrong, but it is far too small.</p><p>A substation is a grid node.</p><p>It is a place where lines meet, voltage levels connect, transformers change voltage, breakers can connect or disconnect parts of the system, measurements are collected, faults are detected, and operators can change the topology of the network.</p><p>In graph language, a substation is where the abstract edge-and-node model becomes physical.</p><p>A transmission line arrives. Another line leaves. A transformer connects the 380 kV grid to the 220 kV grid or the 110 kV grid. A distribution network may be supplied from there. A power plant may be connected nearby. A breaker can disconnect a faulty line. Protection systems can isolate a damaged part of the network before the fault spreads further.</p><p>That is why substations are not secondary details. They are one of the main reasons the grid can be operated at all.</p><p>But in this article, we will not yet open the substation and inspect every component. Busbars, bays, breakers, disconnectors, transformers, protection relays, SCADA, and IEC 61850 deserve their own article. For now, we need only one idea:</p><p>A substation is a controllable node of the grid graph.</p><h2>A real example: Pongau substation</h2><p>Now let us stop speaking only in abstractions.</p><p>APG&#8217;s (<strong>Austrian Power Grid</strong>) Pongau substation is a good real-world example because it shows how much can happen at one node of the grid. </p><p>Pongau is a region in the Austrian federal state of Salzburg, south of the city of Salzburg and close to the Alpine hydropower and pumped-storage area around Kaprun and Tauern. You do not need to know Austrian geography to follow the argument. The only important point is that this node sits between several relevant grid directions.</p><p>APG describes Pongau as a newly constructed 380/220/110/30 kV substation in St. Johann im Pongau, commissioned in the first quarter of 2025 as part of the Salzburg line. The substation includes 380 kV GIS switchgear, two 380/220 kV transformers that connect the 380 kV and 220 kV grids, and two 380/110 kV transformers that connect the 380 kV and 110 kV grids. Austrian Power Grid, Pongau Substation</p><p>Before looking at the substation structure, we should first place it on the map. If you do not know Austrian geography, &#8220;Pongau&#8221; is just a name. The important thing is that it sits in a region where several relevant directions meet: toward Salzburg, toward Kaprun and Tauern, toward Wei&#223;enbach, and toward the regional Salzburg grid.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!P3_H!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4446f6a6-da4e-4c20-bd61-e46185248ad8_1536x1024.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!P3_H!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4446f6a6-da4e-4c20-bd61-e46185248ad8_1536x1024.jpeg 424w, https://substackcdn.com/image/fetch/$s_!P3_H!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4446f6a6-da4e-4c20-bd61-e46185248ad8_1536x1024.jpeg 848w, https://substackcdn.com/image/fetch/$s_!P3_H!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4446f6a6-da4e-4c20-bd61-e46185248ad8_1536x1024.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!P3_H!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4446f6a6-da4e-4c20-bd61-e46185248ad8_1536x1024.jpeg 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!P3_H!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4446f6a6-da4e-4c20-bd61-e46185248ad8_1536x1024.jpeg" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4446f6a6-da4e-4c20-bd61-e46185248ad8_1536x1024.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:224093,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/199757049?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4446f6a6-da4e-4c20-bd61-e46185248ad8_1536x1024.jpeg&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!P3_H!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4446f6a6-da4e-4c20-bd61-e46185248ad8_1536x1024.jpeg 424w, https://substackcdn.com/image/fetch/$s_!P3_H!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4446f6a6-da4e-4c20-bd61-e46185248ad8_1536x1024.jpeg 848w, https://substackcdn.com/image/fetch/$s_!P3_H!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4446f6a6-da4e-4c20-bd61-e46185248ad8_1536x1024.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!P3_H!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4446f6a6-da4e-4c20-bd61-e46185248ad8_1536x1024.jpeg 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 6: Pongau on the Austrian transmission map. </em></p><p>Pongau is not just a transformer in a field. It is a grid node where different voltage levels, transmission directions, pumped-storage connections, and regional distribution meet.</p><p>This is not a transformer in a field.</p><p>At this one node, different voltage levels meet. A 380 kV system from the Salzburg line is integrated. A connection continues toward Kaprun and Tauern. The 220 kV side connects toward Wei&#223;enbach. The 110 kV side connects to Salzburg Netz and the regional distribution grid. The 30 kV level is local or auxiliary in this simplified view, not a major transmission corridor.</p><p>This is exactly why the graph model is useful.</p><p>If we tried to explain Pongau with the pipe analogy, we would ask the wrong question: where does the electricity come from, and where does it go?</p><p>But the better question is: what does this node connect?</p><p>It connects voltage levels. It connects transmission paths. It connects regional distribution. It connects pumped storage. It strengthens supply reliability. It becomes part of the high-voltage architecture that allows the Austrian grid to operate as a system rather than as isolated local supply islands.</p><p>A substation like Pongau is not a passive object on the way from generator to consumer. It is part of the architecture that makes the whole system usable.</p><h2>Generators do not &#8220;send electricity to houses&#8221;</h2><p>Now that we have the graph, we can attach generators to it.</p><p>A generator is any facility that injects electrical power into the grid. It can be a hydropower plant, a gas plant, a wind farm, a solar plant, a biomass plant, or another generation source.</p><p>But the important word is injects.</p><p>A generator does not choose one household and send energy to it. It pushes power into the synchronized system. That changes the state of the system, and the physical network determines how power flows.</p><p>This is why the simple sentence &#8220;this power plant supplies this city&#8221; is often misleading. It may be true in an administrative, regional, or approximate sense, but electrically the situation is more complex. A power plant is connected to a grid node. Consumers are connected to other grid nodes. The system balances the total injection and withdrawal through the whole network.</p><p>Not let&#8217;s look at Kaprun.</p><p>Kaprun is a small municipality in the Austrian Alps, in the federal state of Salzburg, but in the Austrian power system the name means much more than a tourist village near mountains and reservoirs. The Kaprun area is closely associated with hydropower and pumped-storage infrastructure. It sits near the Alpine water reservoirs and power plants that can turn stored water into electricity when the grid needs power, or consume electricity to pump water back uphill when storing energy makes sense.</p><p>That makes Kaprun perfect for this article. It shows why &#8220;generator&#8221; and &#8220;consumer&#8221; are not always fixed identities. VERBUND (<strong>Austria's leading electricity company and one of the largest producers of hydroelectricity in Europe</strong>) describes the Kaprun power plant group as a storage power plant system with turbine capacity and pumping capacity. Pumped storage is useful because it can generate electricity when water flows down through turbines, but it can also consume electricity when pumps move water back up into a higher reservoir. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8r6j!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76da3ef4-d795-4519-87a2-52326f5be37c_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8r6j!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76da3ef4-d795-4519-87a2-52326f5be37c_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!8r6j!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76da3ef4-d795-4519-87a2-52326f5be37c_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!8r6j!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76da3ef4-d795-4519-87a2-52326f5be37c_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!8r6j!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76da3ef4-d795-4519-87a2-52326f5be37c_1536x1024.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!8r6j!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76da3ef4-d795-4519-87a2-52326f5be37c_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/76da3ef4-d795-4519-87a2-52326f5be37c_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1589869,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/199757049?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76da3ef4-d795-4519-87a2-52326f5be37c_1536x1024.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!8r6j!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76da3ef4-d795-4519-87a2-52326f5be37c_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!8r6j!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76da3ef4-d795-4519-87a2-52326f5be37c_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!8r6j!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76da3ef4-d795-4519-87a2-52326f5be37c_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!8r6j!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F76da3ef4-d795-4519-87a2-52326f5be37c_1536x1024.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 8: Pumped storage breaks the simple category. It can inject power like a generator or withdraw power like a large consumer.</em></p><p>This destroys another simple category.</p><p>A pumped-storage plant can behave like a generator. And it can behave like a consumer.</p><p>When the system needs power, it can inject power. When there is excess generation or when storage is economically and operationally useful, it can withdraw power and store energy as water at a higher elevation.</p><p>So even the terms &#8220;generator&#8221; and &#8220;consumer&#8221; are not fixed identities forever. They are roles a component can play in the current operating state of the grid.</p><h2>Consumers are not the end of a pipe</h2><p>Consumers also become clearer in the graph model.</p><p>A house is a consumer. A factory is a consumer. A railway system is a consumer. A city is a huge collection of consumers. A distribution grid can look like one large withdrawal point from the perspective of the transmission grid.</p><p>Most individual consumers are not connected directly to the high-voltage transmission grid. They are connected through lower-voltage distribution networks. Those distribution networks are then connected to the transmission grid through substations and transformers.</p><p>So when we zoom out to the transmission level, we should not imagine millions of tiny sockets attached directly to the 380 kV grid. We should imagine large withdrawal areas connected through distribution networks.</p><p>This is another reason the pipe picture fails.</p><p>The grid is not one pipe that becomes smaller and smaller until it reaches your phone charger. It is a layered electrical system. The high-voltage grid forms the backbone. Substations connect it to regional and local networks. Distribution grids bring power closer to consumers. And at each level, voltage, protection, switching, measurement, and operation matter.</p><p>The closer we move to individual homes, the more radial the system often becomes. But the transmission grid itself is designed more like a meshed backbone because important regions should not depend on one fragile path.</p><h2>Redundancy: the graph should not break too easily</h2><p>In graph theory, a bridge is an edge whose removal disconnects part of the graph.</p><p>That idea is useful for thinking about the transmission grid.</p><p>A fragile grid would have critical lines where one failure separates a whole region from the rest of the system. A stronger grid gives important regions more than one way to stay connected. Real grids are not perfectly bridge-free everywhere, but redundancy is one of the key design goals of transmission infrastructure.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_BO8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36fa4aac-3582-4880-b378-00fc5714aad3_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_BO8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36fa4aac-3582-4880-b378-00fc5714aad3_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!_BO8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36fa4aac-3582-4880-b378-00fc5714aad3_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!_BO8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36fa4aac-3582-4880-b378-00fc5714aad3_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!_BO8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36fa4aac-3582-4880-b378-00fc5714aad3_1536x1024.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!_BO8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36fa4aac-3582-4880-b378-00fc5714aad3_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/36fa4aac-3582-4880-b378-00fc5714aad3_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1565626,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/199757049?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36fa4aac-3582-4880-b378-00fc5714aad3_1536x1024.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!_BO8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36fa4aac-3582-4880-b378-00fc5714aad3_1536x1024.png 424w, https://substackcdn.com/image/fetch/$s_!_BO8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36fa4aac-3582-4880-b378-00fc5714aad3_1536x1024.png 848w, https://substackcdn.com/image/fetch/$s_!_BO8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36fa4aac-3582-4880-b378-00fc5714aad3_1536x1024.png 1272w, https://substackcdn.com/image/fetch/$s_!_BO8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36fa4aac-3582-4880-b378-00fc5714aad3_1536x1024.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><em>Figure 9: In a fragile graph, one failed edge can disconnect a region. A stronger transmission grid creates alternative paths.</em></p><p>Austria gives a good example here. APG describes the 380 kV Salzburg line as part of Austria&#8217;s extra-high-voltage ring, and says the ring structure allows power to flow to customers from either direction. The Salzburg line closed a gap in the western part of that ring and entered full operation in April 2025. </p><p>The same idea appears in southern Austria. APG&#8217;s Carinthia power grid area project plans a 380 kV connection between Obersielach and Lienz to close the 380 kV grid in southern Austria. APG explains that the 380 kV ring creates a redundant connection because important substations can be supplied from two sides. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gjTl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5dfb27e-5b75-4883-8b21-006d9b41c2a6_745x558.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gjTl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5dfb27e-5b75-4883-8b21-006d9b41c2a6_745x558.png 424w, https://substackcdn.com/image/fetch/$s_!gjTl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5dfb27e-5b75-4883-8b21-006d9b41c2a6_745x558.png 848w, https://substackcdn.com/image/fetch/$s_!gjTl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5dfb27e-5b75-4883-8b21-006d9b41c2a6_745x558.png 1272w, https://substackcdn.com/image/fetch/$s_!gjTl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5dfb27e-5b75-4883-8b21-006d9b41c2a6_745x558.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!gjTl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5dfb27e-5b75-4883-8b21-006d9b41c2a6_745x558.png" width="745" height="558" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e5dfb27e-5b75-4883-8b21-006d9b41c2a6_745x558.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:558,&quot;width&quot;:745,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:102321,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.dmytrohuz.com/i/199757049?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5dfb27e-5b75-4883-8b21-006d9b41c2a6_745x558.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!gjTl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5dfb27e-5b75-4883-8b21-006d9b41c2a6_745x558.png 424w, https://substackcdn.com/image/fetch/$s_!gjTl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5dfb27e-5b75-4883-8b21-006d9b41c2a6_745x558.png 848w, https://substackcdn.com/image/fetch/$s_!gjTl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5dfb27e-5b75-4883-8b21-006d9b41c2a6_745x558.png 1272w, https://substackcdn.com/image/fetch/$s_!gjTl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5dfb27e-5b75-4883-8b21-006d9b41c2a6_745x558.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image buttonBase-GK1x3M"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image buttonBase-GK1x3M"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>This is the graph model becoming real engineering.</p><p>We build redundancy because real systems fail. Lines are taken out for maintenance. Weather damages infrastructure. Equipment trips. Loads change. Generation patterns shift. If the grid were a simple tree, every important edge would become a potential disaster.</p><p>A meshed high-voltage grid gives operators more room to keep the system alive.</p><p>Again, we should not confuse this with the internet. The grid does not reroute power like packets. But topology matters. Connectivity matters. Alternative paths matter. A ring is not just a geometric shape. It is a way to reduce dependence on a single corridor.</p><h2>So what is the grid?</h2><p>At this point, we can rebuild the picture.</p><p>The grid is not a pipe. It is not a chain from power plant to socket. It is not a delivery system. It is a synchronized graph built from physical infrastructure.</p><p>High-voltage transmission lines form the backbone. Substations are the nodes where lines, transformers, voltage levels, distribution grids, generators, and storage systems connect. Generators inject power into the system. Consumers withdraw power from it. Pumped storage can do both. Redundancy helps the system survive outages and maintenance. Operators and protection systems keep the graph inside safe limits.</p><p>And all of this is part of a larger synchronized machine.</p><p>The most important idea is not that the grid has many components. The most important idea is that all these components participate in one continuously changing operating state.</p><p>Generation changes. Consumption changes. Storage changes mode. Power flows change. Lines become loaded or unloaded. Substations connect and disconnect parts of the graph. Protection systems wait for faults. Operators watch the system.</p><p>And through all of that, the grid must stay balanced.</p><h2>The real goal: balance</h2><p>The whole grid has one brutal rule: generation and consumption must stay balanced all the time.</p><p>But neither side is stable.</p><p>Consumers switch devices on and off. Factories start machines. Trains accelerate. Cities move through morning peaks and evening peaks. Wind farms produce more or less depending on the weather. Solar production changes with clouds and time of day. Power plants start, stop, ramp up, or reduce output. Pumped-storage plants can suddenly become large consumers or large generators.</p><p>And still, the system has to remain synchronized.</p><p>Across Austria, across neighboring countries, across the continental European grid, the machine has to keep its frequency close to 50 Hz. APG&#8217;s balancing information describes 50 Hz as the set point value in the Continental Europe synchronous area and explains that generation and consumption must stay in constant equilibrium. APG Balancing</p><p>That is the real goal of the grid.</p><p>Not simply to &#8220;send electricity&#8221; from power plants to houses.</p><p>The real goal is to continuously adapt generation, consumption, storage, topology, voltage, and power flows so the whole system remains stable.</p><p>This is why the pipe analogy is not only incomplete. It hides the most beautiful part of the system.</p><p>A pipe does not need synchronization. A pipe does not have frequency. A pipe does not react to every change in the whole continent. A pipe does not have to balance generation and consumption in real time.</p><p>The grid does.</p><p>And now that we can see the grid as a synchronized graph, the next question becomes much more interesting:</p><p>How is this machine operated?</p><p>Continue with <a href="https://www.softwareinthegrid.com/p/how-the-european-grid-stays-stable">How the European Grid Stays Stable</a> to see how protection, monitoring, control, and operation keep this machine within its limits. For the full reading path, return to <a href="https://www.softwareinthegrid.com/p/a-developers-map-of-the-european">A Developer&#8217;s Map of the European Power Grid</a>.</p><h2>Sources</h2><ul><li><p>Austrian Power Grid: <a href="https://www.apg.at/en/power-grid/power-grid-austria/">[Power Grid Austria]</a></p></li><li><p>Austrian Power Grid: [<a href="https://www.apg.at/en/projects/pongau-substation/">Pongau Substation</a>]</p></li><li><p>Austrian Power Grid: [<a href="https://www.apg.at/en/projects/salzburg-line/">Salzburg Line</a>]</p></li><li><p>Austrian Power Grid: [<a href="https://www.apg.at/en/projects/carinthia-power-grid-area/">Carinthia Power Grid Area</a>]</p></li><li><p>APG Market: [<a href="https://markt.apg.at/en/power-grid/balancing/">Balancing</a>]</p></li><li><p>ENTSO-E: [<a href="https://www.entsoe.eu/data/map/">Transmission System Map</a>]</p></li><li><p>VERBUND: [<a href="https://www.verbund.com/en-at/about-verbund/power-plants">Power plants and hydropower information</a>]</p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.softwareinthegrid.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Subscribe to follow how physical infrastructure, control systems, and software work together in the power grid.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item></channel></rss>