DEV Community

Cover image for Computer Networking Explained: From Real-World Analogies to Production Systems | Day 1
Muhammad Hassan Obaid
Muhammad Hassan Obaid

Posted on

Computer Networking Explained: From Real-World Analogies to Production Systems | Day 1

CodeWithObaid | Software Engineer Interview Preparation Series

Have you ever wondered what actually happens when you type google.com into your browser and press Enter?

Your browser somehow finds the correct server, sends a request, receives a response, and displays a webpage in seconds.

But how?

How does your laptop communicate with a server thousands of kilometers away? How does your request reach the correct destination? And how do thousands of users access the same application without their requests getting mixed up?

The answer begins with Computer Networking.

Let's understand it from the ground up, using real-world analogies first, technical definitions second, and production-level examples throughout.

1. What Is a Computer Network?

Imagine an office with 100 employees. They need to share documents, communicate with one another, print reports, and access company applications.

Instead of working in isolation, their computers are connected so they can exchange information and share resources.

That is the basic idea behind a computer network.

Technical definition: A computer network is a collection of interconnected devices that communicate and exchange data or share resources through communication links and agreed-upon protocols.

A network can connect two devices in the same room or millions of devices across the world.

The building blocks of a network

Think of a network as a delivery system:

  • Nodes: The participants sending or receiving information, such as laptops, mobile phones, servers, and printers.

  • Links: The connections between devices, using Ethernet cables, optical fiber, Wi-Fi, or other transmission technologies.

  • Network devices: Equipment such as switches and routers that help move traffic between devices and networks.

  • Protocols: The rules that determine how devices communicate.

  • Addresses: Identifiers, such as IP addresses, that help direct data to the correct network destination.

A simplified network might look like this:


       Laptop A                 Laptop B

           |                        |

           +----------+-------------+

                      |

                  [Switch]

                      |

                  [Router]

                      |

                  Internet

                      |

                [Web Server]

Enter fullscreen mode Exit fullscreen mode

The diagram is simplified, but it captures an important idea: devices need both connections and rules to communicate successfully.

Real-world example: In an e-commerce application, your phone, the application's backend server, the database server, and external payment services may communicate over networks. Understanding networking helps explain why a request can fail even when your application code appears correct.

2. How Does a Computer Network Work?

Let's follow a familiar example: you open an online shopping application and view a product.

At a high level, the process looks like this:


+-------------------+

| Your Mobile Phone |

+-------------------+

          |

          | Request

          v

+-------------------+

| Wi-Fi Router      |

+-------------------+

          |

          v

+-------------------+

| Internet / Routes |

+-------------------+

          |

          v

+-------------------+

| Backend Server    |

+-------------------+

          |

          | Query

          v

+-------------------+

| Database Server   |

+-------------------+

          |

          v

    Response returns

    to your mobile

Enter fullscreen mode Exit fullscreen mode

The actual journey may involve many additional devices, services, and network hops. The diagram shows the logical flow, not every physical connection.

Here is what happens conceptually.

Step 1: The application creates a request.

Your mobile application asks the backend for product information. For example, it may send an HTTP request to an API endpoint.

Step 2: The destination is identified.

The application needs to reach the correct server. DNS can translate a domain name into an IP address, unless a usable answer is already cached or the destination is identified another way.

Step 3: The data is prepared for transmission.

Networking protocols add the information needed for delivery. Depending on the protocol, this can include source and destination addresses, port numbers, sequencing information, and error-checking data.

Step 4: The data travels across the network.

Local network devices forward traffic, and routers direct IP packets between networks. The path may cross multiple networks operated by different organizations.

Step 5: The server processes the request.

The backend may validate the request, query a database, call another service, and construct a response.

Step 6: The response reaches the client.

The response travels back through the network. Your application processes it and displays the product information.

One important detail: the response does not necessarily follow exactly the same route as the request.

What are packets?

Imagine sending a 100-page document through a delivery service. Rather than treating the entire document as one indivisible item, you divide it into smaller packages, label them, and deliver them.

Network communication works on a similar principle.

Data is transmitted in manageable units. At the IP layer, these units are called packets. At the transport layer, TCP uses segments, while UDP uses datagrams. At the link layer, Ethernet commonly carries frames.


Original Data

+--------------------------------------+

| "Here is the product information..." |

+--------------------------------------+

                  |

                  v

          Data is transmitted

          in smaller units

                  |

          +-------+-------+

          |       |       |

          v       v       v

       Packet  Packet  Packet

          1       2       3

          |       |       |

          +-------+-------+

                  |

                  v

        Destination processes data

Enter fullscreen mode Exit fullscreen mode

This is a conceptual illustration. Actual packetization depends on the protocols and network conditions.

Why does this matter?

  • Large amounts of data can be transmitted efficiently.

  • Networks can carry traffic from many applications.

  • Lost or corrupted data can be detected or recovered from when the relevant protocol provides those mechanisms.

  • Routers can forward individual IP packets without understanding the application's business logic.

Interview takeaway: A packet is not the same thing as a TCP segment or an Ethernet frame. They belong to different networking layers.

3. What Are Network Protocols?

Imagine two people trying to communicate, but one speaks English and the other speaks Japanese, with neither understanding the other.

Even if they can hear each other, communication will fail without a shared language or a translation mechanism.

Protocols serve a similar purpose in computer networks: they define how devices format, transmit, interpret, and handle information.

A protocol may specify message structure, addressing, sequencing, error handling, connection establishment, or security.

Some important protocols include:

| Protocol | Purpose | Practical example |

|---|---|---|

| HTTP | Transfers web resources | Loading a web page |

| HTTPS | HTTP secured using TLS | Secure banking or shopping |

| TCP | Reliable, ordered byte-stream transport | Many API and database connections |

| UDP | Datagram transport without TCP-style delivery guarantees | Real-time media and DNS, depending on the use case |

| IP | Addresses and routes packets between networks | Sending traffic to a remote server |

| DNS | Resolves names to records | Finding the address associated with a domain |

| DHCP | Automatically configures network settings | Joining a Wi-Fi network |

| ARP | Resolves IPv4 addresses to link-layer addresses on a local network | Finding the local next-hop MAC address |

A real production example

Suppose your React frontend calls a Ruby on Rails API:


React Frontend

      |

      | HTTPS request

      v

Load Balancer / Reverse Proxy

      |

      v

Rails Application

      |

      | Database connection

      v

PostgreSQL

Enter fullscreen mode Exit fullscreen mode

Different protocols and layers are involved in this journey.

  • HTTPS protects communication between the client and the HTTPS endpoint.

  • TCP commonly provides reliable transport for HTTPS over HTTP/1.1 or HTTP/2.

  • IP routes traffic between networks.

  • The database connection uses its own application protocol, commonly over TCP for PostgreSQL.

Modern HTTP/3 is different: it runs over QUIC, which uses UDP, rather than TCP.

The key lesson: Protocols solve different problems. Do not assume every network communication uses TCP, or that HTTPS itself replaces IP addressing and routing.

4. What Is an IP Address?

Imagine sending a parcel to a house. The delivery service needs an address to identify the intended destination.

Similarly, an IP address is a logical network-layer address used to identify an interface for communication across IP networks.

For example:


192.168.1.10

Enter fullscreen mode Exit fullscreen mode

This is an example of an IPv4 address.

IPv6 addresses use a different format and provide a vastly larger address space.

An important distinction: an IP address is not necessarily a permanent identity for a device. Addresses may change, be assigned dynamically, or be shared through mechanisms such as Network Address Translation (NAT).

Public IP vs. private IP

Private IP addresses are used within private networks and are not globally routable on the public internet. Common IPv4 private ranges include:

  • 10.0.0.0/8

  • 172.16.0.0/12

  • 192.168.0.0/16

Public IP addresses are globally routable addresses, subject to routing policies and other network conditions.

For example, your laptop might have a private address such as 192.168.1.10, while your home router uses a public IP address for internet communication.


Laptop

192.168.1.10

      |

      v

Home Router

Private LAN + Public IP

      |

      | NAT, when configured

      v

    Internet

      |

      v

Remote Server

Enter fullscreen mode Exit fullscreen mode

NAT commonly allows multiple devices using private IPv4 addresses to share a public IPv4 address.

Why should backend engineers care?

When debugging a production system, IP addressing matters for:

  • Firewall allowlists and network access rules.

  • Private communication between application and database servers.

  • Container and cloud network configuration.

  • Diagnosing connectivity problems.

  • Understanding why a service is reachable from one network but not another.

Interview takeaway: IP addresses identify network interfaces at the network layer. They are different from MAC addresses, which are used for link-layer delivery on local networks, and port numbers, which identify transport-layer endpoints.

5. Switches vs. Routers: What Is the Difference?

Imagine a large office building.

Inside the building, a receptionist helps direct visitors to the correct department. To reach another building across town, you need a different kind of navigation system.

Switches and routers play different roles in a network.

What is a switch?

A traditional Ethernet switch connects devices within a local network and forwards Ethernet frames based on MAC addresses.

It learns which MAC addresses are reachable through which ports and uses that information to forward frames.


Computer A       Computer B

    |                |

    +-------+--------+

            |

         [Switch]

            |

         [Printer]

Enter fullscreen mode Exit fullscreen mode

Real-world use: Connecting computers, printers, servers, and access points within an office or data center network.

What is a router?

A router forwards IP packets between different networks using routing information.


Office Network

      |

      v

   [Router]

      |

      v

   ISP Network

      |

      v

  Remote Network

Enter fullscreen mode Exit fullscreen mode

Real-world use: Connecting a home network to an internet service provider or connecting separate cloud network segments.

Quick comparison

| Feature | Switch | Router |

|---|---|---|

| Typical role | Connects devices within a LAN | Connects different IP networks |

| Main forwarding information | MAC address | IP address and routing table |

| Typical layer | Layer 2 | Layer 3 |

| Example | Office Ethernet network | Home network to the internet |

These are the typical roles of Layer 2 switches and IP routers. Multilayer switches can perform routing, and real network equipment can combine several functions.

6. Wired vs. Wireless Networks

A network also depends on how devices connect to one another.

Wired networking

Examples include Ethernet and optical fiber.

Advantages

  • Predictable performance in well-designed networks.

  • Generally lower interference from radio congestion.

  • Fiber supports high bandwidth over long distances.

Trade-offs

  • Cabling and installation costs.

  • Less mobility.

  • Physical infrastructure may be difficult to change.

Where it fits: Data centers, office desktops, server connections, and environments requiring stable, high-throughput connectivity.

Wireless networking

Wi-Fi connects devices through radio signals rather than requiring an Ethernet cable for every device.

Advantages

  • Mobility and convenience.

  • Easier expansion for many user devices.

  • Less physical cabling at the edge.

Trade-offs

  • Interference and congestion.

  • Performance varies with distance and signal quality.

  • Security depends on correct configuration and authentication.

Where it fits: Phones, laptops, guest networks, and mobile devices.

Production insight: Wired and wireless networking are not competing choices for every situation. A typical enterprise uses wired infrastructure for servers and access points while employees connect through Wi-Fi.

7. What Is a Firewall?

Imagine a security guard at the entrance to an office. The guard checks who can enter and which areas they can access.

A firewall applies network traffic rules to allow or block communication.

Depending on the type, it may inspect IP addresses, ports, connection state, protocols, or application-level information.


Internet

   |

   v

[Firewall Rules]

   |

   +---- Allowed traffic ----> Application

   |

   +---- Blocked traffic ----> Rejected

Enter fullscreen mode Exit fullscreen mode

A production example

Suppose your application runs on a cloud server and uses PostgreSQL.

A sensible security design might allow:

  • Public HTTPS traffic to the application entry point.

  • Application-server traffic to the database on its required port.

  • Administrative access only through approved, restricted paths.

It should not expose the database port to the entire internet.

Best practice: Apply least privilege. Permit only the traffic that is actually required, and review rules as the system evolves.

A firewall is not a complete security strategy. Authentication, authorization, encryption, patching, monitoring, and secure application code remain essential.

8. Types of Computer Network Architecture

Network architecture describes how devices and services are organized to communicate and share responsibilities.

Two fundamental models are client-server and peer-to-peer.

A. Client-server architecture

Think of a restaurant.

Customers place orders, and the restaurant's kitchen prepares them. Customers do not need to maintain their own independent kitchens to obtain meals.

Similarly, clients request services, and servers provide them.


       Client A       Client B

           \             /

            \           /

             v         v

             +---------+

             |  Server |

             +---------+

                  |

                  v

               Database

Enter fullscreen mode Exit fullscreen mode

Technical definition: Client-server architecture is a model in which client processes request services or resources from server processes.

Real-world examples:

  • A React application requesting data from a Rails API.

  • A mobile banking app communicating with banking services.

  • A browser retrieving pages from a web server.

Advantages

  • Centralized management and access control.

  • Easier coordination of shared data.

  • Clear separation between clients and backend services.

Trade-offs

  • Servers require capacity planning and monitoring.

  • A single server can become a bottleneck or a single point of failure.

  • Infrastructure and operational complexity increase as the system scales.

These problems can be mitigated with replication, load balancing, caching, and redundancy, although each introduces additional complexity.

When to use it: Most business applications, SaaS products, banking systems, and centralized services.

B. Peer-to-peer (P2P) architecture

Now imagine a group of people sharing files directly with one another instead of relying entirely on a central distribution server.

That is the core idea behind peer-to-peer networking.


        Peer A

        /    \

       /      \

   Peer B ---- Peer C

       \       /

        \     /

        Peer D

Enter fullscreen mode Exit fullscreen mode

In a peer-to-peer system, participating nodes can provide resources directly to other peers. Depending on the design, a peer may act as both a requester and a provider.

Real-world examples: BitTorrent-style file distribution and certain decentralized communication or resource-sharing systems.

Advantages

  • Resources and traffic can be distributed across participating peers.

  • The system may reduce dependence on a central data-distribution server.

  • It can make effective use of participants' available bandwidth and resources.

Trade-offs

  • Peers can disconnect unexpectedly.

  • Discovering peers and managing trust can be challenging.

  • Security, data integrity, and availability require careful design.

  • Performance can vary with the number and quality of participating peers.

When to use it: Distributed file sharing or workloads where direct peer participation provides meaningful benefits.

When not to use it: Avoid assuming pure P2P is ideal for every business application. Systems requiring strong centralized authorization, consistent shared state, or predictable operational control may be better served by client-server architecture or a hybrid model.

One final nuance: P2P does not always mean there is no central server whatsoever. Some P2P systems use centralized discovery, coordination, or authentication while transferring data directly between peers.

Final Takeaway

Computer networking is not just about cables, routers, or memorizing protocol names. It is about understanding how information moves between systems, how each layer contributes to communication, and where failures can occur.

As a software engineer, this knowledge helps you debug API failures, understand cloud deployments, design safer architectures, and communicate confidently in technical interviews.

Coming next on CodeWithObaid:

We'll explore Client-Server Architecture (Client-Server Model) and Network Devices in greater depth, including how requests move through switches, routers, firewalls, load balancers, and servers in a real production environment.

Interview questions you must prepare from Day 1
These are the questions I would prioritize for an entry-level or junior software engineer interview. Practice answering each in your own words before memorizing the sample answer.
A. Theoretical questions

  1. What is a computer network?
    Expected answer
    A computer network is a collection of interconnected devices that exchange data and share resources using communication links and protocols. Examples include office LANs and the internet.

  2. How does data travel from a client to a server?
    A client creates a request, resolves the destination if necessary, and sends data through the network stack. Network devices forward the traffic toward the server, which processes the request and returns a response. The exact path depends on routing and network configuration.

  3. What is the difference between a packet, a frame, and a segment?
    A TCP segment is a transport-layer unit, an IP packet is a network-layer unit, and an Ethernet frame is a link-layer unit. They are encapsulated as data moves through the networking stack.

  4. What is a network protocol, and why do we need it?
    A protocol defines rules for communication, including message formats and how devices exchange or interpret data. Without compatible protocols, devices cannot reliably understand each other's communication.

  5. What is the difference between TCP and UDP?
    TCP provides a reliable, ordered byte stream with retransmission and flow control. UDP provides datagrams without TCP-style delivery or ordering guarantees. TCP is common for web APIs, while UDP is useful for latency-sensitive communication and protocols built on top of it, such as QUIC.

  6. What is the difference between an IP address, a MAC address, and a port?
    An IP address identifies a network-layer interface for routing. A MAC address is used for link-layer delivery on a local network. A port identifies a transport-layer endpoint associated with an application or service.

  7. What is the difference between a public and private IP address?
    Private IPv4 addresses are used within private networks and are not globally routable on the public internet. Public IP addresses are globally routable, subject to routing policies. NAT commonly enables private-addressed devices to share a public IPv4 address.

  8. What is the difference between a switch and a router?
    A Layer 2 switch typically forwards Ethernet frames based on MAC addresses within a LAN. A router forwards IP packets between networks using routing information.

  9. What is a firewall?
    A firewall enforces traffic-control rules to allow or block network communication. It helps reduce unauthorized access but does not replace application security, authentication, or encryption.

  10. Compare client-server and peer-to-peer architecture.
    In client-server architecture, clients request services from servers that provide them. In P2P architecture, peers can both request and provide resources. Client-server favors centralized control, while P2P can distribute resource sharing but introduces peer discovery, trust, and availability challenges.

B. Scenario-based questions

  1. Your browser cannot open a website, but other websites work. How would you troubleshoot it?
    Strong interview answer
    I would first determine whether the problem affects one browser, one device, or multiple devices. Then I would check DNS resolution, test connectivity to the destination, inspect HTTP status codes, and review browser and server logs. I would also check TLS certificate errors, proxy settings, and firewall rules. I would use tools such as nslookup, curl, and traceroute where appropriate.

  2. Your Rails application can connect to the web server but cannot connect to PostgreSQL. What would you check?
    I would verify the database hostname, port, credentials, and connection configuration. Then I would check whether PostgreSQL is running, whether the database is listening on the expected interface, and whether security groups, firewall rules, routing, or network policies allow the connection. Finally, I would inspect database logs and application error messages to distinguish connectivity failures from authentication or database errors.

  3. Two computers are connected to the same switch but cannot communicate. Does that mean the switch is faulty?
    Not necessarily. I would check link status, VLAN membership, IP addresses, subnet masks, duplicate IP addresses, host firewalls, and switch configuration. If the devices belong to different VLANs or IP subnets, appropriate routing may be required.

  4. Why can a server be reachable by IP address but not by domain name?
    This suggests a possible DNS resolution issue, although other causes are possible. I would check the DNS record, resolver configuration, cached results, and whether the domain points to the correct address.

  5. Your application works locally but fails after deployment to the cloud. What networking issues could explain this?
    Possible causes include incorrect environment variables or hostnames, blocked inbound or outbound ports, incorrect routing, security group rules, DNS configuration, TLS problems, and missing connectivity between application and database networks. I would compare local and production configurations and test each connection independently.

  6. A company has thousands of users accessing its API. Would you choose client-server or P2P architecture? Why?
    For a typical business API, I would choose client-server architecture because it supports centralized authentication, authorization, data management, and operational control. I would scale it with load balancing, multiple application instances, caching, and database optimization. P2P would be considered only if direct resource sharing between peers provided a meaningful benefit.

  7. A database server is accidentally exposed to the public internet. What would you do?
    I would immediately restrict network access to approved sources, verify the intended access rules, and investigate logs for suspicious connections. I would check whether credentials or data may have been compromised and rotate affected secrets if necessary. I would then implement private networking, least-privilege firewall rules, secure credential management, and monitoring.

C. Production-level follow-up questions
These distinguish someone who has memorized definitions from someone who can apply networking concepts.

  • What happens when an HTTP request crosses multiple routers?
  • Why does a server need both an IP address and a port number?
  • Why might a connection time out even when DNS resolution succeeds?
  • What is NAT, and why is it commonly used with private IPv4 networks?
  • Why does HTTPS need TLS if TCP already provides reliable delivery?
  • What is the difference between a network connectivity error and an HTTP 500 response?
  • Why should a production database usually not be publicly accessible?
  • Can two devices on the same LAN communicate without a router? Under what conditions?
  • Why might a UDP-based application work differently from a TCP-based application on a congested network?
  • What problems can arise when a client-server application has only one server?

If you're preparing for software engineering interviews, follow the series and build your understanding one concept at a time.

CodeWithObaid #ComputerNetworking #SoftwareEngineering #BackendDevelopment #InterviewPreparation #SystemDesign

Top comments (0)