Computer Network
Introduction

Introduction to Computer Networks

In modern software engineering, the network is not just plumbing—it is a core architectural component. From designing distributed systems, debugging API latencies, to configuring cloud load balancers, a deep understanding of computer networks is indispensable.

This section covers the fundamental design of networks, focusing on the core mechanisms that make end-to-end communication possible on the internet.


The Core Concept: How Devices Connect

At its simplest, a computer network is a system of interconnected nodes (servers, routers, switches, user devices) that exchange data using common communication protocols.

When a client (like a browser or mobile app) wants to fetch data from a server, it initiates a request. But what happens under the hood?

To coordinate this complex workflow across different hardware and software vendors, networks rely on layered architectures.


Layered Architectures: OSI vs. TCP/IP

The network stack is modular. Each layer has a specific responsibility, providing services to the layer above it and consuming services from the layer below it.

We use two primary conceptual models to describe this modularity:

  1. OSI (Open Systems Interconnection) Model: A theoretical 7-layer framework.
  2. TCP/IP (Internet Protocol Suite) Model: A practical 4-layer framework used by the actual Internet.

OSI vs. TCP/IP Comparison

OSI LayerNameDescriptionTCP/IP LayerKey ProtocolsData Unit
7ApplicationUser-facing protocols (APIs, web browsers, email).Application (Layers 5-7 combined)HTTP, DNS, SMTP, FTP, SSHData / Payload
6PresentationData formatting, encryption, compression.TLS, SSL, JSON, XML
5SessionEstablishes and manages connections/sessions.SOCKS, NetBIOS
4TransportEnd-to-end reliability, flow control, port addressing.TransportTCP, UDPSegment (TCP) / Datagram (UDP)
3NetworkRouting packets across multiple networks, logical addressing.InternetIP (IPv4, IPv6), ICMP, ARPPacket
2Data LinkNode-to-node data transfer (same physical network), MAC addressing.Network Access (Layers 1-2 combined)Ethernet, Wi-Fi (802.11), PPPFrame
1PhysicalTransmission of raw bitstreams over physical mediums.Fiber, Copper, Radio wavesBits

Life of a Network Packet: Encapsulation

As data travels down the sender's stack, each layer wraps the payload with its own protocol headers. This process is called Encapsulation. When the receiver gets the physical bits, it does the reverse (Decapsulation), stripping the headers layer-by-layer.

+--------------------------------------------------------+
| Application Layer:  [ HTTP Data ]                      |
+--------------------------------------------------------+
                           |  Encapsulated inside Transport Layer
                           v
+--------------------------------------------------------+
| Transport Layer:    [ TCP Header ][ HTTP Data ]        | -> TCP Segment
+--------------------------------------------------------+
                           |  Encapsulated inside Network Layer
                           v
+--------------------------------------------------------+
| Network Layer:      [ IP Header ][ TCP ][ HTTP Data ]  | -> IP Packet
+--------------------------------------------------------+
                           |  Encapsulated inside Link Layer
                           v
+--------------------------------------------------------+
| Link Layer:   [ MAC Header ][ IP ][ TCP ][ HTTP ][FCS] | -> Ethernet Frame
+--------------------------------------------------------+

Core Infrastructure Pillars

To build, scale, and debug modern systems, software engineers must master three pillars of networking:

  1. Domain Name System (DNS): Resolves human-readable domain names to machine-readable IP addresses. Learn how DNS resolution works, records types, and modern DNS routing architectures like Anycast.
  2. Ports and Sockets: How applications on the same machine run concurrently without interfering, utilizing transport-layer ports (TCP/UDP multiplexing).
  3. Network Address Translation (NAT): How millions of private devices share limited public IPv4 addresses, and the challenges NAT introduces for direct peer-to-peer communication.